Skip to content

Run queries #0-#2 of the aggregation_in_order performance test in one thread - #133450

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-aggregation-in-order-one-thread
Nov 22, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-aggregation-in-order-one-thread

Conversation

@groeneai

@groeneai groeneai commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100759
Related: #127697
Related: #133126
Related: #129366

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The aggregation_in_order performance test runs its GROUP BY CounterID and GROUP BY CounterID, EventDate queries with max_threads = 1 as new copies, so their timings no longer depend on the slowest of the streams the part is split into.

Description

Round 4 of #100759. On amd master 2026-11-12..11-21, the servers' medians of #0 (GROUP BY CounterID, 59 ms) and #2 (GROUP BY CounterID, EventDate, 65 ms) differ by more than 10% in 27% / 24% of 501 reports, 18% / 13% of runs are over the floors, 76 flags in 430 commits. arm: 4% of runs, 1% over the floors.

Both read one part in order: spreadMarkRangesAmongStreamsWithOrder splits its 12208 marks among the max_threads = 8 streams up front (no work stealing), so the query lasts as long as its slowest stream, and the amd job pins both servers to the same 8 CPUs. In 328 of the 501 reports neither side waits for a CPU, yet 97 differ by more than 10%: their wall-time ratio follows their CPU-time ratio with slope 3.2, tripling an ordinary 2-6% per-side CPU difference. The rest are run-queue waits: a background thread of either server, mostly the trace_log flush (my #133126), takes a stream's CPU.

No query number or text changes: #0 and the substitution query (#1/#2) are disabled (#129366) and appended with max_threads = 1 as #4-#6, as #127697 did for aggregation_in_order_if_null_map. #3 still measures the merge of 8 in-order streams. The copies take about 0.3-0.4 s per run.

Validation on two servers set up like the amd job (8 pinned CPUs, max_threads = 8, same 12208 marks): in 12 restart cycles the server difference of #0 / #2 exceeds the CPU difference by over 3 points in 9 / 4 (slope 1.27 / 3.24), of the copies in none (1.00 / 0.99). One busy thread on the 8 CPUs makes #0 / #2 wait 33 / 43 ms more and run 1.31x / 1.50x slower, the copies 1.00x / 0.99x, no wait. Same marks read, same result.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/133450]

Version info

  • Merged into: 26.12.1.150-master (included in 26.12 and later)

On amd, queries 0 and 2 differ by more than 10% between the two servers in
27% / 24% of 501 master reports (18% / 13% of runs over the report's
floors, 76 flags in 430 commits, 2026-11-12..11-21); arm 4% / 1%.

Both read one part in order: its 12208 marks are split among the
max_threads = 8 streams up front (no work stealing), so the query takes as
long as its slowest stream. The amd job pins both servers to the same 8
CPUs. Two inputs make one stream slower:

- In 328 of the 501 reports neither side waits for a CPU, yet 97 still
  differ by more than 10%. There the log ratio of the two servers' wall
  times follows the log ratio of their CPU times with slope 3.2
  (correlation 0.84), so an ordinary 2-6% per-side CPU difference becomes
  three times that. Single-threaded in-order queries keep it 1:1
  (aggregation_in_order_if_null_map, aggregation_in_order_partial_key:
  more than 10% in 0-1.6% of reports).
- The rest are run-queue waits: a background thread of either server,
  mostly the trace_log flush, takes one stream's CPU (slow samples wait
  43-48 ms for a CPU against 3 ms).

Disable query 0 and the substitution query (1, 2) and append them with
max_threads = 1 (4-6), as was done for aggregation_in_order_if_null_map.
Query 3 keeps measuring the merge of several in-order streams. No existing
query number or text changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings on the diff and the description, two runs). My own review: 2 nits on the description text, both resolved before publishing.

# Sev Finding Verdict Evidence / action
1 💡 "Over the floors" and the arm numbers need a re-runnable definition AGREE, fixed in the description floors as in the #100759 round-4 census (stat_threshold > 25%, or |diff| > 15% and above it); query_metrics_v2 recompute 16.9% / 12.8% for amd #0 / #2 over 11-12..11-21; arm wording made unambiguous
2 💡 The step in the inputs from 2026-10-24 (also seen in other tests) is not explained here DISAGREE (separate) the copies neither wait nor amplify: one busy thread gives them 1.00x / 0.99x with no extra wait, and 0 of 12 restart cycles show a server difference above their CPU difference

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261121-223900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, as a measured contrast on two local servers set up like the amd job (master release binary, both on the same 8 pinned CPUs, max_threads = 8, hits_100m_single with the same 12208 marks). 6 cycles, each with and without one busy thread on the same server processes: #0 / #2 run 1.31x / 1.50x slower and wait 33 / 43 ms more (21 of 24 pairs slower). 12 restart cycles: their server difference exceeds the CPU difference by more than 3 points in 9 / 4 cycles.
b Root cause explained? Both queries read one part in order; its marks are split among the 8 streams up front with no work stealing, so the query lasts as long as its slowest stream. A per-side CPU difference is multiplied about 3x (CI slope 3.2 / 3.05 in the reports without waits), and any runnable background thread on the 8 pinned CPUs, mostly the trace_log flush, delays one stream.
c Fix matches root cause? Yes. One stream has no slowest stream; no threshold, query text or engine path is changed.
d Test intent preserved / new tests added? The copies run the same aggregation over the same 100M rows and 12208 marks with identical results (md5 equal); #3 still measures the merge of 8 in-order streams. This is the performance test itself; no product code.
e Both directions demonstrated? Yes, old and new queries on the same servers and passes: with the busy thread the copies are 1.00x / 0.99x with no wait; in 12 restart cycles they exceed the CPU difference in 0 of 12 (slope 1.00 / 0.99 against 1.27 / 3.24).
f Fix is general across code paths? Every in-order performance test checked on CI: aggregation_in_order_if_null_map and _partial_key already run in one thread, aggregation_in_order_2 is time-sliced (30 threads), distinct_in_order and #3 are not exposed. The waiting competitor is handled harness-side by #133126.
g Fix generalizes across inputs (params/datatypes/wrappers)? Both substitution tables keep the same query (#5, #6); one thread behaves the same on amd and arm. Types and wrappers: N/A, no product code.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only; max_threads is long-standing; #0-#3 keep their numbers and text (disabled, not edited), so their history stays readable.
i Invariants and contracts preserved? Query numbering is frozen: #0-#3 byte-identical, --queries-to-run 0/1/2 refused as disabled, #4-#6 appended; every sample reads the same rows, marks and part.

Session id: cron:clickhouse-impl-slot-5:20261121-222300

@clickhouse-gh

clickhouse-gh Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cc94961]

Summary: ✅


AI Review

Summary

The PR preserves the original aggregation_in_order query IDs, disables three noisy benchmarks, and appends max_threads = 1 replacements while retaining parallel aggregation coverage. No actionable findings. Parser-only validation passed; the timing evidence comes from the PR's documented before/after measurements, which were not independently rerun.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). can be tested Allows running workflows for external contributors labels Nov 21, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 22, 2026
Merged via the queue into ClickHouse:master with commit 87867a5 Nov 22, 2026
577 of 579 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants