Repository navigation
Perf tests: stop background merges before the measured queries - #121937
Conversation
Each server creates and fills its own copy of the test tables, and merges that run during the measured queries change the part layout under them and compete for the CPU, differently on the two servers. `perf.py` now issues `SYSTEM STOP MERGES` on every server after the setup queries and `SYSTEM START MERGES` after the teardown. It also runs `SYSTEM START MERGES` at the start of every test, so a test that failed before its teardown does not leave merges stopped for the next one. Tests whose measured queries write (`INSERT`, `OPTIMIZE`, `ALTER`, `SYSTEM`) or run shell scripts keep merges running, and `keep_merges_running="1"` on `<test>` opts out explicitly. Of the 673 tests, 612 stop merges and 61 keep them running.
|
Workflow [PR], commit [1308b5c] Summary: ✅
AI ReviewSummaryThis PR adds a Findings
Final VerdictChanges requested: the stop/start machinery itself is fine, but the selected-query rerun path needs to participate in the read-only classification before this achieves the intended stabilization in CI. |
…, detect writes Addresses the review of #121937: - `SYSTEM STOP MERGES` only cancels the running merges, so wait until `system.merges` is empty before the first measured query. - All merge control is behind `perf.py --stop-merges`, which `compare.sh` passes in CI, so local and non-admin runs need no `SYSTEM MERGES` privilege. - A test keeps merges running when a measured query starts with a write keyword; everything else counts as read-only, so queries like `sparseGrams(...)` are covered. 614 tests stop merges, 59 keep them running.
| "CREATE", "DROP", "RENAME", "EXCHANGE", "ATTACH", "DETACH", "KILL", | ||
| "BACKUP", "RESTORE", | ||
| } | ||
| stop_merges = ( |
There was a problem hiding this comment.
stop_merges is decided from the whole XML file before --queries-to-run / --max-queries narrow the workload, so the confirmation rerun in compare.sh can miss the stabilization on current mixed tests. For example, native_arrow_ipc.xml has an INSERT benchmark followed by a read-only SELECT; rerunning only query 1 still leaves stop_merges false because query 0 is still present in test_queries. The same shape exists in hashed_dictionary_load_factor.xml and sparse_grams_index_build.xml. That means confirm_changes keeps background merges enabled for some read-only reruns, which defeats the determinism this PR is trying to add. Can we compute this from the selected query set after queries_to_run is finalized?
|
Two problems with 1. CI's measured runs don't get the flag. The TEST stage runs every test through 2. Wherever the flag is used, a read-only test whose drop query needs a mutation hangs in teardown. Four of the 614 tests that stop merges have such a drop query:
In CI today, this only affects confirmation reruns. A flagged query from these tests can't be confirmed: the rerun spends 300 s of the 1200 s confirmation budget, fails, and the test keeps its original verdict. A later rerun in the same job of another test that adds a text index on Reproduced with --- a/tests/performance/scripts/perf.py
+++ b/tests/performance/scripts/perf.py
@@ -1273,6 +1273,11 @@
reportStageEnd("run")
+# The drop queries may need merges: a mutating ALTER (e.g. DROP INDEX) waits for its mutation.
+if stop_merges:
+ for c in all_connections:
+ c.execute("SYSTEM START MERGES")
+
# Run drop queries
if not args.keep_created_tables and not args.use_existing_tables:
drop_queries = substitute_parameters(drop_query_templates)
@@ -1289,7 +1294,3 @@
print(f"drop\t{conn_index}\t{c.last_query.elapsed}\t{tsv_escape(q)}")
reportStageEnd("drop-2")
-
-if stop_merges:
- for c in all_connections:
- c.execute("SYSTEM START MERGES") |
The main runs of the performance job go through `CHServer.run_test`, which did not pass `--stop-merges`, so only the `confirm_changes` reruns stopped merges. And a drop query that creates a mutation, such as `ALTER TABLE ... DROP INDEX`, waited for it until `max_execution_time` because `SYSTEM START MERGES` ran only after the drop queries. ClickHouse#121937 (comment) Related: ClickHouse#121937
Since ClickHouse#122073 the measured perf.py runs stop merges on both servers right after the fill. The old fill writes 54 parts in about a second, so each server keeps whatever part set its background merges reached, and the two servers of one run measure different layouts (21 vs 38 parts on ClickHouse#122222, 24 vs 44 on ClickHouse#122154, 22 vs 44 on master 52a67f8). FINAL ... ORDER BY x DESC LIMIT n reads the first reverse ranges of every part (about 23K rows each), so its time grows with the part count, and the dashboard scores the side with more parts as a confirmed regression. The fill now merges the first insert, stops merges on the table and writes the second insert as exactly one part, so both servers read the same two parts whatever the merge timing, like final_read_in_order_limit.xml: - OPTIMIZE ... FINAL waits for the running merges before it selects, so the background merges of the first insert cannot leave it partial, and optimize_throw_if_noop = 1 makes a no-op OPTIMIZE fail with its reason instead of surfacing as a wrong part count. - min_insert_block_size_rows = 16777216 (2^24, above the 10M rows) with min_insert_block_size_bytes = 0: the INSERT squashes on one stream before it fans out to the sinks and never reaches the minimum, so the whole insert is flushed as one part, independent of max_insert_threads, max_block_size and how the numbers_mt threads interleave. - The throwIf over system.parts fails the job unless exactly 2 parts are active, because SYSTEM STOP MERGES on a missing table is a silent no-op. Validated on two servers of one master release build with perf.py --stop-merges, 5 runs per side of the change: before, 14 to 19 parts, different on the two servers in every run, right/left up to 1.18; after, 2 parts and identical SelectedRows on both servers, right/left within 3%. Related: ClickHouse#122073 Related: ClickHouse#121937 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each server of a performance comparison creates and fills its own copy of the test tables. Background merges that run while the queries are measured change the part layout under them and compete with them for the CPU, and that happens differently on the two servers.
With the new
--stop-mergesflag, whichcompare.shpasses in CI,perf.py:SYSTEM STOP MERGESon every server after the setup queries, then waits untilsystem.mergesis empty before the first measured query;SYSTEM START MERGESafter the teardown;SYSTEM START MERGESat the start of every test, so a test that failed before its teardown doesn't leave merges stopped for the next test on the same servers.Tests whose measured queries start with a write keyword (
INSERT,ALTER,OPTIMIZE,SYSTEM,DELETE, ...) or run shell scripts keep merges running.keep_merges_running="1"on<test>opts a test out explicitly. Of the 673 tests, 614 stop merges and 59 keep them running. Local and non-admin runs without the flag issue noSYSTEM ... MERGEScommand.This doesn't make the layout deterministic by itself: merges that run during the fill still depend on timing. Tests that fill from
numbers_mtorrand*()need their own fixes. Examples areand_compare_chain_derived,join_convert_outer_to_innerandread_in_reverse_order_final, whose two servers read different amounts of data in 28 to 72% of PR runs.Checked locally with two 26.8 servers and a throwaway test:
stop-mergesstage, and its part count stays constant on both servers for the whole run.INSERTkeeps merging (6 → 3 parts during the run).Related: #120927
Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/121937]
Version info
26.10.1.602-master(included in26.10and later)