Repository navigation
Fix low-thread slowdown from smaller Adaptive Aggregator staging chunks - #131003
Conversation
|
Workflow [PR], commit [ca1bf65] Summary: ✅
AI ReviewSummaryPR #131003 sizes adaptive aggregation staging chunks by the number of producer partitions and prefetches the next range during walks without hash-table-slot prefetching. No actionable findings at Missing context / blind spots
Final Verdict✅ Approve — no changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+96.34 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units9 translation units recompiled, 58 s compile time in total, 9 of them have a recent master baseline. |
7adf9a6
Related: #128495
Background
The adaptive aggregator (
enable_adaptive_aggregator, enabled by default) stages the rows that miss the frozen hash table of their thread as records, and merges them later, one partition at a time. Every thread keeps one buffer per partition: a chain of memory chunks that double in size from 2 KiB up to a cap. #128495 lowered the cap from 32 KiB to 8 KiB, and to 4 KiB from 17 threads on, because the unused end of the last chunk of every buffer adds up: at 64 threads there are 131,072 buffers.With few threads, the buffers are few, so a small cap saves little memory, but each buffer holds many records in many chunks. Q32 at 4 threads stages 100 million records of 15 bytes into 2,048 buffers, about 730 KB each, which take 92 chunks of up to 8 KiB, where chunks of up to 32 KiB take 26. The merge pays for every chunk: it follows the chunks of a partition from header to header, with a cache miss each, and the hardware prefetchers start a new stream at every chunk. A top-K query by
count()with other aggregates, such as Q32, also reads every partition twice: once to count its groups, and once to build the states of the best ones. That second read did not request the next chunk ahead, so it waited at the start of every chunk.So at 4 threads the 8 KiB cap made Q32 5% slower than chunks of up to 32 KiB, for 1% less peak memory (1,637 → 1,621 MiB). #128495 (comment) found Q32 5% slower on 4 vCPUs after that PR, and 32 KiB chunks gave its time back.
Changes
The cap now follows the number of buffers, so it is large where they are few, and every read of the staged records requests the next chunk ahead.
Stringkeys, and the reads into large tables.Results
ClickBench
hits(100M rows) on AWSc8a.16xlarge(64 cores, one thread per core),clickhouse-local,FORMAT Null, with each width pinned to as many cores. A cell is the median of three processes, each running the query 5 times and taking the average of runs 3 to 5. Peak memory is the peak of the query from--memory-usage.GROUP BY WatchID, ClientIP:count,sum,avg, top 10GROUP BY WatchID, toUInt64(ClientIP):count,sum,avg, top 10GROUP BY URL:count, top 10Q32 and its variant with a 16-byte key gain the most, because their merges read every partition twice. Q33 groups by a
Stringkey, whose reads already requested the next chunk, so only the larger chunks change it, at 4 and 8 threads. From 9 threads on, the chunks stay as on master. Against the code before #128495, Q32 at 4 threads was 3% slower and is now 2% faster. Every query returns the same rows as master.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The adaptive aggregator (
enable_adaptive_aggregator, enabled by default) is faster forGROUP BYwith many distinct keys at low thread counts: it stages records in larger chunks when few threads aggregate, and its merge requests every next chunk of records ahead. On ClickBench Q32 and Q33 and a variant of Q32 with 16-byte keys, the geometric mean speedup is 1.06x at 4 threads and 1.04x at 8 threads, up to 1.08x, with peak memory within 2%; from 16 threads on, speed and memory stay the same.Workflow [PR]
Sync PR [sync-upstream/pr/131003]
Version info
26.11.1.2113-master(included in26.11and later)