Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9d3bd8f
test(precompute): late samples merge into committed windows (failing …
zzylol Nov 29, 2026
edb8405
feat(precompute): merge late samples into committed windows within re…
zzylol Nov 29, 2026
f68d4e8
chore: clippy: name the per-metric route and the query-time entries; …
zzylol Nov 29, 2026
521a2a8
docs: asap_samples_total{outcome="merged_late"} replaces late_for_views
zzylol Nov 29, 2026
10659b3
test(precompute): a late counter sample recomputes its window; a samp…
zzylol Nov 29, 2026
712272c
feat(precompute): recompute order-sensitive windows from raw samples;…
zzylol Nov 29, 2026
dc0a7e5
fix(precompute): a late merge waits only for windows in flight; reade…
zzylol Nov 29, 2026
8f5588f
fix(precompute): a reader that cannot be computed again keeps its row…
zzylol Nov 29, 2026
4c4987e
test(precompute): a late counter sample past the narrow level's reten…
zzylol Nov 30, 2026
3b3eaac
feat(precompute): raw samples kept for recompute as XOR chunks; narro…
zzylol Nov 30, 2026
60942cf
perf(storage): raw data keeps running sample and byte totals instead …
zzylol Nov 30, 2026
a760725
perf(storage): sealing and compressing visit only the panes not done yet
zzylol Nov 30, 2026
fab39b2
perf(storage): appended samples grouped by the interned metric; ahash…
zzylol Nov 30, 2026
5a60272
perf(storage): counter raw kept for recompute compressed in multi-pan…
zzylol Nov 30, 2026
2d75ed9
test(storage): out-of-order requests add chunks and read as one sorte…
zzylol Nov 30, 2026
0867ce6
perf(storage): a request older than its pane's newest sample adds a c…
zzylol Nov 30, 2026
38eaecf
test(precompute): order-sensitive views leave the rest of their group…
zzylol Nov 30, 2026
c6401d9
feat(precompute): a refresh group's order-sensitive views run apart, …
zzylol Nov 30, 2026
5da5b6c
perf(precompute): the raw-compress queue is bounded; past it, shards …
zzylol Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ name; the view tier and push precompute add `asap_view_cache_*`,
`asap_view_cold_read_bytes_total`, `asap_view_segments_marked_cold_total`,
`phase="view_decode"`, `asap_precompute_state_bytes`,
`asap_precompute_open_instances`, `asap_window_commit_lag_seconds` and
`asap_samples_total{outcome="late_for_views"}`. `benchmarks/scripts/profile.sh` records a flamegraph of a running data plane;
`asap_samples_total{outcome="merged_late"}`. `benchmarks/scripts/profile.sh` records a flamegraph of a running data plane;
`cargo run --release -p data_plane --example ingest_bench -- 10000 300`
measures ingest throughput in process (the micro benchmarks are in
`benchmarks/micro/`).
Expand Down
7 changes: 6 additions & 1 deletion benchmarks/micro/view_read_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ fn main() {
let batch = Batch::try_new(schema.clone(), rows).unwrap();
let started = Instant::now();
let written = files
.append(0, (end - 15_000, end), &[(1, std::slice::from_ref(&batch))])
.append(
0,
(end - 15_000, end),
&[(1, std::slice::from_ref(&batch))],
0,
)
.unwrap();
write += started.elapsed();
let location = written
Expand Down
6 changes: 6 additions & 0 deletions crates/data-plane/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub struct EngineOptions {
/// running each batch, so the first runs ahead of the others.
#[doc(hidden)]
pub shard_delay_ms: u64,
/// For tests: how long the ingest coordinator waits, after every shard
/// answered a flush, before it closes windows and publishes the routing.
#[doc(hidden)]
pub routing_delay_after_flush_ms: u64,
/// Persist threads, each writing the view files of every
/// `persist_threads`-th refresh group.
pub persist_threads: usize,
Expand Down Expand Up @@ -154,6 +158,7 @@ impl Default for EngineOptions {
ingest_threads: std::thread::available_parallelism()
.map_or(1, |cores| (usize::from(cores) / 4).max(1)),
shard_delay_ms: 0,
routing_delay_after_flush_ms: 0,
precompute_threads: std::thread::available_parallelism()
.map_or(1, |cores| (usize::from(cores) / 4).clamp(1, 4)),
slow_refreshes: Vec::new(),
Expand Down Expand Up @@ -356,6 +361,7 @@ impl EngineOptions {
slow_refreshes: self.slow_refreshes.clone(),
check_task_inputs: self.check_task_inputs,
shard_delay_ms: self.shard_delay_ms,
routing_delay_after_flush_ms: self.routing_delay_after_flush_ms,
precompute_mode: self.precompute_mode,
push_batching: self.push_batching,
precompute_memory_budget_bytes: self.precompute_memory_budget_bytes,
Expand Down
2 changes: 1 addition & 1 deletion crates/data-plane/src/metrics_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub(crate) fn render(metrics: &Metrics, gauges: &Gauges) -> String {
("dropped_late", stats.samples_dropped_late),
("dropped_future", stats.samples_dropped_future),
("unrouted", stats.samples_unrouted),
("late_for_views", stats.samples_late_for_views),
("merged_late", stats.samples_merged_late),
] {
let _ = writeln!(out, "asap_samples_total{{outcome=\"{outcome}\"}} {count}");
}
Expand Down
241 changes: 199 additions & 42 deletions crates/data-plane/tests/ingest_shards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,50 +209,63 @@ async fn samples_at_a_window_end_in_a_later_request_join_the_window() {
}
}

/// A sample older than a window already closed is dropped and counted,
/// and the window keeps its answer, over one shard or eight. Ported from
/// the ASAPQuery precompute worker's `test_late_data_drop`.
/// A sample of a window already closed is merged into it, over one shard
/// or eight: the window then answers as if the sample had come on time.
/// (The ASAPQuery precompute worker drops it: `test_late_data_drop`.)
#[tokio::test(flavor = "multi_thread")]
async fn a_late_sample_is_dropped_on_any_shard_count() {
async fn a_late_sample_merges_into_its_closed_window_on_any_shard_count() {
for shards in [1, 8] {
let (app, state) = data_plane(shards);
write_seconds(&app, 0..64, 1..=40).await;
// Every sample at 1..=40 s but series 5's at 25 s.
write_seconds(&app, 0..64, 1..=24).await;
write_seconds(&app, 0..5, 25..=25).await;
write_seconds(&app, 6..64, 25..=25).await;
write_seconds(&app, 0..64, 26..=40).await;
common::barrier(&app, 40_000).await;
// Series 5 at 25 s again, with another value: the window (20, 30] is
// closed.
let timeseries = vec![TimeSeries {
labels: [("__name__", "data"), ("instance", "i5"), ("job", "job1")]
.into_iter()
.map(|(name, value)| Label {
name: name.into(),
value: value.into(),
})
.collect(),
samples: vec![Sample {
timestamp: 25_000,
value: 1000.0,
}],
}];
common::remote_write(&app, timeseries).await;
common::barrier(&app, 40_000).await;
let started = std::time::Instant::now();
while state.engine.stats().samples_dropped_late < 1 {
assert!(started.elapsed().as_secs() < 10, "{shards} shards");
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
assert_eq!(
state.engine.stats().samples_dropped_late,
1,
assert_ne!(
common::per_job(&answer(&app, 30).await),
expected(30),
"{shards} shards"
);
// Series 5 at 25 s: the window (20, 30] is closed.
write_seconds(&app, 5..6, 25..=25).await;
common::barrier(&app, 40_000).await;
let stats = state.engine.stats();
assert_eq!(
common::per_job(&answer(&app, 30).await),
expected(30),
(stats.samples_merged_late, stats.samples_dropped_late),
(1, 0),
"{shards} shards"
);
for time_s in [30, 40] {
assert_eq!(
common::per_job(&answer(&app, time_s).await),
expected(time_s),
"{shards} shards, at {time_s} s"
);
}
}
}

/// A sample of a closed window already past its view's retention (30 s
/// plus the 60 s margin) has no window to merge into: it is dropped and
/// counted, and the answers stay as they were.
#[tokio::test(flavor = "multi_thread")]
async fn a_late_sample_past_retention_is_dropped() {
let (app, state) = data_plane(2);
write_seconds(&app, 0..64, 1..=200).await;
common::barrier(&app, 200_000).await;
let before = common::per_job(&answer(&app, 200).await);
write_seconds(&app, 5..6, 25..=25).await;
common::barrier(&app, 200_000).await;
let stats = state.engine.stats();
assert_eq!(
(stats.samples_merged_late, stats.samples_dropped_late),
(0, 1)
);
assert_eq!(common::per_job(&answer(&app, 200).await), before);
assert_eq!(before, expected(200));
}

/// With one series, three of four shards never get a sample; the windows
/// still close as the busy shard's samples pass them, without a barrier.
/// A shard with no samples does not hold the watermark, as the ASAPQuery
Expand Down Expand Up @@ -629,18 +642,162 @@ async fn a_wall_clock_step_closes_no_window_early() {
wait_for_answer_at_40s(&app, &state).await;
}

/// A sample for a window closed by wall-clock time is late: dropped and
/// counted, and the window keeps its answer.
/// A producer pauses past the idle close of `(30, 40]`, then resumes with
/// that window's other samples: they merge into the committed window, so
/// every answer, read before the pause or after, equals the answer of a
/// stream that never paused.
#[tokio::test(flavor = "multi_thread")]
async fn a_sample_after_a_wall_clock_close_is_late() {
async fn samples_after_a_pause_merge_into_the_window_closed_by_wall_clock() {
let clock = WallClock::manual(0);
let (app, state) = idle_data_plane(&clock);
write_through_40s(&app, &clock, 40_000).await;
clock.set(41_000);
wait_for_answer_at_40s(&app, &state).await;
let dropped = state.engine.stats().samples_dropped_late;
write_seconds(&app, 5..6, 35..=35).await;
clock.set(35_000);
write_seconds(&app, 0..64, 1..=35).await;
pass(&app).await;
assert_eq!(state.engine.stats().samples_dropped_late, dropped + 1);
assert_eq!(common::per_job(&answer(&app, 40).await), expected(40));
// The pause: the idle watermark reaches 35 + 15 − 0 − 1 = 49 s, which
// closes (30, 40] with the samples at 31..=35 s only.
clock.set(50_000);
let started = std::time::Instant::now();
while status_and_answer(&app, 40).await.0 != StatusCode::OK {
assert!(
started.elapsed().as_secs() < 10,
"{:?}",
state.engine.stats()
);
pass(&app).await;
}
assert!(state.engine.stats().windows_closed_by_wall_clock > 0);
assert_ne!(common::per_job(&answer(&app, 40).await), expected(40));
// The producer resumes where it stopped.
clock.set(60_000);
write_seconds(&app, 0..64, 36..=60).await;
common::barrier(&app, 60_000).await;
for time_s in [40, 50, 60] {
assert_eq!(
common::per_job(&answer(&app, time_s).await),
expected(time_s),
"at {time_s} s"
);
}
// Series 0..64 at 36..=40 s, into (30, 40].
let stats = state.engine.stats();
assert_eq!(
(stats.samples_merged_late, stats.samples_dropped_late),
(64 * 5, 0)
);
}

/// A counter series' samples: `increase` reads its window's samples in
/// time order, resets included.
const COUNTER_QUERY: &str = "sum by (job) (increase(c_total[30s]))";

/// The plan of `COUNTER_QUERY`, every 10 s, over one counter series.
fn counter_plan_json() -> String {
let workload = serde_json::from_value(json!({
"query_workload": {"language": "promql", "repeating_queries": [{
"query": COUNTER_QUERY,
"demand": {"fixed_interval_at": {"interval": 10000, "evaluation_phase": 0}},
"requirements": {},
"predictability": {"predictable": {"known_at": null}},
}]},
"data_workload": {"arrival": {"ingesting": {"rows_per_second": 1.0}},
"sources": {"c_total": {"series_count": 1, "sample_interval": 1000,
"metric_type": "counter", "column_signs": {"value": "non_negative"}}}},
}))
.unwrap();
serde_json::to_string(&plan_workload(&workload, &common::inputs(false)).unwrap().0).unwrap()
}

/// Writes `samples` (time ms, value) of the counter `c_total{job="a"}`.
async fn write_counter(app: &Router, samples: &[(i64, f64)]) {
let timeseries = vec![TimeSeries {
labels: [("__name__", "c_total"), ("job", "a")]
.into_iter()
.map(|(name, value)| Label {
name: name.into(),
value: value.into(),
})
.collect(),
samples: samples
.iter()
.map(|&(timestamp, value)| Sample { timestamp, value })
.collect(),
}];
common::remote_write(app, timeseries).await;
}

/// A late counter sample between two on-time ones (10 at 2 s, 12 at 8 s;
/// 3 at 5 s comes late, a reset) is not merged as a later sample would be
/// (an increase of 2): its window is computed again from the raw samples
/// kept, so `increase` is 3 + 9 = 12, as when every sample came on time.
#[tokio::test(flavor = "multi_thread")]
async fn a_late_counter_sample_recomputes_its_window_from_the_raw_samples() {
let data_plane = || {
let state = Arc::new(
DataPlane::with_options(
counter_plan_json(),
"http://127.0.0.1:1".into(),
common::no_forward_options(),
)
.unwrap(),
);
(router(state.clone()), state)
};
let (app, _) = data_plane();
write_counter(
&app,
&[(2_000, 10.0), (5_000, 3.0), (8_000, 12.0), (35_000, 20.0)],
)
.await;
common::barrier(&app, 40_000).await;
let (status, on_time) = status_and_answer_of(&app, COUNTER_QUERY, 30_000).await;
assert_eq!(status, StatusCode::OK, "{on_time}");

let (app, state) = data_plane();
write_counter(&app, &[(2_000, 10.0), (8_000, 12.0), (35_000, 20.0)]).await;
common::barrier(&app, 40_000).await;
let (_, before) = status_and_answer_of(&app, COUNTER_QUERY, 30_000).await;
assert_ne!(before, on_time);
write_counter(&app, &[(5_000, 3.0)]).await;
common::barrier(&app, 40_000).await;
let (status, after) = status_and_answer_of(&app, COUNTER_QUERY, 30_000).await;
assert_eq!(status, StatusCode::OK, "{after}");
assert_eq!(after, on_time, "{:?}", state.engine.stats());
assert_eq!(state.engine.stats().samples_dropped_late, 0);
}

/// A sample routed right after its shard answered the flush of the pass
/// that closes its window, before that pass publishes its routing: the
/// shard waits for the new routing, so the sample goes to the window's late
/// merge rather than only to the raw data the closed window no longer
/// reads. The coordinator here waits 1 s between the flush and the routing.
#[tokio::test(flavor = "multi_thread")]
async fn a_sample_routed_while_its_window_closes_is_not_lost() {
let options = EngineOptions {
ingest_threads: 1,
routing_delay_after_flush_ms: 1_000,
..common::no_forward_options()
};
let state = Arc::new(
DataPlane::with_options(plan_json(), "http://127.0.0.1:1".into(), options).unwrap(),
);
let app = router(state.clone());
// Every sample at 1..=30 s but series 5's at 25 s: (20, 30] is open.
write_seconds(&app, 0..64, 1..=24).await;
write_seconds(&app, 0..5, 25..=25).await;
write_seconds(&app, 6..64, 25..=25).await;
write_seconds(&app, 0..64, 26..=30).await;
common::barrier(&app, 20_000).await;
// The barrier at 30 s closes (20, 30]; series 5's sample at 25 s comes
// while its pass waits between the flush and the routing.
let closing = {
let app = app.clone();
tokio::spawn(async move { common::barrier(&app, 30_000).await })
};
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
write_seconds(&app, 5..6, 25..=25).await;
closing.await.unwrap();
common::barrier(&app, 30_000).await;
pass(&app).await;
assert_eq!(common::per_job(&answer(&app, 30).await), expected(30));
assert_eq!(state.engine.stats().samples_dropped_late, 0);
}
Loading