Repository navigation
Conversation
…e thread (failing) RunContext::with_parallelism / parallel_tasks are stubs: the partition count is stored but unused and no task is counted, so the split tests' task assertions fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…over worker threads RunContext::with_parallelism(p) splits each wave of a per-group build's input rows (and a grouped merge of exact records) into p parts by a hash of the group key, folds the parts on rayon's global pool with the code one thread runs, and combines the parts' disjoint groups in key order (k-way merge on key bytes), gathering labels and states and sealing once. Each group sees exactly its rows in their input order, so answers and states are identical to p = 1. No group column, counters and HydraCMS stay on one thread; a merge meeting a keyed exact state falls back to the one-thread fold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
…wave, keep small inputs on one thread Review findings on the key-hash split: - CPU: each partition task measures its worker thread's CPU (runtime::thread_cpu_ns) and the run is charged it (RunContext::parallel_cpu_ns), so a caller measuring its own thread can count the work done for it on the pool. - Memory: a split merge folds wave by wave instead of holding (and charging) the whole input, and charges its parts' tables and records; waves are capped at 262144 rows and 64 MB of charged batch bytes (a dictionary shared by many window batches is charged per batch). - Inputs with fewer than 16384 rows in their first wave stay on one thread (RunContext::with_min_split_rows); each part gets >= 1/8 of that. - Dictionary text keys are hashed once per entry the batch uses (dense or map, as GroupTable resolves them), not once per dictionary entry. A merge meeting a keyed exact state folds the rest on one thread after the records merged so far: a group's records still fold in input order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SummaryAggper group) and grouped merge (SummaryMerge) run on one thread. The network eval's N1 q1 (a per-(src_ip, src_p24, src_p16) sum over 6.2 M rows) keeps 1 of 16 cores busy, while ClickHouse and TimescaleDB spread one query over every core.RunContext::with_parallelism(p)splits these operators' input rows intopparts by a hash of the group key. The parts are folded on rayon's worker threads and combined in the order one thread produces.p = 1for anyp: each group sees exactly its own rows in the same order, so compensated sums add in the same order and sketches see the same items. On a quiet 56-thread host, the network eval's N1 5-minute rounds (6.4 M rows, query-time per-host sums) take a median 1.42 s at 56 threads vs 9.99 s at 1 (7.1x) for 1.4x the CPU, with identical answers.Review guide
feat/sil-intent).crates/executor/src/operators/summary/partitioned.rs(split, per-part fold, key-order combine). Then the routing inoperators/summary/mod.rs(build_per_group_summary,merge_summary_streaming),StateColumnUpdater::gatherandgroups_are_independent, andGroupTable::part_keys/label_arrays_of.fold_build_rowsis the old per-chunk loop body moved into a function, so one thread and the parts share it.Behavior: before → after
The N1 intent (
SELECT src_p16, sum(value) ... GROUP BY src_p16 ORDER BY b DESC LIMIT 5, planned jointly) builds one query-time per-(src_ip, src_p24, src_p16) sum over the 5-minute window, then merges it by src_p16. Before this PR, both run on one thread. After it, withwith_parallelism(16), each 256 k-row wave is split into 16 parts by key hash and folded on 16 threads, and the parts' groups are combined by a k-way merge on key bytes. The top-5 answer and every state are identical to the one-thread run.Interfaces
crates/executor/src/runtime/context.rsimpl RunContext { + /// Split each grouped summary build and merge into `partitions` parts by group-key hash, on rayon's global pool; answers equal 1 (default). + pub fn with_parallelism(self, partitions: usize) -> Self; + /// Partition tasks this run's operators ran on worker threads (observability, tests). + pub fn parallel_tasks(&self) -> usize; + /// CPU time (ns) those tasks used on the worker threads; a caller measuring its own thread adds it to the run's CPU. + pub fn parallel_cpu_ns(&self) -> u64; + /// Inputs with fewer rows (first wave) stay on one thread; each part gets >= rows/8. Default DEFAULT_MIN_SPLIT_ROWS; 0 splits any input (tests). + pub fn with_min_split_rows(self, rows: usize) -> Self; } +/// The default min split rows (16384). +pub const DEFAULT_MIN_SPLIT_ROWS: usize; +/// CPU time the calling thread has used, in ns (CLOCK_THREAD_CPUTIME_ID; 0 off unix). +pub fn thread_cpu_ns() -> u64;Algorithm changes
Problem: one thread per query run; partitioning rows by range would change each group's addition order, which changes compensated-sum bits and sketch states.
Before: per 1024-row chunk:
GroupTable::group_ids→StateColumnUpdater::updateper row → seal → groups in key order.After (when
p > 1, there is at least one group column, and the family's groups are independent):takethe rows intoporder-preserving sub-batches.ifolds its sub-batch of every batch, in input order, with the same code one thread runs (fold_build_rows), into its own table and updater.groups_in_key_order), gather the labels (label_arrays_of) and the states (StateColumnUpdater::gather), and seal once.Grouped merges of exact records work the same way over the whole held input. If any state is a keyed exact object, the merge falls back to the streaming one-thread fold.
Correctness: a group's rows all land in one part and keep their input order, so its state is the one-thread state. The output order is the one-thread key order. Tested bit for bit at p ∈ {2, 3, 5, 8} for Sum/Count/Min/Max/DDSketch/HLL builds, exact merges, filters, NULLs, and float keys with zero signs and NaN payloads.
Stays on one thread: builds with no group column, counters (reorder buffer), HydraCMS (one grid shared by all groups), keyed and all-groups builds, and sketch (object) merges.
Review fixes (second round)
parallel_cpu_ns). The deployment adds this to the query phase measured on the caller's thread.Tests
cargo test -p asap-executor --test executor parallel_execution(7 tests: addssmall_inputs_stay_on_one_threadandsplit_runs_charge_worker_cpu_and_span_waves, a 300 k-row input over two waves). The existing executor suites are unchanged because the default parallelism is 1.Deferred
Filter/TimeRangeoperators ahead of the build.🤖 Generated with Claude Code
https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi