Repository navigation
perf(data_plane): Remote Write decode 652 → 212 ns/sample - #861
Merged
Merged
Conversation
rw_corpus_bench decodes a directory of captured Remote Write bodies and reports ns/sample for snappy alone, the full decode, the hand-off to ingest shards, and a threaded run as the server does it. remote_write_reference keeps the decoder as it was and checks that decode_samples gives the same samples, series and errors on generated requests (label orders, interleaved fields, series appearing mid-stream, unknown fields, stale markers), on every truncation and on byte flips, and with RW_CORPUS_DIR set on captured bodies.
- Decompress into a buffer each thread keeps between requests, instead of a fresh zeroed allocation per request (page faults and zeroing were two thirds of the snappy cost). - Inline the protobuf reader, with a one-byte varint fast path; skip a series' leading labels by their tag and short length; walk only the fields outside the labels for samples; read the timestamp varint of the sender's sample layout inline. - Series are never forgotten, so the interner hands out &'static Series: no reference count is written per sample in decode, routing, chunk building or drop. - The per-thread series cache predicts the next series from the order the sender used last time; a hit is one byte compare, no hash. - try_ingest sizes each shard's vector for its share up front. Same samples, series and errors as before (remote_write_reference).
memory_reservations_wait_then_fail_only_a_lone_window posted the small and the large window's requests back to back and relied on the small window being sealed before the large one's samples were folded. With faster Remote Write decode the large window's samples arrive while the small one is still open, so its reservation waits (as designed) and no window fails. A barrier at 10 s seals the small window first.
…e body A body whose snappy header claimed up to max_decompressed_bytes grew and zeroed the thread's kept buffer, and a decompression error returned before the keep cap was applied, so the thread held the buffer. The cap now applies whatever the outcome, and a body over the kept size decompresses into a fresh allocation. test(data_plane): barrier before the 21 s window in memory_reservations_wait_then_fail_only_a_lone_window, so no shard opens it while another still folds the large window.
zzylol
marked this pull request as ready for review
November 24, 2026 02:37
This was referenced Nov 24, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remote Write decode was the data plane's biggest CPU cost on the demo48 live workload (34,220 series at 10 Hz, 342k samples/s, 4 feeder shards): 55.6% of ASAP's phase CPU. This PR cuts it from 652 to 212 ns per sample in the server, and from 514 to 147 ns per sample in a single-thread benchmark on captured demo48 requests. Results do not change: the same samples, series and errors, checked against the old decoder.
Results
End to end. One data plane on 20 CPUs of a 40-core x86 server (2.2 GHz). It is fed by the four demo48 feeder shards at the demo rate and serves the demo's four query users. The table covers 20 minutes after a 2-minute warm-up. Old =
24342eab, new = this PR's changes on24342eab. The decode path is the same on the current branch head.remote_write_decodeCPUprecomputeappendquerySaturation (data plane limited to 4 CPUs, feeder rate raised per series, 3 minutes measured per step):
The ceiling did not move. At it, the process uses under 1 of its 4 CPUs in both builds, so the limit is not decode CPU. It is a serial stage behind the ingest queue, and decode no longer competes with it for CPU. That bottleneck is outside this PR.
Benchmark (
rw_corpus_benchon 1,080 captured demo48 bodies: 20.5 M samples, 2.37 GB decompressed, about 115 bytes per sample, one sample perTimeSeries; one thread with a warm cache):The snappy figures are measured on their own. The walk and lookup figures split the rest of the decode by their perf shares.
What changed, and what each step gave (decode ns/sample, benchmark)
Reader::field/varint/takewere out-of-line calls and took half the decode time.&'static Seriesinstead ofArc<Series>.RawSample.labels,Chunk.series,intern*andby_identitychange type. No reference count is written per sample anywhere (decode, routing, chunk building, drop). Before, that count was written from the decode thread and from the ingest threads.memcmpand no hash. Every hit is still a byte-for-byte match.try_ingestsizes each shard's vector for its share up front.Tried and dropped: other snappy decoders, measured on the same bodies.
snap1.1.2 runs at 2.9 GB/s, the C++ library (snappy_src) at 1.5 GB/s, and the S2 decoder (minlz) at 1.5 GB/s, sosnapstays. Decoding straight into per-shard vectors was not tried: after step 5 the hand-off costs 9.5 ns.Tests
tests/remote_write_reference.rskeeps the old decoder verbatim and checks thatdecode_samplesgives the same series ids, timestamps, value bits (stale markers included) and errors on:__name__, a duplicate label, a label that is not UTF-8, sample limits from 0 to 5.RW_CORPUS_DIRset (all 20.5 M samples match).cargo fmt --checkandcargo clippy -p data_plane --tests --examplesare clean.--libfiltered to remote_write, store, series_ids, engine, ingestion and push;--testseries_ids, server, remote_write_reference, no_forward, concurrency, push_precompute (3 of 3 runs), range_isolation, planner_executor_answers.ingest_shards::a_shard_running_ahead_does_not_close_windows_earlyis timing-dependent. It failed 2 of 3 runs on the base and fails here as well.push_precompute::memory_reservations_wait_then_fail_only_a_lone_window). The test posted the small window's and the large window's requests back to back. It relied on the small window being sealed before the large window's samples were folded. With the faster decode they arrive while the small window is still open, so the large window's reservation waits (as designed) and nothing fails. Adding a 2 ms sleep per request makes it pass again, which confirms the cause. The test now seals the small window with a barrier at 10 s before posting the large one, and it passes on both the base and this branch.Usage