Skip to content

feat(data_plane): parallel query runs (--query-parallelism) and concurrent independent queries per round - #905

Draft
zzylol wants to merge 3 commits into
feat/raw-read-label-pushdownfrom
feat/parallel-rounds
Draft

zzylol wants to merge 3 commits into
feat/raw-read-label-pushdownfrom
feat/parallel-rounds

Conversation

@zzylol

@zzylol zzylol commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a query run uses one core: grouped builds and merges run on one thread, raw reads convert one ingest shard after another, and an intent round runs its queries one at a time even when they don't depend on each other. On a whole 56-thread server, the baselines (ClickHouse, TimescaleDB) spread a query over every core.
  • Change: --query-parallelism N (default: the cores) does three things. It sizes rayon's global pool. It makes each query run split its grouped builds and merges by group key into N parts (the planner executor's RunContext::with_parallelism). And it makes raw reads convert the ingest shards in parallel, keeping their order. Separately, the intent round loop now starts a query as soon as its upstreams finish, so independent queries run at once.
  • Effect: answers are identical for any N (the e2e test compares each value's bits at N = 1 vs 4). In a round where q1 takes 100 ms, q2 300 ms and q3 depends on q1, the round now takes 300 ms instead of 500 ms. Latency and CPU at 1/8/16 threads: see Measurements.

Review fixes (second round)

  • B1 CPU accounting. The partition tasks' worker CPU (executor RunContext::parallel_cpu_ns) and the parallel shard reads' worker CPU are charged to the query worker thread (metrics::add_offloaded_cpu_ns). Timer and PhaseStats::record include that charge, so asap_phase_cpu_seconds_total{phase="query"} counts the work wherever it ran. The worker share is also reported separately as asap_query_parallel_cpu_seconds_total. Tests: metrics::tests::worker_cpu_charged_to_the_thread_counts_in_its_phase, and the e2e test now asserts that query-phase CPU ≥ worker CPU > 0 at parallelism 4.
  • I1 / pool size. New --query-pool-threads sets the rayon pool size; --query-parallelism sets the parts per run. Both default to the cores. Ingest, precompute and persist threads share the same cores.
  • I2. A failed build_global is now logged as a warning, and the actual pool size is reported as the gauge asap_query_pool_threads.
  • I3. Restacked onto feat(data_plane): raw reads return only the series a Scan's label predicates select #902's head 129bcc8.
  • Memory. Fixed in the executor (ASAPPlanner#1563): split merges fold wave by wave with a byte cap, and small inputs stay on one thread.

Review guide

Behavior: before → after

data_plane --plan n1.json --intent ... --query-parallelism 16:

  • Before: N1 q1's shared per-host sum over 6.2 M rows ran on one query worker (0.67 of 16 cores busy).
  • After: the build is split into 16 key-hash parts on the query-part-* threads, and the shards' raw chunks are converted in parallel. q1, q2 and q3 return the same rows and bindings.

With N5 (18 independent queries per clock), each round's queries now run concurrently on the query workers.

Interfaces

data_plane/src/engine.rs, main.rs, query.rs, store.rs, metrics.rs

 pub struct EngineOptions {
+    /// Parts one query run splits each grouped build and merge into (by group key); also turns on parallel shard reads; default the cores; answers identical for any value.
+    pub query_parallelism: usize,
+    /// Threads of the query worker pool (rayon global pool); default the cores; ingest/precompute/persist share the cores.
+    pub query_pool_threads: usize,
+    /// For tests: split inputs this small (RunContext::with_min_split_rows); None = executor default.
+    pub query_min_split_rows: Option<usize>,
 }
 impl QueryEngine {
+    /// Runs split by group key into `parallelism` parts; partition tasks and their worker CPU (ns) counted.
+    pub fn with_parallelism(self, parallelism: usize, min_split_rows: Option<usize>, tasks: Arc<AtomicU64>, cpu_ns: Arc<AtomicU64>) -> Self;
 }
 impl RunStore {
+    /// Raw reads read the ingest shards on rayon's workers (same batches, same order).
+    pub fn with_parallel_shard_reads(self, parallel: bool) -> Self;
 }
 pub struct Metrics {
+    /// `asap_query_parallel_tasks_total`: partition tasks the query runs ran on worker threads.
+    pub query_parallel_tasks: Arc<AtomicU64>,
+    /// `asap_query_parallel_cpu_seconds_total`: worker-thread CPU of those tasks and of parallel shard reads (included in phase="query").
+    pub query_parallel_cpu_ns: Arc<AtomicU64>,
+    /// `asap_query_pool_threads`: the pool's actual size.
+    pub query_pool_threads: AtomicU64,
 }
+/// Charges worker-thread CPU spent for this thread's runs; Timer / PhaseStats::record include it.
+pub fn add_offloaded_cpu_ns(ns: u64);

CLI: --query-parallelism N, --query-pool-threads N.

Algorithm changes

Round loop:

  • Before: queries ran one at a time in topological order.
  • After: a query starts as soon as every upstream it reads has finished; the roots start at once (FuturesUnordered over ready queries). Statuses, bindings, timeouts, group latency (round start → last member end) and record order are unchanged.

Raw reads: shards are read in parallel and their batches concatenated in shard order, so the executor sees the same rows in the same order as a sequential read.

Tests

  • intent::tests::independent_queries_in_a_round_run_concurrently
  • intent::tests::a_dependent_waits_for_every_upstream
  • tests/intent_sil_modes.rs::parallel_query_runs_answer_like_sequential_runs: all three planning modes, N = 1 vs 4, bit-identical answers; tasks > 0 with 4 and 0 with 1.
  • The existing intent and SIL e2e tests pass.

Measurements

Quiet host: 2x E5-2683 v3, 56 threads, 251 GB; load ≤ 4 during the runs. Tool: par_bench (in process; rows fed unpaced, windows closed, then 3 rounds 10 s apart). Each run is pinned with taskset -c 0-(P-1) and QUERY_PARALLELISM=P, so the engine sees P cores (ingest shards = P/4). 3 reps per point (n = 9 rounds). Answers (every round, every value's bits) are identical across P = 1/8/28/56 and across reps.

Workloads:

  • N1: n1_5min full-intent plan, synthetic x1, 6.4 M rows; q2 and q3 build per-host sums at query time.
  • E6: drill_cnt x1, 660 s fed.

Label layout (this PR):

workload threads round ms median (min-max) per query ms median query CPU core-s per round median n
e6full 1 231.0 (204.0-235.3) q1 14.2, q2 216.8 0.23 9
e6full 8 135.7 (133.0-156.8) q1 10.8, q2 124.9 0.38 9
e6full 28 130.2 (126.4-138.0) q1 11.0, q2 119.2 0.46 9
e6full 56 143.8 (137.4-145.7) q1 12.3, q2 130.5 0.64 9
e6qat 1 234.4 (224.2-290.2) q1 15.6, q2 218.8 0.24 9
e6qat 8 175.2 (168.3-281.7) q1 11.5, q2 163.4 0.23 9
e6qat 28 146.8 (134.1-163.4) q1 11.5, q2 135.6 0.27 9
e6qat 56 155.4 (151.4-167.4) q1 13.1, q2 142.9 0.34 9
n1 1 9991.1 (9944.1-10384.0) q1 1.3, q2 6950.5, q3 3021.2 9.98 9
n1 8 6456.3 (6016.4-8207.5) q1 2.3, q2 4543.5, q3 1944.0 12.57 9
n1 28 2223.0 (2109.8-2797.8) q1 2.6, q2 1433.0, q3 780.5 12.40 9
n1 56 1416.6 (1348.2-1858.1) q1 3.8, q2 852.6, q3 516.3 13.83 9
answers n1: 12 files identical=True
answers e6full: 12 files identical=True
answers e6qat: 12 files identical=True
  • N1 rounds go from 9.99 s to 1.42 s at 56 threads (7.1x) for 1.4x the CPU.
  • At P = 8 the gain is only 1.5x, because taskset 0-7 leaves 2 ingest shards and raw reads convert per shard. With 8 shards (INGEST_THREADS=8) the median round is 2.04 s (4.9x).
  • E6 q2 is small (≤ 6 M rows, 100 groups): 1.6-1.8x at 28 threads.

With #904's series-key layout (local combo #904 + #905; packets keyed by src_p16, auth and flows by host):

workload threads round ms median (min-max) per query ms median query CPU core-s per round median n
e6full 1 233.8 (207.5-235.8) q1 14.3, q2 218.3 0.23 9
e6full 8 136.0 (133.8-137.5) q1 10.7, q2 124.6 0.37 9
e6full 28 131.2 (129.4-140.6) q1 11.4, q2 120.2 0.45 9
e6full 56 141.2 (140.5-150.2) q1 12.1, q2 129.3 0.62 9
e6qat 1 185.4 (177.6-236.9) q1 15.2, q2 167.9 0.19 9
e6qat 8 158.9 (154.3-218.4) q1 11.7, q2 146.2 0.17 9
e6qat 28 142.1 (135.3-167.0) q1 11.3, q2 130.3 0.18 9
e6qat 56 144.4 (136.9-153.8) q1 13.0, q2 130.7 0.19 9
n1 1 474.0 (452.9-757.1) q1 1.3, q2 219.4, q3 240.0 0.48 9
n1 8 455.3 (444.3-588.2) q1 1.8, q2 243.1, q3 207.9 0.46 9
n1 28 340.4 (329.0-373.1) q1 2.6, q2 168.0, q3 169.5 0.43 9
n1 56 349.7 (314.9-360.7) q1 4.1, q2 187.4, q3 157.6 0.44 9
answers n1: 12 files identical=True
answers e6full: 12 files identical=True
answers e6qat: 12 files identical=True
  • Answers equal the label layout's.
  • The layout removes most of N1's scan cost (9.99 s to 0.47 s at P = 1). Parallelism then adds 1.4x.

The CPU column in these tables is the bench's sum over all query* threads. Those runs used the binary from before the CPU-accounting fix. With the fix, phase="query" reports the same total.

Deferred

  • Chunk-level parallel conversion inside RawData::read. Shards only for now, to stay out of the series-key branch's way.
  • Splitting ingestion runs (they keep their series partitions).
  • An in-process bench (par_bench) lives with the eval tools, not in this repo.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi

@zzylol zzylol added enhancement New feature or request area: data plane Runtime ingestion, storage, and query-serving data paths area: query engine PromQL lowering, execution, result shaping, and fallback behavior labels Dec 4, 2026
zzylol and others added 2 commits December 4, 2026 02:16
…runs answer like one thread (failing)

EngineOptions::query_parallelism and the asap_query_parallel_tasks_total
counter are stubs (unused, never incremented).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…ies per round

- --query-parallelism N (EngineOptions::query_parallelism, default the
  cores) sizes rayon's global pool; each query run splits its grouped
  builds and merges by group key into N parts (executor
  RunContext::with_parallelism) and raw reads convert the ingest shards
  in parallel, keeping their order. Answers are identical for any N.
  asap_query_parallel_tasks_total counts the partition tasks.
- IntentLoop::run_round schedules by dataflow: a query starts as soon as
  every upstream it reads has finished; independent queries run at once
  on the query workers. Statuses, bindings, timeouts, group latency and
  record order are unchanged.
- Pins ASAPPlanner feat/parallel-query-exec (stacked on #1553).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
zzylol added a commit that referenced this pull request Dec 4, 2026
zzylol added a commit that referenced this pull request Dec 4, 2026
… query pool size

Review findings on parallel query runs:
- The partition tasks' worker CPU (executor RunContext::parallel_cpu_ns)
  and the parallel shard reads' worker CPU are charged to the query
  worker thread (metrics::add_offloaded_cpu_ns), which Timer and
  PhaseStats::record include: asap_phase_cpu_seconds_total{phase=query}
  counts the work wherever it ran; asap_query_parallel_cpu_seconds_total
  reports the worker share.
- --query-pool-threads sizes the worker pool apart from
  --query-parallelism (parts per run); a failed build_global is logged
  and asap_query_pool_threads reports the pool's size. Ingest, precompute
  and persist threads share the cores.
- query_min_split_rows (tests) lets small tables split.
- Pins ASAPPlanner feat/parallel-query-exec 74621ba2 (split merges by
  wave, small inputs on one thread, worker CPU per run).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
@zzylol
zzylol force-pushed the feat/parallel-rounds branch from ae4888c to 4467d93 Compare December 4, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths area: query engine PromQL lowering, execution, result shaping, and fallback behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant