Repository navigation
Pin max_insert_threads in 02354_distributed_with_external_aggregation_memory_usage - #112478
Conversation
…_memory_usage The test began failing on its INSERT with Code: 241. Query memory limit exceeded: would use 4.66 GiB, maximum: 4.66 GiB (query: insert into t_2354_dist_with_external_aggr select number, toString(number) as s, toFixedString(s, 100) from numbers_mt(5e7);) so it never reached the external aggregation it exists to measure. max_insert_threads changed default from 1 to auto (the number of CPU cores) in ClickHouse#109006. This INSERT carried no SETTINGS clause, so it inherits the profile default and the write side's per-thread buffers now scale with the core count. The 5G budget in this test was measured with single-threaded insert ("5G is just the actual value taken from the logs + delta"), so the peak crosses the 4.66 GiB profile limit from tests/config/users.d/limits.yaml. max_insert_threads_min_free_memory_per_thread does not prevent it: the guard runs and reduced the request from 192 to 134 threads, but its budget is server free memory rather than the query's max_memory_usage, so insert parallelism is never tied to the limit the query is measured against. Pinning max_insert_threads = 1 restores the execution shape the budget was calibrated for. This is the same adaptation ClickHouse#109006 made in the same commit to the tests it identified, for example 03217_primary_index_memory_leak.sql, where max_insert_threads = 1 sits directly beside max_memory_usage = '100M'. This test needed the identical change and did not get it. Measured with the CI binary at this base commit, on a server carrying the CI limits profile: before the fix the test fails in 0.35-0.47 s, with the fix it passes in 10.52 s, and removing only the pin makes it fail again. Peak memory for the INSERT is 2.28 GiB at one thread (48.9% of the budget) versus 4.65 GiB at the default, so the pin leaves real headroom rather than sitting just under the cap. 50 runs with randomization enabled: 50 OK, 0 FAIL. Of the 62 stateless tests combining INSERT ... SELECT with max_memory_usage, 13 already pin max_insert_threads. Across the ClickHouse#109006 merge boundary this test is the only one that regressed, going from 0 failures to 12 across 12 distinct pull requests plus one master run, against 0 failures in the preceding 90 days.
Internal second-model review (click to expand)Two independent reviews of this change: a cold read of the resulting code, and a separate Raised as a verification ask: static inspection cannot show that the pin stays below the 5G profile
The "intermittent" premise is also weaker than the data. The CI runner's own same-settings rerun 💡 Passing-run count could not be reproduced (nit, own review) - Fixed. The count now states the 💡 Off-by-one in the pinned-test count (nit, own review) - Fixed. On the merge base 12 of the 62 💡 Trivial-insert-select push-down is not part of the mechanism (nit, own review) - No change 💡 Carrier set independently confirmed as exactly one test (nit, own review) - No action. Three |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260729-172438 |
|
cc @nickitat, could you review this? The test was failing on its INSERT with Code 241 before reaching the external aggregation it measures: #109006 changed the max_insert_threads default from 1 to the core count, and this INSERT had no SETTINGS clause, so the write side per-thread buffers pushed the peak past the 5G profile limit the test was calibrated against. |
|
Workflow [PR], commit [fd8865a] Summary: ✅ AI ReviewSummaryThis PR pins Final Verdict✅ No blocking issues found. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
02354_distributed_with_external_aggregation_memory_usagestarted failing on the INSERT, before itreaches the external aggregation it exists to measure:
Master failure:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=86d92d6b4119f54ab6f5fad650502dd3531ef4d8&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
Root cause: #109006 changed the
max_insert_threadsdefault from1to auto (the number of CPUcores). This INSERT had no
SETTINGSclause, so it inherits the profile default, and the writeside's per-thread buffers now scale with the core count. The 5G budget in this test was measured
with single-threaded insert ("5G is just the actual value taken from the logs + delta"), so the
peak crosses the 4.66 GiB profile limit from
tests/config/users.d/limits.yaml.The fix pins
max_insert_threads = 1on that INSERT, restoring the execution shape the budget wascalibrated for. This is the same adaptation #109006 applied in the same commit to the tests it
identified, for example
03217_primary_index_memory_leak.sql, wheremax_insert_threads = 1sitsdirectly beside
max_memory_usage = '100M'. This test needed the identical change and did not getit. No limit is raised, no data volume is reduced, and every assertion is unchanged.
I deliberately did not make
getMaxThreadsForAvailableMemoryquery-limit aware. It already runshere and reduced the request from 192 to 134 threads, but its budget is server free memory rather
than the query's
max_memory_usage, so it cannot help. Teaching itgetCurrentQueryHardLimit()would change read-side parallelism for every query that sets a memory limit, across its 19 call
sites, which is a separate discussion for #109006 rather than a test fix.
Validation
Reproduced with the CI-built binary at the base commit, on a server carrying
tests/config/users.d/limits.yaml(max_memory_usage = 5000000000asserted live,max_insert_threadsrenderingauto(192)).Code: 241at 4.66 GiBCode: 241The duration split matches CI, where the 12 observed failures took 500-1860 ms and passing runs
take 10-26 s: the INSERT dies almost immediately instead of running to completion.
Peak memory for the same INSERT, from
system.query_log:max_insert_threads1(this fix)So the pin leaves about 2.5 GiB of headroom rather than sitting just under the cap.
50 runs with randomization enabled: 50 OK, 0 FAIL.
--long-test-runs-ratio 1.0is needed for thecount to be real, since the
longtag otherwise scales--test-runsby 0.1.Scope: of the 62 stateless tests that combine
INSERT ... SELECTwithmax_memory_usage, 12already pinned
max_insert_threadsbefore this change. Querying theQuery memory limit exceededsignature across the #109006 merge boundary, this test is the only one that regressed, going from 0 failures to 12
across 12 distinct pull requests plus one master run, against 0 failures in the 90 days before
that merge (24181 passing runs). Every other candidate has no failures after the merge.
Version info
26.8.1.425(included in26.8and later)