Skip to content

versions: wait for background merges to settle before benchmarking - #1622

Merged
alexey-milovidov merged 1 commit into
mainfrom
versions-wait-for-merges-before-bench
Aug 27, 2026
Merged

alexey-milovidov merged 1 commit into
mainfrom
versions-wait-for-merges-before-bench

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

The 2026-08-26 master (26.9.1.170) run of the versions benchmark showed strange, massive degradations on ssb (hot runs up to 130x slower: Q1 0.064s → 8.4s, Q7 1.5s → 32s), visible at https://benchmark.clickhouse.com/versions/#version=-&dataset=+sb&metric=hot&queries=-

Investigation showed these are not per-query engine regressions but an artifact of when the queries run relative to deferred background merge work:

  • Since ClickHouse 26.8, a plain INSERT runs with max_insert_threads = all cores (Support max_insert_threads for plain INSERTs ClickHouse#109000). The bulk Native load saturates the machine, so background merges barely progress during the load window.
  • The load finishes ~2x faster (ssb load: 737s vs 1569s on 26.7.1.1315 — 737s is exactly the 87 GB / 125 MB/s gp3 throughput floor), and the deferred merge work (~1.7x write amplification) lands in the query phase, competing with the queries for CPU, disk bandwidth and page cache on the c7a.4xlarge (16 vCPU, 32 GB).
  • The master results show the exact churn timeline: mgbench (benchmarked first) is mildly elevated (hot +12-50%, colds up to 3x), ssb (second, the largest single-INSERT dataset) degrades catastrophically with tapering successive tries (Q7: 40/45/39/35/32s) and recovers from Q8 on, and hits (third) is consistently faster on master (0.6-0.9x) — the genuine engine improvements, visible once the merge storm has ended.
  • Local A/B (26.9.1.187 vs 26.7.1.1315, same SF10 data, same DDL, settled tables) confirms no per-query regression: master is equal or faster on all 13 ssb queries, but accumulates ~3.6x more post-load merge wall time under an unconstrained load (MergeTotalMilliseconds 8417s vs 2321s for the same inserted data).

The fix: after loading, wait for the server-wide system.merges to drain (bounded by MERGE_SETTLE_TIMEOUT, default 1 h; requires a few consecutive empty reads; skips gracefully on prehistoric builds without system.merges) before starting the query phase. Every version is then measured against the same, settled table state — the state the old single-threaded loads reached implicitly within the load window. This also stabilizes the reported data_size (measured on settled parts, not mid-merge).

The wait mostly displaces time the merge storm would otherwise steal from the query phase, so the total run duration stays within the existing 5 h VM budget.

🤖 Generated with Claude Code

Since ClickHouse 26.8, a plain INSERT runs with max_insert_threads = all
cores (ClickHouse/ClickHouse#109000). The bulk
Native load saturates the machine, so background merges barely progress
during the load: the load itself finishes ~2x faster (ssb: 737s vs 1569s
on 26.7.1.1315 -- exactly the 87 GB / 125 MB/s gp3 throughput floor),
and the deferred merge work (~1.7x write amplification) lands in the
query phase, where it competes with the queries for CPU, disk bandwidth
and page cache on the c7a.4xlarge (16 vCPU, 32 GB).

The 2026-08-26 master (26.9.1.170) results show the resulting timeline:
mgbench (benchmarked first) is mildly elevated, ssb (second, and the
largest single-INSERT dataset) degrades catastrophically with the
telltale tapering within and across queries (Q1 hot 0.064s -> 8.4s, Q7
1.5s -> 32s with successive tries 40/45/39/35/32s, while Q8-Q13 are
normal), and hits (third) is consistently *faster* on master -- the
genuine engine speedups, visible once the merge storm has ended:
https://benchmark.clickhouse.com/versions/#version=-&dataset=+sb&metric=hot&queries=-

Wait for the server-wide system.merges to drain (up to
MERGE_SETTLE_TIMEOUT, default 1 h) before the query phase, so every
version is measured against the same, settled table state -- the state
the old single-threaded loads reached implicitly within the load window.
This also stabilizes the reported data_size (measured on settled parts).

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov
alexey-milovidov merged commit 344fbd8 into main Aug 27, 2026
3 checks passed
@alexey-milovidov
alexey-milovidov deleted the versions-wait-for-merges-before-bench branch August 27, 2026 02:21
alexey-milovidov added a commit that referenced this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant