Repository navigation
Conversation
Follow-up to ClickHouse#107461. That PR set max_bytes_before_external_group_by and max_bytes_before_external_join to 300 MiB in the shared 04033_tpc_ds.lib and 04040_tpc_h.lib to cap peak memory. At that low threshold the heaviest queries spill GROUP BY / join state to disk eagerly, and external aggregation/join I/O is far slower under instrumented builds (ASAN/TSAN/coverage). 04033_tpc_ds_q10 on amd_tsan went from p90 ~35s / max ~144s before ClickHouse#107461 to p90 ~374s / max ~577s after, occasionally exceeding the 600s per-test wall-clock budget and failing as "Timeout! Processes left in process group" (e.g. on PR ClickHouse#107083). The same inflation hit q04/q69 and the TPC-H queries (no failures yet there). Measured locally on an ASAN build at SF1 (web disk, 10 GiB server cap): q10 single-query wall time was ~15.5s with the 300 MiB threshold (spilling) vs ~2.2s without spill. The peak memory of the heaviest queries is the same at 300 MiB and 2 GiB (q10 4.14 vs 4.29 GiB, q69 4.23 GiB, q23 2.61 GiB, q47 2.76 GiB) because the join spill plus the default max_bytes_ratio_before_external_join=0.5 already cap it; the GROUP BY spill at 300 MiB just adds I/O cost. All stay well under the 5 GiB sanitizer per-test memory limit, while running without spill exceeds it (Code 241), so the cap is still needed. Raising both absolute thresholds to 2 GiB keeps the peak-memory cap (and the 0.5 ratio remains the safety net under real memory pressure: the effective threshold is min(absolute, 0.5*available)) while letting the heavy operators run in memory at SF1, removing the eager-spill runtime cost. Query results are unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-5:20260619-103700 |
|
cc @rienath — could you review? Follow-up to #107461 (the disk-spill feature @ alexey-milovidov requested): the 300 MiB thresholds spill eagerly and made the heaviest TPC-DS/H queries ~7x slower under sanitizers, pushing 04033_tpc_ds_q10 on amd_tsan to a 600s wall-clock timeout. Raising both to 2 GiB keeps peak memory under the 5 GiB sanitizer budget (4.1-4.3 GiB, no-spill OOMs) while removing the eager-spill cost. Open to a different threshold if you prefer. |
|
Workflow [PR], commit [b83a047] Summary: ❌
AI ReviewSummary
Missing context / blind spots
Findings
Tests
Final Verdict
|
|
CI finished on
No PR-caused failures. (The Config Workflow "Pre Hooks" entry was a transient hook step; Mergeable Check passed.) |
where? Wait until it is fixed and merge master |
|
@rienath Tracked in issue #107941 (auto-filed for this exact hung-check / possible-deadlock signature) and diagnostic PR #105905 (open, logs live thread pools at GlobalThreadPool shutdown to pin the root cause). It is a chronic endemic trunk flake, not a single bug: 293 master + 332 PR hits across 254 distinct PRs in the last 30 days, and it reproduces on master with no PR. No fix ETA; #105905 is diagnostic-only and still in review. The failure is unrelated to this PR (test-only, two TPC So "wait until it is fixed" would block this CI-fix indefinitely. Want me to merge master and re-run anyway (it may flake again at ~0.5-1% on msan), or hold? |
By the way, @groeneai did you check how long it takes in these circumstances with the new limits? Please give me results of bottleneck queries with old limit, new limit and no limit at all. We need to decide what limit we want (if any) |
|
@rienath Bottleneck queries at old (300 MiB) / new (2 GiB) / no limit. ASAN, SF1, single query, warm cache, 10 GB cap (debug cannot reproduce: sanitizer allocation inflation is what crosses the threshold). wall / peak / on-disk spill: TPC-DS (S3 web disk)
TPC-H (local MergeTree)
2 GiB is the worst case for the join-heavy TPC-H queries: 6x-180x slower than both 300 MiB and no limit. Decoupling the two settings shows it is entirely So raising both to 2 GiB trades the q10 timeout for a worse TPC-H join timeout. The join threshold wants to be low (300 MiB, bounded spill) or 0 (plain hash), not 2 GiB. Options:
Which do you prefer? Caveat: single-query ASAN, not the 8-way-parallel cold-S3 amd_tsan job, so absolute seconds scale up there but the ordering holds. |
|
@groeneai Did some digging — I think this is tuning the wrong knob. A few things:
Suggested next step: don't raise both knobs. Keep group_by spill low — that's the coverage/memory win alexey asked for and it works (your q61 5.7→0.28). The problem is only max_bytes_before_external_join: 2 GiB is the thrash zone, so keep it low (clean spill, q08 ~17s) or leave joins in memory — just not 2 GiB. And q04 needs nothing here; #107441 already covers it. Happy to share the queries. |
|
@rienath Confirmed from CIDB, and it is worse than re-tuning: spill is the root cause of both remaining failures. q04: the only OOM was the server total tracker (~53.7 GiB) on the azure ASan shard with ~19 heavy queries co-scheduled, not a per-query cap. That was already fixed by the concurrency cut in #107441 (merged Jun 14). q04 then ran green on amd_tsan (3987 OK / 0 fail) and coverage (6019 OK / 0 fail) across Jun 11-18. Its only post-fix failures are 3 coverage timeouts on Jun 19/22, i.e. after spill (#107461) merged Jun 18. Spill did not help q04 and introduced its one remaining failure. q10: same story, and it undercuts this PR's premise. q10 amd_tsan was green Jun 11-18 (3954 OK, 0 timeouts). After spill merged Jun 18 it has 9 timeouts (Jun 19-23), 2 on master. So the 300 MiB spill is what introduced the q10 amd_tsan timeout this PR was trying to fix by raising to 2 GiB. Join threshold: agreed, and thanks for the correction (switch at threshold/2 ~1 GiB, re-partition churn near the cap). 2 GiB is the worst regime, matching the 6-180x TPC-H slowdowns I measured. Conclusion: with spill reverted, both q10 and q04 are already green (the Jun 11-18 state), so no threshold is needed at all. I would revert #107461 (drop the spill settings from both .lib files) and close this PR. One caveat: #107461 was alexey-milovidov's request to exercise the external-agg/external-join paths, so a straight revert drops that coverage. OK to revert outright, or keep the coverage by decoupling (low join 300 MiB, high group_by)? Since it reverts his change I would rather confirm the direction before opening the revert. |
|
I think we should revert. We can test spilling in other ways until it becomes faster. Green CI is priority number one. Let's revert @alexey-milovidov? |
|
@rienath Agreed, revert outright (no threshold, no decouple). Green CI first; we can re-add spill coverage separately once it is fast. That is just reverting the two .lib files (04033_tpc_ds, 04040_tpc_h) to no external spill and closing this PR. Ready to push the moment alexey-milovidov signs off, since it was his feature in #107461. |
| --max_bytes_before_external_group_by 314572800 | ||
| --max_bytes_before_external_join 314572800 | ||
| --max_bytes_before_external_group_by 2147483648 | ||
| --max_bytes_before_external_join 2147483648 |
There was a problem hiding this comment.
This keeps max_bytes_before_external_join in the measured worst regime for the TPC-H queries that source this shared lib. The PR's contract is to avoid sanitizer timeouts, but the later discussion already shows 2 GiB makes the join-heavy TPC-H cases much slower than both the old 300 MiB spill and no absolute join limit: q05 was measured at 74s vs 10.7s / 8.6s, q08 at 104-127s vs 17.9s / 10.8s, and q09 at 1374s vs 7.6s / 5.8s. That matches the implementation too: automatic spill conversion starts at half of max_bytes_before_external_join, so this threshold puts these joins into grace-hash repartitioning without cleanly spilling.
Please do not raise the TPC-H join threshold to 2 GiB; either revert the spill settings as agreed in the discussion, or keep max_bytes_before_external_join in a validated low-spill / disabled regime while tuning GROUP BY separately.
There was a problem hiding this comment.
Agreed, and this matches our 06-23 benchmark. The resolution settled in the thread is to revert the spill settings outright (drop external spill from both .lib files), not keep any join threshold. The revert is ready; it is only held on the feature owner's sign-off since the spill settings were their requested change.
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 406 line(s), 16 function(s) across 129 file(s) · Details Top files
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Follow-up to #107461, which set
max_bytes_before_external_group_byandmax_bytes_before_external_jointo 300 MiB in the shared04033_tpc_ds.liband04040_tpc_h.libto cap peak memory. At that low threshold the heaviest queries spill GROUP BY / join state to disk eagerly, and external aggregation/join I/O is far slower under instrumented builds (ASAN/TSAN/coverage).04033_tpc_ds_q10onamd_tsanwent from p90 ~35s / max ~144s before #107461 to p90 ~374s / max ~577s after, occasionally exceeding the 600s per-test wall-clock budget and failing asTimeout! Processes left in process group(CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107083&sha=be29f58460c89497f2d216444a4bd6dcc16411e6&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29 ). The same runtime inflation hit q04/q69 and the TPC-H queries (no failures there yet).Measured locally on an ASAN build at SF1 (web disk, 10 GiB server cap):
max_bytes_ratio_before_external_join = 0.5already cap it; the GROUP BY spill at 300 MiB just adds I/O.Raising both absolute thresholds to 2 GiB keeps the peak-memory cap (the effective threshold is
min(absolute, 0.5 * available), so the 0.5 ratio remains the safety net under real memory pressure) while letting the heavy operators run in memory at SF1, removing the eager-spill runtime cost. Query results are unchanged (04033_tpc_ds_q10output is byte-identical and matches the reference).