Repository navigation
feat(data_plane): tiered view storage, push precompute by default, faster Remote Write decode - #864
Merged
Merged
Conversation
…ote Write decode The content of feat/tiered-view-storage (with #852's review fixes merged at 18b080bf), on top of main.
… window-path group's close The late cutoff of a metric was the oldest window still open among the window-path groups only, so with a pushed long group and a window-path short group on one metric, the short group's close dropped samples the long group's open window still needed. A metric any push group scans is no longer dropped as late by the router; push shards drop the samples of their sealed windows themselves. Raw-data eviction still counts only window-path groups.
… groups The budget failed a window only when a shard had exactly one instance open, so with two or more push groups it never applied. A shard now fails its largest open window when no group has an older window open on any shard. The EngineOptions doc says what is enforced: nothing waits.
…a declared stream start Without a declared stream start the first window is skipped though it had data, and after a restart that loaded views the samples before it are gone, so a range reaching back before a view's first stored window is missing data, not empty. The floor now applies only with the stream start declared, and ViewStore::restarted clears it as Ingestion::restarted does.
…a fragment encodes append_record created (and truncated) the segment file before any fragment encoded, so a window recomputed after a restart whose end equals a recovered segment's first end truncated that (maybe mapped) segment. A segment is now created only when a record has a fragment, with create_new; when its name is taken it goes to <end>_<n>.seg, which the index reads by the part before the underscore.
A fragment's offset plus length is added with checked_add; at index time a record whose head names a texts, grids or fragment range outside its own frame ends the segment, as an undecodable record does; and a fragment's row count is bounded by its length before a constant column allocates it.
A window removed (past retention) while its decode was in flight was inserted when the decode finished, and a removed key stayed in the CLOCK ring. remove now marks an in-flight key so the loader does not insert it, and takes the key out of the ring.
… the probe's seal The install probe counted the Scans opened before the run's first stall; a Scan opened only after the seal would get no samples on the shards. Such a group now stays on the window path.
The data plane decides which groups are pushed by its install probe (push::probe); pipelines.rs was read only by the push tests. It moves to tests/pipelines/, and the comments no longer say install uses it.
Segments directly in a group's directory, before the split by retention, were only ever written by this branch's earlier revisions.
…:Text Plain and text values are columns of a fragment; only states are stored as a StoredValue.
One value formatter for instant and range answers; format_value stays as the test reference write_value is checked against. Envelope is kept: VectorResponse and the matrix reference test both use it.
…until implemented
…ap::ValueEnum An unknown value is now an error instead of silently meaning window or mmap; ingest_bench parses PRECOMPUTE_MODE strictly too. The library default stays Window, and its doc says why it differs from the binary's push.
WindowLocation::{offset,maps,is_cold,is_sealed} are cfg(test);
Snapshot::view_rows, ViewStore::rows and ViewRowsByView are doc(hidden);
DEFAULT_VIEW_SEGMENT_MS re-exported persist's default and is inlined.
…lt and the pins in the README
# Conflicts: # Cargo.lock # Cargo.toml
This was referenced Nov 24, 2026
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.
Lands
feat/tiered-view-storageonmain: replaces #855 (and #854, which was merged into it), rebased ontomainafter #852 was squash-merged. The branchfeat/tiered-view-storageis kept unchanged. It contains three pieces of work:--precompute-mode push, the default;windowkeeps the runs over each closed window), under a precompute memory budget, with batched pushes.It also carries #852's review fixes into the code these change (merged at 18b080bf): the refusal of raw reads that reach evicted samples, the late and extreme-timestamp sample drops, and stopping at an undecodable record now also apply to the cold-tier segment index (6a4d9b4c, with a test).
The sections below are the three PRs' descriptions.
Review fixes (c17ae04..45ef3ef)
Independent reviews by dimension (correctness; dead code and duplication; docs and ASAPPlanner terms; privacy). Fixed, each behavior change with a test that failed first:
create_new, only once a fragment encodes (00dc34f)Scanopened after its sealStoredValuevariants,CacheStats.loads, a second value formatter, test-only accessors, hand-parsed enumsclap::ValueEnum(078f99b..983b1fb)Not changed: samples a push shard drops for its own sealed windows are counted once by the router as
late_for_views, not again; the run instances a group may open before its first seal are not bounded yet.Follow-ups
push_precompute.rs,view_tiering.rsandview_cold_allocations.rskeep their ownbarrier/metrictest helpers; move them totests/commonlike the others.Tiered view storage (#855)
Design: docs/design/tiered-view-storage.md. Implements the approved design and its zero-copy revision: cold view windows are read from mapped segments through state views, never rebuilt. Pins ProjectASAP/ASAPPlanner#1447 (executor: mapped state columns, streaming
SummaryMerge) and ProjectASAP/asap_sketchlib#271 (DDSketch, KLL and Count-Min views). B1 results are in the PR comments. With every read cold in a 3 GiB cgroup, the working set is 456 MiB and anon is 352 MiB, against 1300 MiB and 1273 MiB with tiering off, and q01 latency is unchanged (1.1–1.3 s). V22 (compressed samples) waits for the backend codec PR.Summary
Keep recently read view windows decoded in a bounded heap cache, and serve all other windows from the view files the data plane already writes for recovery: sealed segments are mapped and decoded in place from a columnar format. The persistence files become the cold tier, so each window is encoded and written once. Under a cgroup
memory.maxthe data plane then slows down instead of being OOM-killed, and disk use becomes bounded by retention.Review guide
*.stale.Behavior: before → after
Dashboard plan (KLL quantile, Max, Rate, Increase chains, 15 s windows, 1 h retention), 10k series per metric, 1 sample/s, measured in process on a 56-core x86 server:
--view-cache-max-bytes(default from the cgroup'smemory.max); the rest in the files (1.46 GB per hour today, less with columnar fragments), reclaimable page cachememory.maxInterfaces
// data_plane/src/engine.rs pub struct EngineOptions { pub view_sync_interval_ms: u64, + /// Bytes of decoded view windows the window cache may hold; `None`: from the cgroup's memory.max, or no budget. + pub view_cache_max_bytes: Option<u64>, + /// A cached window not read for this long leaves the cache; `None`: 60 s; `Some(0)`: never. + pub view_cache_idle_ms: Option<u64>, + /// Milliseconds of windows per view file segment (default 15 min). + pub view_segment_ms: i64, + /// Mapped sealed segments, or `pread`. + pub view_read: ViewRead, + #[doc(hidden)] pub cold_decode_delay_ms: u64, + #[doc(hidden)] pub unpersistable_views: Vec<PhysicalASAPNodeId>, } // data_plane/src/persist.rs +pub const FORMAT_VERSION: u32 = 2; +pub enum ViewRead { Mmap, Pread } +/// One view's fragment of one window in a segment. +pub struct WindowLocation { .. } +impl WindowLocation { + pub fn read(&self, schema: &SchemaRef, how: ViewRead) -> Result<Batch, Error>; + pub fn segment_path(&self) -> &Path; + pub fn offset(&self) -> u64; + pub fn len(&self) -> u32; + pub fn is_sealed(&self) -> bool; + pub fn maps(&self, address: usize) -> bool; +} +pub type ViewIndex = BTreeMap<PhysicalASAPNodeId, Vec<((i64, i64), WindowLocation)>>; pub struct Written { pub bytes: u64, pub sync_ns: u64, pub not_persisted: u64, + pub locations: Vec<(PhysicalASAPNodeId, WindowLocation)>, } impl ViewFiles { + pub fn with_segment_ms(self, segment_ms: i64) -> Self; + pub fn seal(&mut self, group: usize) -> io::Result<()>; + pub fn delete_expired(&mut self, group: usize, oldest_kept_end_ms: i64) -> io::Result<usize>; + pub fn index(&mut self, groups: &[Vec<(MaterializedView, SchemaRef)>]) -> io::Result<ViewIndex>; } // data_plane/src/window_cache.rs (new) +pub struct WindowKey { pub view: PhysicalASAPNodeId, pub end_ms: i64 } +pub struct WindowCache { .. } +impl WindowCache { + pub fn new(max_bytes: Option<u64>, idle: Option<Duration>) -> Self; + pub fn insert(&self, key: WindowKey, batches: Arc<Vec<Batch>>, bytes: u64, now: Instant); + pub fn get(&self, key: WindowKey, now: Instant) -> Option<Arc<Vec<Batch>>>; + pub fn get_or_load(&self, key: WindowKey, now: Instant, load: impl FnOnce() -> Result<(Arc<Vec<Batch>>, u64), Error>) -> Result<Arc<Vec<Batch>>, Error>; + pub fn evict_idle(&self, now: Instant); + pub fn set_target_bytes(&self, target: Option<u64>); + pub fn remove(&self, key: WindowKey); + pub fn stats(&self) -> CacheStats; +} // data_plane/src/memory_budget.rs (new) +pub struct CgroupMemory { pub max_bytes: Option<u64>, pub current_bytes: u64, pub anon_bytes: u64, pub file_bytes: u64 } +pub fn read_cgroup(dir: &Path) -> io::Result<CgroupMemory>; +pub fn default_view_cache_budget(cgroup: &CgroupMemory, other_pools_bytes: u64) -> Option<u64>; +pub fn monitored_target(budget: Option<u64>, cgroup: &CgroupMemory, cached_bytes: u64) -> Option<u64>;CLI:
--view-cache-max-bytes,--view-cache-idle-ms,--view-segment-ms,--view-read mmap|pread.Algorithm
Pendingand inserted into the cache; persist threads encode its columnar fragments and append the record to the group's active segment, then acknowledge the locations; the committer turns the windowStored.Storedwindow not in the cache is decoded once (single flight) from its fragment: borrowed from the mapping for sealed segments,preadfor the active one; inserted if it fits.Storedwindows, by idle time and the byte budget; a 1 s monitor ofmemory.current/memory.statlowers the target when anonymous memory runs high.Tests (failing first)
PARITY_INGEST_THREADS=1,4,8)tests/planner_executor_parity.rswith_every_view_read_cold_*view_cache_max_bytessrc/persist.rsWritten::locationsis emptysrc/persist.rssrc/window_cache.rssrc/window_cache.rssrc/window_cache.rstests/view_tiering.rstests/view_tiering.rssrc/persist.rs,tests/view_tiering.rsseal/delete_expirednot implemented; install refusesview_segment_mstests/view_tiering.rstests/view_tiering.rssrc/persist.rs,tests/view_tiering.rsindexnot implementedsrc/persist.rsindexnot implementedsrc/memory_budget.rsscripts/tiered_views_cgroup.sh+examples/tier_bench.rstests/view_tiering.rstests/view_tiering.rssrc/persist.rssrc/persist.rsexamples/tier_bench.rs(VIEW_CACHE_MAX_BYTES,VIEW_READ,COLD=1)examples/view_read_bench.rsVerification
See the test run in the PR comments: every new test fails for the reason above; the existing tests are unchanged.
Follow-ups
Push precompute (#854)
Design: docs/design/parallel-precompute.md.
This PR has the design, the approved tests T1–T19 and B1–B2, and the push precompute implementation (
--precompute-mode push). Push is now thedata_planedefault;--precompute-mode windowkeeps the window path.For reviewers
data_plane/src/push.rs: shard instances, thePushStore, the install probe, seal, and the memory budget.engine.rs:PrecomputeJob::Push,PoolEvent::PartialandWindowTasks::push_windowreuse the pool's reorder buffer, merge and barriers.jobcolumn.PARITY_PUSH_SHARDS.Reducechain does not compile.What push does
Scans read exactly the window (checked by a probe at install) is built by push. Other groups stay on the window path.--precompute-memory-budget-bytesis checked against the instances' run memory. While an older window is open anywhere, state may go over the budget until its seal frees it. A lone window over the budget fails alone.precompute_push,precompute_seal(by group and shard),precompute_combineandprecompute_commit.asap_precompute_state_bytes,asap_precompute_open_instancesandasap_window_commit_lag_seconds.asap_samples_total{outcome="late_for_views"}.pipelines::combine_rule(s)implement the rule table.Results
The design doc records E1/E2 in D1, D2, D8 and D9, and has a B1/B2 section.
B1/B2 (typical 60 s / 10 Hz dashboard, 12 views, raw data not kept, K ingest shards = K precompute threads, paced at 10 Hz). Push coalesces each shard's samples into morsels of up to 32,768 samples or 1 s before folding (
--push-batch-samples,--push-batch-max-ms); a seal folds what is pending first.data_planedefault (--precompute-mode windowkeeps the window path).Core scaling
Setup.
0..K: physical cores first, then SMT siblings.Push.
Window path (with
--precompute-threads K).The full tables are in the design doc's B section.
Verification
cargo test -p data_plane: every test passes.push_precompute: 15 passed, 3 ignored (T9 and T16 are out of scope for this PR).precompute_pool,ingest_shards,planner_executor_parity(T1, T2) and the rest: all pass.PARITY_PUSH_SHARDS).Remote Write decode (#861)
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