Repository navigation
feat: execute ASAPPlanner main's InstallablePlan through asap-executor - #852
Merged
Merged
Conversation
Pins ASAPPlanner 1760a69f (asap-planner, asap-executor). The plan file is now wire version 15: a PhysicalASAPDAG with each view's and query-time Scan's retention_ms, and the query texts. control_plane: plan_installable returns (InstallablePlan, SelectedPlanReport); deployment inputs are DeploymentCapabilities and CostInputs; --cost-inputs, --report; load_plan checks the plan compiles. The backend declares query_time_results_retained: false (no view refreshed on first read yet). data_plane: the stored-summary, precompute, per-sample and raw-window modules are replaced by the executor. A time-indexed store keeps raw samples (Remote Write) and view rows (InMemoryDataStore); ingestion runs one ingestion run per refresh group window; each query is one query run of its root. Views are kept a margin past their retention so queries behind ingestion are answered. Raw samples are no longer read from Prometheus. Tests: planner_executor_parity compares the data plane over HTTP with the Planner executor in process on 14 public workloads, raw data kept or not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The deployment capabilities gained counter semantics, state families not mergeable across windows and excluded candidates; the backend keeps their defaults. The parity test binds its reference raw tables for appending, since binding a table whole is now test-support only.
Queries no longer queue behind ingestion on the engine thread. The engine thread publishes a snapshot of the store after each command; query-N worker threads (--query-threads, default one per core) each run one query to completion over the newest snapshot. A run's output stream is not Send, so a run never moves between threads. The store is copy on write: materialized views move from the executor's InMemoryDataStore to a ViewStore whose clones share every batch, with the same tiling read and retention. Raw data is cloned when a snapshot still reads it; the next commit replaces it with shared columnar panes.
The engine thread becomes two: the ingest thread stores samples, keeps the watermark and closes refresh windows; the precompute thread runs each closed window's ingestion run and publishes the views. A refresh reads the raw data as it was when its window closed (the snapshot travels with the job), so it reads the samples the serial engine read. Closed windows not yet refreshed are bounded (--max-precompute-backlog, default 256): when the backlog is full the ingest thread waits, its queue fills and Remote Write gets 503. The backlog is reported on /api/v1/status/asap. Raw samples are held columnar by pane: each Remote Write request's samples of a pane become one immutable chunk (time, value and a series code per row; series identity text computed once per series when it is interned); a pane the watermark has passed is compacted into one chunk; eviction drops whole panes and reads never return samples at or before the eviction cutoff. The pane width is the gcd of the refresh groups' widths and phases and 60 s. A read returns one batch per chunk of the panes overlapping the range, the open pane's chunks included, filtering only chunks that straddle the range. Tests: a query is answered from the refreshed views while a refresh is held; pane eviction; the columnar read returns the row-wise read's rows.
…; ingest bench Threads are named ingest, precompute and query-N. Each phase records its thread CPU time (CLOCK_THREAD_CPUTIME_ID) and wall time: Remote Write decode on the HTTP threads, append on the ingest thread, each refresh group's ingestion runs on the precompute thread, and each planned query's runs on the workers. GET /metrics exports them in the Prometheus text format with query latency, sample and window counters, the queued samples and precompute backlog, the watermark lag, the samples, panes and bytes held as raw data, the bytes of views, RSS, and each thread's CPU time by name. scripts/profile.sh records a perf profile of a running data_plane and writes a flamegraph. The ingest_bench example feeds Remote Write requests in process and reports samples per second and CPU per thread. The README describes the threads, the backlog bound and the metrics.
… per evaluation time What runs once is the plan's decision, by each query-time node's Lifetime. A OneEvaluation node that several queries' runs reach is cut out of them into a run of its own; each query run binds it as a materialized view slot (an on-first-read descriptor, so asap-executor is unchanged). Its output at evaluation time T lives in the view store's query-time partition, keyed by (T, node): the first run that needs it computes it while concurrent runs wait for it (single flight), later runs read it, and results are dropped once T is more than --query-time-results-retention-ms behind the newest evaluation time or when more than --query-time-results-max-bytes are held. A failed computation is not kept. A plan that would compute any other node in several queries' runs is refused at install. --no-shared-results computes the node in every query's run, as before, for comparison. /metrics exports the partition's bytes, entries, computes and hits. Tests: two queries of #509 Example 1 sharing a OneEvaluation node, run concurrently at two evaluation times, compute it once per time and answer as runs that compute it themselves; a plan that marks that node None is refused; the partition's single computation and expiry. The parity test passes with sharing on (126 of 126 queries equal).
…r step /api/v1/query_range parses query, start and end (Unix seconds) and step (seconds or a Prometheus duration), refusing a non-positive step, an end before the start or more than 11,000 steps with 400 bad_data as Prometheus does. A planned query is evaluated at every step, the steps in parallel on the query workers (a shared OneEvaluation node is computed once per step time), and answered as a Prometheus matrix; it is not answered if any step is not, and is then forwarded with the reason, or refused under --no-forward, as an instant query is. Tests: a planned range query's value at each step equals the instant answer at that time; an unplanned range query is refused under --no-forward; the parity harness plans the mixed workloads 01-03 with range_evaluation over each query's last three evaluations and compares every step with the Planner executor's query run at that time (162 of 162 steps equal).
Each view has one append-only file in --view-dir (default asap-views; --no-view-persistence keeps views in memory only): one record per refreshed window, a little-endian length and a MessagePack payload with the window's (start, end] and rows, synced before the next window is refreshed. At startup the records within each view's retention are loaded back into the view store, and a window every view of its group already stores is not refreshed again (windows_already_stored). A partial record at a file's end is ignored. Raw samples and open windows are not persisted. Plain values and exact states (ExactAccumulator, IncreaseAccumulator, which the executor serializes) are stored. Sketch states have no byte encoding in asap_sketchlib or the executor yet, so a window of a view holding one is not written; /metrics counts those windows (asap_view_windows_not_persisted_total) beside the bytes written, the sync time and the windows loaded. EngineOptions is no longer Copy: it holds the view directory. Test: a data plane restarted over the view files of an earlier one answers a query as before without any sample written again.
docs/design/data-plane-demo.md describes the demo: goals and non-goals, the ingest, precompute and query-worker threads, columnar panes and the open pane, backpressure, OneEvaluation results shared per evaluation time as the plan decides, range queries, view persistence, the /metrics names, the evaluation design and the rejected alternatives. The README links it.
The design records why one chain width makes long windows at a low sample rate no cheaper than raw scans, and the planned levels of chains (a coarse chain computed from the fine chain's view at ingestion time), with their cost and the work they need. The alternatives table records that stored views are bounded, separately from how a window is computed and from freshness at the open window.
…an; safe restarts Sketch states are stored as asap_sketchlib's ASAPv1 bytes with the kernel they rebuild (DDSketch, KLL, Count-Min, KMV, Hydra-KLL), read and rebuilt through the executor kernels' public sketch fields. HyperLogLog, UnivMon, Count-Min-with-heap and Hydra-Count-Min kernels expose no way to rebuild their state, so views holding them are still not persisted and are counted. Review fixes: - One file per refresh group, one record per window holding every view appended, one fdatasync per window (was one per view and window). - Each file starts with a header naming the plan (a hash of the plan file) and the group; another plan's file is renamed *.stale and never loaded, so a changed plan cannot load wrong views. - A torn or oversized last record is cut off at load, so records appended afterwards stay aligned; a garbage length no longer sizes an allocation. - A window is skipped per view: a view that already stores it is not appended to again and no duplicate record is written, while the group's other views still get it. - After a restart that loaded views, a declared stream start no longer makes the first window complete, so windows whose samples arrived before the restart stay missing instead of being stored empty. - The ingest thread no longer overwrites windows_already_stored. Tests: each persisted kernel round-trips through bytes (re-encoded bytes, estimates and merges equal); torn tail and other-plan files; exact, DDSketch and KLL views answer alike after a restart; another plan's files are not loaded; windows before a restart are not stored empty.
…orkers - Query-time results: an entry is created in a computing state under the map lock, so expiry never drops one being computed and its bytes are counted only while it is held; a failure reaches the runs that waited for it and is not kept; a result is kept only for a time the watermark has passed (a client's far-future time is computed per run), and results expire behind the watermark, not behind the newest client time. The ingest thread publishes the watermark with the raw data. - Range queries: at most one step per query worker in flight; the first unanswered step, or the client going away, drops the remaining steps, and a worker skips a step nobody waits for. Steps are measured as phase=query_range_step and requests as asap_range_query_latency_seconds, apart from instant queries. A range is refused, as Prometheus does, only when (end - start) / step exceeds 11,000. - A panic in a query run answers that query with an error; the worker keeps serving. - Smaller: no String per sample in ingest_at; a chunk's series identity dictionary is built on its first read; PublishedStore::run_store removed; series_ids doc; the bench reuses metrics::thread_cpu_seconds (clock ticks from sysconf), persists views by default and can split a scrape into many small requests. Tests: single computation and expiry behind the watermark; waiters share the computer's result or failure; range steps measured apart.
Copies, unchanged, ASAPPlanner's chains-10m-5m-3m-10s, rollup-quantile-nested-labels and topk-by-job-and-global sketch-plan workloads and the rangeheavy-t5-q05-q09-1h memo example, plus the demo's dashboard workload, into the parity harness (raw data kept and not). The dashboard plan's quantile chain is a KLL sketch, which seeds its compaction coin at random, so a plan with KLL is compared within 5%; every other plan exactly.
Adds how the precompute and query engines execute six plans of different shapes, corrected to the implementation (refresh groups in plan order, a Scan under two groups read by each, OneEvaluation nodes cut when read by several queries' runs, range steps bounded per worker), and corrects the design after review: late samples, view retention wording, the new public surface, query memory beyond the run limit, worker panics, query-time result retention behind the watermark, range-query bounds and metrics, per-group view files with one sync per window tied to the plan, restart behavior, sketch persistence and its gaps, and follow-ups.
The data_plane binary (and the benches) use jemalloc: Remote Write decoding and query runs allocate many small, short-lived objects across threads. The write handler's decode-and-intern step moves into remote_write::decode_samples, and the decode_bench example measures it per sample for two request shapes. decode_bench, microseconds per sample (system allocator -> jemalloc): one series per sample (10,000 x 1) 1.80 -> 1.51; 100 samples per series (100 x 100) 0.083 -> 0.083.
…es cache decode_samples walks the decompressed protobuf in place instead of building a WriteRequest of owned Strings. Each TimeSeries' encoded label bytes are the key of a per-thread cache of interned series, so a known series costs one hash and one compare, with no lock and no allocation; only a new series is parsed, validated (UTF-8, __name__, no duplicate label) and interned. The samples vector is sized from the body up front. Errors are those of the full decode. decode_bench, microseconds per sample (jemalloc, before -> after): one series per sample (10,000 x 1) 1.51 -> 0.38; 100 samples per series (100 x 100) 0.083 -> 0.089. Test: the in-place decode gives the full decode's samples, series and errors.
…r file View files are synced every --view-sync-interval-ms (default 5,000: VictoriaMetrics' default -inmemoryDataFlushInterval as of v1.155.0) instead of after every window, and the precompute thread also syncs when no window closes, so a refreshed window is durable within that interval, the same class of guarantee VictoriaMetrics gives its in-memory data; 0 syncs after every window. The files are synced when the engine stops. A text (label value or series identity) is stored once per file: each record carries the texts it adds to the file's dictionary and rows hold indices. Loading replays the dictionary, and appends after a restart continue it. Test: a second restart after windows written since the first reads them back alike (dictionary continued across restarts).
result_samples parsed every row's series identity JSON into a label map. The interner now indexes series by identity text, so a row of an input series takes its labels from the interned series; only a series the query built (its labels changed) is parsed.
ingest_at looked each sample's metric up in a BTreeSet<String> and a SipHash map keyed by an Arc<str> clone, and checked every refresh group for a start. Samples of one metric come together, so the last metric is checked by pointer first, the per-request metric list holds whether a Scan reads it and its eviction cutoff (taken at its first routed sample, as before), and groups are checked for a start only while one has not started.
inferno stays the default; without it the FlameGraph perl scripts in FLAMEGRAPH_DIR (default /mydata/bin/FlameGraph-41fee1f) draw the graph, and the error names whichever tools are missing. Full stacks need CARGO_PROFILE_RELEASE_DEBUG=true.
…e_from_disk Pins ASAPPlanner main 056da657, whose executor gives every sketch kernel one interface: sketch() to read its asap_sketchlib state and restore_from_disk to rebuild it. All persisted kernels now use it, and four more persist: HyperLogLog (with its precision), weighted frequency (Count-Min or Count Sketch, with or without a heap), UnivMon (with its key-byte counters) and Hydra-Count-Min, whose grid is shared by every group of a build and is stored once per record and rebuilt once. A UnivMon whose heaps mix key types has no ASAPv1 encoding; its windows are counted as not persisted and the refresh goes on. The design doc records the executor follow-ups the profile found (DDSketch merge clones before merging; group tables not pre-sized). Tests: every kernel round-trips through bytes (re-encoded bytes, readouts and merges equal; a merged UnivMon compared on L2 only, since its merge breaks heap ties nondeterministically); a shared Hydra-Count-Min grid is stored once and answers every group as before.
…te path The precompute thread publishes a refreshed window and queues its rows; a pool of --persist-threads persist-N threads (default a quarter of the cores, 1 to 4) encodes, writes and syncs them. Refresh group g goes to thread g % n, so each file has one writer and keeps window order. The queue is bounded by bytes (--max-persist-backlog-bytes, default 256 MiB); only when it is full does the precompute thread wait, exported as asap_view_persist_wait_seconds_total, with asap_persist_backlog_bytes and asap_persist_backlog_windows. Each persist thread syncs its files every --view-sync-interval-ms on its own timer, and writes and syncs everything queued when the engine stops. An event-time barrier answers once the windows before it are written, without the precompute thread waiting. Tests: with every window's write delayed, windows are refreshed and answer at once, and stopping the engine still writes every queued window; with three persist threads, every query of a plan with several refresh groups answers alike after a restart.
This was referenced Nov 23, 2026
zzylol
marked this pull request as ready for review
November 23, 2026 21:08
Add series_ids::Labels for a shared label set and use it in the matrix response and the result-label table, so clippy::type_complexity no longer fires on newer toolchains.
A step given as a duration (e.g. 9223372036854775807ms) was not capped: (end - start) / step was 0, so the step count check passed, and start + i * step wrapped, so the evaluation times never ended and a range request collected an unbounded list. Refuse a step beyond MAX_TIME_MS and stop the evaluation times instead of overflowing.
Describe the precompute committer and its precompute-N workers, the result cache and its flags, the query-time results' default byte bound, the pinned Planner commit, and name the example without an issue number.
Sharded ingestion and multi-level window chains are built: say what remains of each. Ingestion-time windows run in parallel, ordered by the refresh task graph. Replace issue and PR numbers with short descriptions, and mark the plan listings as illustrative output of an earlier Planner commit.
RawData::read clamped a range's start to the eviction cutoff, so a step whose window reached samples already evicted was answered from the samples left (a partial window), served as a plan answer and kept in the result cache. A range starting before the evicted samples now fails the read, which the run reports like a missing view window (Unanswered::MissingRows): the step is forwarded, or refused with --no-forward, and never cached. A range before the first sample ever received still reads as empty, as Prometheus answers it.
Module docs name the ingest shards and coordinator, the precompute pool and committer, the persist threads and the range queries; the store's raw table includes the series identity; view files are one per refresh group, synced on the sync interval by their persist thread; query-time results are kept behind the watermark.
…ecode read_group skipped a record that did not decode and loaded the ones after it, which then read the per-file text dictionary shifted by the texts the skipped record added. Treat it as a torn tail: load the records before it and cut the file there.
A Remote Write sample at i64::MIN reached window arithmetic (window_end negates the timestamp) and overflowed, which panicked an ingest shard and stopped the engine. The router now drops a sample further from the epoch than prometheus::MAX_TIME_MS and counts it as future or late. It is done in the router rather than in decode_samples because the router keeps the per-outcome sample counters.
Only its own tests called it; it now lives in the tests module, and decode_samples states its errors itself.
Only a test called it; the test interns label pairs with intern_pairs.
serde_json is already a normal dependency, which tests can use.
profile.sh defaulted FLAMEGRAPH_DIR to a path on one machine. It now uses FLAMEGRAPH_DIR when set, else the scripts on the PATH.
main set the test-only EngineOptions fields by hand; it now fills them with ..EngineOptions::default(). malloc_conf need not be pub: its export_name keeps the _rjem_malloc_conf symbol global, which jemalloc reads.
The router accepted a sample between a metric's eviction cutoff and the published watermark when a query-time Scan reads that metric, but answers at times the watermark has passed are final: kept in the result cache and the query-time results. A cached answer then differed from what a fresh run returned once the late sample arrived. Of the two consistent fixes, dropping is the smaller one: the watermark already means no sample at or before it is expected (it includes the allowed lateness, and a barrier states every sample at or before it was written), and the views already ignore such samples (their windows are closed). Treating those answers as not final would instead disable the result cache and the shared query-time results for every query reading raw samples. Such samples are now counted as dropped_late; eviction still follows the eviction cutoff.
Only tests read it. The server tests now check the samples the engine routed (accepted, dropped or unrouted) on /api/v1/status/asap.
The view store and the view-file loader each converted retention_ms to i64 and counted back from the newest window; both now call store::oldest_kept_end, and the engine converts the query-time results' retention with ingestion::millis like the other duration options.
SketchKernel, FrequencyKind, decode_sketch, PartitionReads, Routed, IngestionError (with Ingestion::new and Routing::route that return them), MAX_TIME_MS, MAX_RANGE_STEPS, BadTime, BadRange (with the parsers that return them) and FORWARD_REASON_HEADER are pub(crate): no test or example uses them. encode_sketch, which only tests call, moves into the persist tests.
Move the helpers the integration tests repeated into tests/common: posting a Remote Write request, the event-time barrier (and its status), GET returning status, execution header and JSON, the instant query URI, a /metrics value, per-job answers, the public workloads, the no-forward engine options and the one-query plan builder. ingestion::wall_clock_ms is public so a test reads the clock the data plane reads.
This was referenced Nov 23, 2026
Closed
Closed
zzylol
added a commit
that referenced
this pull request
Nov 24, 2026
…ster Remote Write decode (#864) Tiered view storage, push precompute by default, and a faster Remote Write decode in the data plane. - Tiered view storage: views are written per refresh group and retention as time segments, deleted past retention. Decoded windows are cached in memory up to a budget (from the cgroup's memory.max) and an idle time; other windows are read back from mapped segments, with states read in place. Recovery indexes record heads without decoding. - Push precompute, the default (--precompute-mode push): ingest shards fold samples into the open windows' pipelines as they arrive, in batches, under a precompute memory budget; groups that cannot be pushed, and every group under --precompute-mode window, run one ingestion run per closed window. - Remote Write decode from 652 to 212 ns per sample. #852's review fixes apply to the new paths. Review fixes: a mixed push/window plan no longer drops samples an open push window reads; the memory budget applies with several push groups; ranges before a view's first window are read only with a declared stream start; segments are never truncated; on-disk heads are bounds-checked; a cache remove racing a load is not undone. Pins ASAPPlanner 737bfb1 with asap_sketchlib patched to 355093f.
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.
Design: docs/design/data-plane-demo.md (the data plane for the comparison with VictoriaMetrics: threads, columnar panes, shared query-time results, range queries, view persistence, metrics, evaluation design).
Supersedes #845. #845 bumps the ASAPPlanner pin only and does not compile: the Planner's plan file, executor API and planning inputs changed under it (66 compile errors). This PR pins ASAPPlanner main
846a70aand runs the plan through the Planner's executor.What changes for a user
control_planewritesplan.json(wire version 15) and, with--report report.json, Stage 3'sSelectedPlanReport(cost, predicted usage per node and per query).--plan-selection-settingsis replaced by--cost-inputs.--measured-operation-costsand--ignore-accuracy-guaranteesare kept.data_planekeeps the raw samples it receives by Remote Write. Planned queries no longer read raw samples from Prometheus. New flags:--run-memory-limit-bytesand--view-retention-margin-ms./api/v1/status/asapreportsingestioncounters (samples, and windows refreshed, failed or skipped) in place ofprecomputeandquery_run.query_time_results_retained: false, so the Planner selects no view refreshed on first read. The data plane does not refresh such views yet./api/v1/query_range), one evaluation per step.--view-dir, defaultasap-views;--no-view-persistence): one file per refresh group, one record per window, synced every--view-sync-interval-ms(default 5 s) on--persist-threadsthreads, tied to the plan by a hash; sketch states asasap_sketchlib's ASAPv1 bytes.GET /metricsexports a per-phase CPU breakdown and the data plane's counters in the Prometheus text format.--query-threads,--precompute-threads,--max-precompute-backlog,--no-shared-results,--query-time-results-retention-ms,--query-time-results-max-bytes,--view-dir,--no-view-persistence,--result-cache-bytes,--no-result-cache,--ingest-threads,--persist-threads,--max-persist-backlog-bytes,--view-sync-interval-ms.How the data plane runs a plan
InstallablePlan::from_json,validate,materialized_views,ingestion_refresh_groupsDataStore: raw samples per scanned metric as(ts, value, $promql_series_identity, labels...), columnar by pane; view rows in a copy-on-write view store with the executor's tiling readW, phasep), oneexecute_ingestionrun per window(e - W, e]once the watermark reachese; rows appended with the range they covercompilewith the views it reads,Scope::Query), rows turned into a PromQL vector; a query-timeOneEvaluationnode several queries read is compiled on its own and bound as a view slotThe plan's retention counts back from the newest evaluation, but ingestion refreshes windows ahead of the queries it answers. Views and query-time raw samples are therefore kept
--view-retention-margin-ms(default 60 s) past their retention. The end-to-end run found this: without the margin, a query at a time 20 s behind ingestion found its oldest windows already dropped.Threads (before → after)
Before: one engine thread ran Remote Write appends, every closed window's ingestion run and every query in turn. While a window's views were computed, Remote Write queued (503 when full) and queries waited.
After:
ingest-0..N(--ingest-threads, default a quarter of the cores)ingest(coordinator)precompute(committer),precompute-0..N(--precompute-threads, default a quarter of the cores, 1 to 4) andprecompute-queueexecute_ingestionrun per closed window on a worker, or one per worker over a share of the series; the committer merges the parts and stores each group's windows in window orderpersist-0..N(--persist-threads, a quarter of the cores, 1 to 4)query-0..N(--query-threads, default one per core)A run's output stream is not
Send, so a run never moves between threads; what crosses threads (QueryEngine,RunStore,RawData,ViewStore,Precompute) is checkedSend/Syncat compile time. At most--max-precompute-backlog(256) windows wait for precompute; when full, the coordinator waits, the shards' queues fill and Remote Write gets 503 (see below). A query does not wait for queued writes; the event-time barrier does (it answers once its windows are refreshed).Ingest shards: correctness and backpressure (6d40b3d..8682b64)
With several ingest shards, parity lost 16–20 answers per run (sums and top-k low): windows closed before every shard had appended its samples. The rule is now: the watermark moves only behind a flush, and every pass that took a report or a barrier sends one. A flush means every shard has run what was admitted before it.
--max-queued-samples, Remote Write gets 503, and the reports waiting stay bounded. Before, the shards kept draining into an unbounded channel: no 503, no eviction, unbounded memory.Borrowed from the ASAPQuery precompute engine (
asap-query-engine/src/precompute_engine/): routing by series hash, a cross-worker watermark where workers with no samples do not hold it back, a periodic tick, the close-past-the-end rule, and dropping and counting late samples. Its watermark, unstarted-worker, boundary and late-data tests are ported at the engine level. ASAPQuery closes each worker's own partial windows; here one coordinator closes a window over every shard's raw data, so the cross-shard minimum is reached by the flush.struct ShardReport { shard: usize, raw_data: Arc<RawData>, newest_ms: Option<i64>, first_seen: Vec<(Arc<str>, i64)>, - now_ms: i64, + /// Samples of the batch, counted out of the queues when applied. + samples: u64, } enum Command { Report(ShardReport), - Flushed, + /// The shard numbered here has run every message sent before the flush. + Flushed(usize), AdvanceWatermark { barrier_ms: i64, reply: oneshot::Sender<i64> }, Stop, } -fn flush(shards: &[Sender<ShardMessage>], shared: &Shared) +/// Sends a flush under the admission lock; returns the time it was sent. +fn flush(shards: &[Sender<ShardMessage>], shared: &Shared) -> i64 impl Ingestion { - pub fn observe(&mut self, first_seen: &[(Arc<str>, i64)], now_ms: i64) + pub fn observe(&mut self, first_seen: &[(Arc<str>, i64)]) + /// Sets the clock the watermark is capped at: the last flush's time. + pub fn advance_clock(&mut self, now_ms: i64) } pub struct EngineOptions { + /// For tests: every shard but the first waits this long per batch. + #[doc(hidden)] + pub shard_delay_ms: u64, }The boundary between the coordinator and the precompute is unchanged:
PrecomputeJobgoes over the bounded jobs channel, and the coordinator blocks on it.Regression tests (
data_plane/tests/ingest_shards.rs, one engine against one shard or several). Each was shown to fail on the old behaviour:a_shard_running_ahead_does_not_close_windows_early(8 shards, 7 slowed by 20 ms)a_watermark_capped_at_the_clock_moves_only_behind_a_flush(samples up to 1 s ahead of the clock, 4 shards, 3 slowed by 250 ms)samples_at_a_window_end_in_a_later_request_join_the_window(1 and 8 shards)a_late_sample_is_dropped_on_any_shard_count(from ASAPQuery'stest_late_data_drop)a_precompute_that_cannot_keep_up_reaches_remote_writea_barrier_during_another_barriers_flush_covers_writes_before_itbarriers_during_one_flush_all_answerParity (
PARITY_INGEST_THREADS=n), on 8682b64's code: 148/148 queries and 162/162 range steps, 3 runs each at 1, 4 and 8 shards.ingest_shards: 9/9, 3 runs.Precompute task pool and windows split by series
Before: one
precomputethread computed every closed window in turn. Groups that closed together queued behind each other, and one big group's window took as long as one core needed. With the 60 s, 10 Hz dashboard (10k series ofdataand ofdata_total; one refresh group of twelve per-series views, 12M samples per window), each window took 23.8 s on one thread and was ready 24.7 s after its end. Every query at a 3 s or 6 s delay was refused.After:
--precompute-threads(default a quarter of the cores, 1 to 4; 1 is the old behaviour).Windows as tasks. Each closed window is a task. Windows of different groups, and of one group, compute in parallel on
precompute-N. A per-group reorder buffer commits each group's windows in window order. The committer (precompute) is the view store's only writer and publishes once per pass. A group that reads another group's views starts a window only after the windows it reads are committed (RefreshTaskGraph, built at install). A group holding an operator that may carry state across windows runs serially.Windows split by series. A group can be split when every node computes each series alone: time-series
Scans that keep the series identity, row filters, and summaries with aPerEntityreduction. If it also reads no other group's views, each window runs as one task per thread, and partireads the series whose id isimodn. The committer merges the parts' rows into the executor's group key order, one batch per view, so the stored views are byte-identical to one run's. Any other group runs whole. The install log says which groups are split, and/metricsexportsasap_precompute_window_parts. Merging partial states of a node that combines series would change float sums in the last bits, so it is not done.Why a task can run on its own. A task is a pure function of immutable inputs:
Arcpanes never changed in place);Its output stays invisible until committed, and each
execute_ingestionstarts fresh.Backlog and metrics. The backlog bound is unchanged (plus up to two windows per worker in flight), and backpressure still reaches Remote Write. New metrics, per group: queue wait, commit wait, and window-ready time (window end → committed). For the pool: busy seconds and thread count.
examples/ingest_bench, paced (live rate), views plan, 16 pinned cores of a shared 56-core host, allowed lateness 1 s, 420 s, one run each. Window-ready time is from the window's end to its commit, the 1 s allowed lateness included:At 12 threads every window is ready within 4 s of its end, so a 6 s query delay is served. A split run costs about 8–15% more CPU than one run: each part reads and cuts every chunk of the window. Before chunks were cut once per run, the extra cost was 70%.
Windows in parallel only,
random-mixed-seed-862-01(three groups, 10k series per metric, 300 s):The mixed-workload rows were measured before the series split. In those runs, the 4-thread CPU includes the cost of cutting chunks per scan, which is now fixed.
Columnar raw store
Raw samples are held per pane (width: gcd of the refresh groups' widths and phases and 60 s). Each Remote Write request's samples of a pane are one immutable chunk: time and value arrays and a per-row series code into the chunk's series, whose identity JSON is computed once when the series is interned. A pane the watermark has passed is compacted into one chunk. Eviction drops whole panes, and a read never returns a sample at or before the eviction cutoff, so answers match the row store exactly.
Open pane, chosen for query-time
Scans: the ingest thread publishes the raw data after every request (copy on write: per-pane chunk lists are copied, chunks are shared), and a read returns one batch per chunk of every pane overlapping the range, the open pane's chunks so far included; only a chunk straddling the range is filtered. This is the simplest option that needs no lock and no copy of the open pane per read; its cost is many small batches when many small requests fall in one open pane.Shared query-time results (the plan decides)
A
OneEvaluationquery-time node that several queries' runs reach is computed once per evaluation time T: the first run computes it while concurrent runs wait (single flight), later runs read it from the view store's query-time partition, keyed by (T, node), kept--query-time-results-retention-ms(60 s) behind the newest T, bounded by--query-time-results-max-bytes. Any other node two queries' runs would compute makes the plan refused at install. No executor change: the node is bound as an on-first-read view slot.Result cache
Before: a range request refreshed 15 s later recomputed every step. After: each planned query's answer at evaluation time T is kept, keyed by (query root, T), once it is final: the run succeeded (every view window it read is stored, and stored windows never change) and, if the root reads raw data at query time, T ≤ the watermark its snapshot was published with. A range request runs only the missing steps; an instant query at T reads a range step at T. Eviction: T more than the plan's longest retention plus
--view-retention-margin-msbehind the watermark, then LRU beyond--result-cache-bytes(256 MiB). A run now reads the watermark before the snapshot, which also closes that race for shared query-time results. The steps of one range request read one snapshot, and raw chunks read whole are converted once per request.examples/range_bench, dashboard workload, 1k series per metric, four 1 h panels at 15 s steps (964 steps), 56-core x86 server:The rest of a cached refresh is JSON encoding of the two 1,000-series matrices (0.4–0.5 s each). Reading one snapshot per request changes cold CPU by about 3 % (within noise): the cold cost is DDSketch merges, not reads. The Planner's cost model does not know about the cache (follow-up in the design doc).
/metricsCPU breakdownasap_phase_cpu_seconds_total/asap_phase_wall_seconds_total/asap_phase_runs_totalbyphase:remote_write_decode,append,precompute(per refresh group),query(per query text); thread CPU fromCLOCK_THREAD_CPUTIME_ID. Alsoasap_query_latency_seconds(histogram per query),asap_samples_total,asap_windows_total,asap_samples_queued,asap_precompute_backlog_windows,asap_watermark_lag_seconds,asap_raw_data_bytes,asap_view_bytes,asap_query_time_result_*,asap_view_persisted_bytes_total,asap_view_sync_seconds_total,asap_view_windows_not_persisted_total,process_resident_memory_bytes, andasap_thread_cpu_seconds_total{thread}.scripts/profile.shwrites a flamegraph of a running data plane.Ingest throughput, before and after
cargo run --release -p data_plane --example ingest_bench -- SERIES 300 PLAN [REQUESTS] [memory]: in process, 300 s of 1 s scrapes sent by Remote Write as fast as accepted, then a barrier at the last sample. Workloadrandom-mixed-seed-862-01;rawkeeps raw samples (4 views, 25 windows),viewskeeps none (7 views, 325 windows). "Refreshed" is samples/s until every window is refreshed; "acknowledged" until every write is accepted. Views are persisted (the default). One run each on a shared host, so the numbers are indicative."Now" includes jemalloc, the in-place Remote Write decode, the interval sync (5 s) and the per-file text dictionary. Writes are acknowledged at 2.0–2.3M samples/s. View-heavy plans are limited by the precompute thread and, at 10k series, by the disk: the views plan writes 6.5 MB per window (2.1 GB per 5 minutes) and syncing it took about 200 s on this shared, nearly full disk.
Ingest threads (same bench, one client, 16 cores). Acknowledged throughput stays at about 2.2–2.3M samples/s at 10k series and 1.7–1.8M at 100k with 1, 2, 4 or 8 shards: the single bench client, which decodes and sends every request itself, is the limit, not the shards. The table is in the design doc's Measurements section.
Remote Write decode (
decode_bench, µs per sample): one series per sample (10,000 × 1, the feeder's shape) 1.80 (system allocator) → 1.51 (jemalloc) → 0.38 (in-place decode); 100 samples per series (Prometheus' shape) 0.083 → 0.083 → 0.089.Bytes per window written (views plan, 1k series): 0.93 MB with a sync per window and label text per row → 0.64 MB with the per-file text dictionary; raw plan 224 KB → 123 KB; views plan, 10k series, 9.4 MB → 6.5 MB.
View persistence
Every sketch kernel is persisted through the executor's
sketch()andrestore_from_disk(ASAPPlanner #1435): DDSketch, KLL, Count-Min, KMV, HyperLogLog, weighted frequency (Count-Min or Count Sketch, with or without a heap), UnivMon, Hydra-KLL and Hydra-Count-Min (one grid per window, shared by its groups), asasap_sketchlib's ASAPv1 bytes; exact states by their serde form. A UnivMon whose heaps mix key types has no ASAPv1 encoding (anasap_sketchliblimitation) and is counted inasap_view_windows_not_persisted_total; it is 0 for the benchmark and demo plans. Files are synced every--view-sync-interval-ms(default 5 s, VictoriaMetrics' default-inmemoryDataFlushInterval), so a window is durable within that interval; texts are stored once per file. A file of another plan is renamed*.stale; a torn last record is cut off at load; after a restart, windows whose samples arrived before it stay missing.Review fixes
Shared query-time results: no orphaned entries or leaked bytes (an entry is created computing, under the map lock), waiters get the computer's failure, results are kept only for times the watermark has passed and expire behind it. Range queries: at most one step per query worker in flight, the first failure or a dropped client stops the rest, steps measured apart from instant queries, the 11,000-step limit as Prometheus applies it. A panicking query run answers with an error and the worker keeps serving. Not done: the precompute test gate stays on the production path (one uncontended lock per window); test helpers are not yet consolidated into
tests/common; buildingMaterializedViewvalues through serde JSON and the per-request work linear in retained panes are recorded as follow-ups in the design doc.Code deleted, replaced by the Planner
sds.rs(definitions, keys, build order)materialized_views,ingestion_refresh_groupsprecompute.rspane buildsraw_sample_window.rsDataStore::read_raw_datawith the executor'sScan/TimeRangeper_sample.rs(per-sample state updates)query.rsraw fetches from Prometheus,QueryRunpanesTheir tests are deleted with them (
per_sample,precompute,query,query_run,sds,answers).Tests
planner_executor_parity: 18 public workloads (examples/, plus ASAPPlanner'srandom-mixed-seed-86201–06 and four sketch-plan snapshot workloads copied unchanged intodata_plane/tests/workloads/), each planned with raw data kept and not kept. The data plane runs over HTTP with--no-forward; the Planner executor runs in process on the same plan and samples. Result after the re-pin and with shared query-time results on: 36 plans (18 workloads, raw data kept and not; two raw-only workloads cannot be planned without raw data), 148 of 148 queries equal, all with rows. Plans with a KLL sketch are compared within 5%: KLL seeds its compaction coin at random, so two builds of one window differ within its error (the dashboard plan's quantile query). The design doc's six example workloads are among them. The same harness plans the mixed workloads 01–03 withrange_evaluationand compares each range step with the Planner executor's run at that time: 162 of 162 steps equal.a_query_behind_the_newest_window_is_still_answered.concurrency); two queries sharing aOneEvaluationnode, run concurrently at two times, compute it once per time and answer as runs that compute it themselves, and a plan that marks that nodeNoneis refused (shared_results); a planned range query equals its per-step instant answers and an unplanned one is refused (range_queries); exact, DDSketch and KLL views answer alike after a restart, another plan's files are not loaded, and windows before a restart are not stored empty (view_persistence); each persisted sketch kernel round-trips through bytes, a torn tail is cut off, waiters share the computer's result or failure, range steps are measured apart (unit andrange_queriestests);/metricsreports the phases (server); the columnar read returns the row read's rows, pane eviction, and query-time result expiry (unit tests).fixed_intervalbecomesfixed_interval_at, andvalues_non_negativebecomescolumn_signs. Two expectations changed with the Planner's selection:ignore_accuracy_guarantees, because there is no guaranteed plan without raw data. It is bounded by the plan's own α (0.1).Scans differ only by aregioncolumn); answers are still within α.precompute_pool, plus scheduler unit tests inengine.rs):planner_executor_paritypasses withPARITY_PRECOMPUTE_THREADS1, 4, 8 and 12 (KLL within 5% as before).planner_executor_parityasks every query (instant and range) twice with the cache on and once with it off; all three must agree with the reference. Newresult_cachetests: a repeated range runs no cached step; an instant query reads the range step at its time; a step answered before its raw samples arrived runs again (fails if non-final answers are cached); eviction by age and by LRU bytes, view reads by binary search and shared raw chunk conversion (unit tests).cargo fmt --check,cargo clippy --workspace --all-targets -D warningsandcargo test --workspacepass (after the review fixes: data_plane lib 32, ingest_shards 10, planner_executor_parity 2, precompute_pool 6, result_cache 5, server 10, view_persistence 7, plus concurrency, no_forward, planner_executor_answers, range_queries, series_ids, shared_results, view_memory, window_levels).data_plane --no-forward. Four planned queries (rate,increase,max_over_time,sum(sum_over_time)) all run from tumbling-window views refreshed at ingestion. After about 2 h, at three evaluation times, every answer equals Prometheus's own answer exactly (56 + 56 + 1 + 1 series). RSS stayed at 19 MB.Not done yet
AcrossEvaluations).asap_sketchliblimitation).--allowed-lateness-ms.Review fixes (3e52dad..b5570f5)
Independent reviews (correctness; dead code and duplication; doc alignment) before merging. Fixed on this branch, each with a failing test first where it is a behavior change:
stepgiven as a huge duration wrapped the step times, so one request grew aVecwithout endMAX_TIME_MSrefused; step times stop instead of wrapping (44b7122)--no-forward) and never cached; reads before the first sample still succeed, as in Prometheus (5e1159d)Scanwas accepted behind the published watermark after answers at that time were cacheddropped_late(75d4325)type_complexityon the CI toolchainremote_write::decode,series_ids::intern,DataPlane.samples, duplicateserde_jsondev-dependency, itemspubbut used only in the cratedata_plane/teststests/common(b5570f5)scripts/profile.sh; a stray disk-usage filefdatasyncand an old pin; issue numbers in the design doc