Repository navigation
Bound a performance comparison profile run by the profiling budget it was given - #117447
Conversation
… was given Performance Comparison shards go red with "N errors" although no query regressed: about 15 reds over 13 unrelated pull requests in three days, across 7 shards and both arches. A red on an unrelated pull request is a check hiding the regressions it exists to report. The failure is in the profile run that follows a query's measured runs, whose only product is flame-graph stacks, so it cannot regress anything. perf.py declares a per-query profiling budget (--profile-seconds, 10 in CI, ci/jobs/scripts/perf/compare.sh) but tests it only between runs, and the settings dict for those runs sets no max_execution_time, under a comment asserting that dedicated profile runs are not timed. That premise is the defect: the runs are not measured, but they are budgeted. Sampling one allocation in ten (memory_profiler_sample_probability, plus jemalloc_enable_profiler) multiplies an allocation-bound query by one to two orders of magnitude, so the only bound left is the server profile's 300 s max_execution_time, and reaching it raises TIMEOUT_EXCEEDED out of the script. One group_by_dynamic_keys query spent 417 s of profile time against a declared 10 s budget and ended the run; the measured runs of that same query were healthy and 5.6% faster on the tested arm. Enforce the declared budget on each profile run, and treat reaching it as the end of profiling for that query instead of an error. The catch is narrowed to TIMEOUT_EXCEEDED, so every other failure still aborts as before. The conn loop is deliberately not broken out of, so both servers truncate at the same bound; both still emit a profile row, which is what joins their trace_log samples into the report. Those samples are real (a truncated run left 2.77M MemorySample entries under its query_id) and are dropped today only because the row was never printed, which is why the shard's differential flame graphs are degenerate 579-byte stubs. Emitting profile-total again also lets compare.sh debit the global profile budget for time that is actually spent. Measured on a local two-server rig, one binary, arms made unequal so the profile block is actually entered: the profile run of that query costs 20x its measured time (5.45 s -> 109.18 s), matching the 22x observed in CI on the master arm, so the amplification is not caused by any pull request. Before, the run exits non-zero with Code 159 at the same frame as the CI artifact and loses two of three queries; after, it exits clean, reports all three, and truncates at the bound. Removing either half of the change alone still fails: without the bound the runs stretch past the server cap (profile-total 32.3 s -> 70.06 s), and without the catch the check stays red, only sooner. Across five other fixtures nothing is truncated, matching the failing job's own distribution of 749 profile runs with p99 = 1.18 s and exactly one run over 10 s. Truncated runs overshoot the bound by 58-65% rather than a few percent, because max_execution_time is checked between processing steps and one step is expensive under allocation sampling; the same granularity gave CI a 9.8% overshoot at 300 s. The worst case is still bounded per query instead of 2 x 300 s. Co-Authored-By: Claude Opus 5 <[email protected]>
The sentence added by the previous commit reads as if `--profile-seconds` bounded a whole profile run, but it bounds each statement: `execute_query_group` issues one `connection.execute` per statement with the same settings dict. A query item made of several statements can therefore take a multiple of the budget, as TPC-DS Q14 in `tests/performance/tpcds.xml` would, its `query_14.sql` splitting into two statements. This is the granularity `--max-query-seconds` and `--prewarm-max-query-seconds` already have, so only the wording changes. Co-Authored-By: Claude Opus 5 <[email protected]>
The profiling budget (`--profile-seconds`) reaches the server as `max_execution_time` on every `connection.execute`, and `execute_query_group` issues one such call per statement, so the bound applies to each statement and a query item made of several statements can take a multiple of it. The comment above the setting still promised the budget for the whole query, contradicting the README sentence added in the previous commit. A reviewer raised this twice, once against the README and once against the comment, so both now carry the same wording. The literals in the two other comments this branch adds are backticked to follow the repository style rule.
Internal second-model review: adjudication log (click to expand)Pre-publication review over three rounds by an independent model (engine: codex; 4 findings in
| 11 | 💡 | The description said allocation sampling costs such a query "two orders of magnitude", after the README sentence had been corrected to "orders of magnitude slower" | AGREE, fixed | The measured arms are 22.2x (completed) and 88.1x or more (killed at the server cap, so a lower bound only), i.e. one to two orders, and the upper arm is not a number one may round. The description now carries the same phrase as the README | The breadth claim in the description was re-measured from scratch in each round rather than carried Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260901-030900 |
|
Workflow [PR], commit [5d6b78a] Summary: ✅
AI ReviewSummaryThis PR bounds performance-comparison profile runs with Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictChanges requested. |
Pre-PR validation gate (a-i)
Also measured, because printing Mutation controls, one per half of the fix, both reddening: dropping the bound but keeping the catch leaves RC 0 while the runs stretch to 32.8 s and 37.2 s and One honest deviation from expectation: truncated runs overshoot the bound by 58-65% (15.8-16.5 s against 10 s), not the ~15% predicted. It is server-side, not client overhead ( |
|
cc @leshikus, could you review this? The performance comparison profile runs declare a 10 s budget ( |
| }, | ||
| ) | ||
| except clickhouse_driver.errors.ServerException as e: | ||
| if e.code != TIMEOUT_EXCEEDED: |
There was a problem hiding this comment.
This handles TIMEOUT_EXCEEDED as non-fatal for every profiled SQL item, not just read-only ones. The suite already profiles stateful benchmarks such as tests/performance/merge_tree_insert.xml (later INSERTs into the same table depend on the table state created by earlier ones) and tests/performance/hashed_dictionary_load_factor.xml (SYSTEM RELOAD DICTIONARY before later dictHas reads). If one of those profile runs times out here, the harness keeps going with whatever rows, parts, or reload state each side managed to produce before the timeout. Because profiling only starts after a measurable left/right difference, the shared --profile-seconds cap can leave different partial state on the two servers, so the later queries in the same file stop being comparable. I think this path needs a read-only guard (you already have first_keyword), or profiling should be skipped for mutating/stateful query groups instead of continuing after a partial run.
There was a problem hiding this comment.
Checked the two fixtures you name and then the whole suite. The mechanism is real, but neither cited fixture carries it, so I am not adding the guard.
merge_tree_insert.xml is not a carrier. All 9 timed <query> items (27 after substitution) are INSERTs and none reads the tables back, so accumulated row count is never an input to a measurement in that file.
hashed_dictionary_load_factor.xml does have the read-back shape, and SYSTEM RELOAD DICTIONARY does honour max_execution_time (Code: 159 ... maximum: 10.000 ms). But the reload is atomic. Measured on a 3,000,000 element HASHED dictionary immediately after the cap cut a reload: system.dictionaries gives status = LOADED, element_count = 3000000, empty last_exception, and dictHas still answers 1. A truncated reload leaves the previously loaded dictionary rather than a partial one, and the source tables are written only by <fill_query>, so the content a later dictHas sees is invariant either way.
Suite-wide, of 588 fixtures 48 have a mutating timed query, and exactly 2 of those also read the mutated object in a later timed query: hashed_dictionary_load_factor.xml and hashed_dictionary_sharded.xml, both the reload plus dictHas shape above. Reachability is separately out of range: allocation sampling amplifies an INSERT by x1.31 and this reload by x1.20 (0.285 s to 0.341 s, median of 3, settings confirmed in system.query_log), against x22 for the allocation bound aggregation that motivated this PR. Reaching a 10 s budget needs a base runtime above 7.6 s, and --max-query-seconds already caps a measured run at 15 s.
I did reproduce the divergence, with a fixture written for it (timed parallel INSERT, then a timed SELECT over the same table): the truncated arm ends at 174,455,389 rows against 180,000,000, while the same run on unpatched perf.py ends symmetric at 180,000,000. So it is a real behaviour change, with no carrier in the current suite.
On the remedy, first_keyword is not a lever here: it runs only on file= items (perf.py:503-509), so inline items would need a new statement classifier. Re-raising for non read-only groups restores the Code: 159 abort this PR removes, across those same 48 files, and skipping profiling for them instead drops flame graphs master produces today for exactly the queries that regressed.
ff6e119
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required (CI only).
Description
Performance Comparisonshards go red although no query regressed: in the three days to2026-09-01, 17 reds over 7 shards and both architectures, spanning 10 unrelated pull requests,
this one, and master, every one reporting
10 errors(that plural is a separatemiscount, #116491). The check hides the regressions it exists to report.
The failure is in the profile run after a query's measured runs, whose only product is
flame-graph stacks.
perf.pydeclares a per-query profiling budget (--profile-seconds, 10 in CI)but checks it only between runs, and its profile settings set no
max_execution_time. Profileruns are not measured, but they are budgeted: allocation sampling makes such a query orders
of magnitude slower, so the only bound left is the server's 300 s cap, and reaching it raises
TIMEOUT_EXCEEDEDout of the script. Onegroup_by_dynamic_keysquery spent 417 s against thatbudget.
This enforces the budget per run and treats reaching it as the end of profiling, not an error. The
catch is narrowed to that error code, so every other failure still aborts. Both servers
truncate at the same bound and still report a
profilerow, which joins theirtrace_logsamplesinto the report; today those samples are dropped and the differential flame graph is a stub.
On a two-server rig that profile run costs 20x its measured time, matching CI's 22x on the master
arm. Before, it exits with
Code: 159; after, clean, reporting every query. Removing either halfalone still fails. Nothing is truncated across five other fixtures; the job's 749 runs have
p99 = 1.18 s and one over 10 s.
Two other conditions share this signature, out of scope:
release_baseshards failing in thesetup thread pool, and the
default.checksrow collapse since 2026-08-30 (observability only).Related: #116057 (no open issue).
Failing report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116057&sha=f44965677e97c8f207eef1685f9c42484dc65c75&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F6%29
Workflow [PR]
Sync PR [sync-upstream/pr/117447]