Skip to content

Fix errors during building report (due to lack of space for temporary data) - #109397

Merged
azat merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-report-disable-tmp-spill
Jul 9, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-report-disable-tmp-spill

Conversation

@groeneai

@groeneai groeneai commented Jul 4, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Related: #108804

The report build tries to use external aggregation and the disk does not have enough space (Code: 243), so limit memory and disable external aggregation. With spilling off a single job can peak ~30G, so also bound the parallel report jobs by host RAM to avoid Code: 241, and print report/errors.log to the job log.

CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109299&sha=34a2cd5d2faf6037651d0a9f6310ba967755e1a8&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%204%2F6%29

Version info

  • Merged into: 26.7.1.715 (included in 26.7 and later)

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @azat for review: this disables temp-disk spilling on the report-build clickhouse-local (follow-up to #108804). The heaviest eqmed.sql randomization queries were tripping the 0.5 * host RAM external-groupby threshold and reserving ~28 GiB on a report/tmp disk with only ~26 GiB free, so the check went red with Code 243 while every query row passed. These aggregations need well under 1 GiB tracked memory, so keeping them in RAM (with a per-query max_memory_usage cap) is the fix.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9bd7cda]

Summary: ✅


AI Review

Summary

This PR fixes the report-building clickhouse-local path by moving the spill-disabling settings into the normal query-setting position, mirroring them in performance_tests.py, capping the GNU parallel fan-out for the eqmed.sql post-processing step, and printing report/errors.log into the job log. I did not find a remaining correctness issue in the changed code itself, but the current PR head still lacks a completed Performance Comparison run, so the final /15 concurrency adjustment has not been revalidated on the CI path it is meant to fix.

Missing context / blind spots
  • ⚠️ The current head 9bd7cda9 does not yet have a completed Performance Comparison check in GitHub, so I could not confirm on live CI that the final host_ram/15 setting still avoids both NOT_ENOUGH_SPACE and MEMORY_LIMIT_EXCEEDED.
Tests
  • ⚠️ Please rerun at least one affected Performance Comparison shard on this exact head, ideally the arm shard that originally hit the report-build failure, to prove the final /15 job cap still keeps the report stage green after the last change.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: provide a completed Performance Comparison run for the current head 9bd7cda9 on an affected shard.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 4, 2026
Comment thread ci/jobs/scripts/perf/compare.sh Resolved
@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from 5638975 to 06c525a Compare July 4, 2026 17:27
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jul 4, 2026
@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

Confirmed, and fixed in 06c525a. The distinction is exactly right: clickhouse-local sends everything after -- to the application config (ClientApplicationBaseParser.cpp:52-54 skips these during option parsing; ClientApplicationBase.cpp:238 routes them via argsToConfig into config()). LocalServer::initialize reads server settings from config() (programs/local/LocalServer.cpp:358), so --memory_worker_use_cgroup=0 (a ServerSettings entry, src/Core/ServerSettings.cpp:1252) is honored there. But max_bytes_before_external_* / max_memory_usage are query settings (src/Core/Settings.cpp), applied from the command line into cmd_settings (ClientBase.cpp:3886) only for options parsed before -- — so after -- they were silently dropped and the Code 243 external-spill path stayed live.

Verified empirically (26.7.1 debug local):

# after --  (old form): ignored
$ clickhouse-local --query "SELECT value,changed FROM system.settings WHERE name='max_bytes_ratio_before_external_group_by'" -- --max_bytes_ratio_before_external_group_by=0
0.5   0        <- changed=0, still default 0.5 => spill threshold ~0.5*hostRAM

# before -- (fix): applied
$ clickhouse-local --max_bytes_ratio_before_external_group_by=0 --query "SELECT value,changed FROM system.settings WHERE name='max_bytes_ratio_before_external_group_by'"
0     1        <- changed=1, external aggregation off => never reserves temp disk

Fix: split the report-build settings into query settings (passed before --) and server settings (kept after --). In compare.sh the query settings now go in CHPC_REPORT_LOCAL_QUERY_SETTINGS placed before -- at all 7 invocation sites (the eqmed.sql parallel step + the analyze/report/metrics heredoc queries); CHPC_REPORT_LOCAL_SERVER_SETTINGS keeps only --memory_worker_use_cgroup=0 after --. performance_tests.py mirrors this with REPORT_LOCAL_QUERY_SETTINGS (before) and REPORT_LOCAL_SERVER_SETTINGS (after), spread in that order into both clickhouse-local calls. Confirmed the query settings now report changed=1 and a group-by that would spill under a low threshold stays in RAM with the thresholds pinned to 0.

Comment thread ci/jobs/performance_tests.py Resolved
@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from 06c525a to 066f644 Compare July 4, 2026 19:33
@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

@azat done. Trimmed the code comments in both ci/jobs/performance_tests.py and ci/jobs/scripts/perf/compare.sh to essentials (dropped the "how -- is parsed" explanation; the mechanism now lives in the commit message). Rebased on master, squashed into one commit, and trimmed the commit message and PR description. New head 066f644b.

Comment thread ci/jobs/performance_tests.py Resolved
Comment thread ci/jobs/performance_tests.py Resolved
@azat

azat commented Jul 4, 2026

Copy link
Copy Markdown
Member

@groeneai description is still contains lots of words I think, just tell that "it tries to use external aggregation and the disk does not have enough space, let's instead limit memory and disable external aggregatoin"

@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from 066f644 to 78cbf6b Compare July 4, 2026 20:06
@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

Done in 78cbf6b. Description cut to that one sentence; max_memory_usage set to 16Gi in both files.

@azat
azat enabled auto-merge July 4, 2026 20:11
@azat
azat disabled auto-merge July 4, 2026 20:11
@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from 78cbf6b to 9011a6e Compare July 4, 2026 22:43
@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

Updated (head 9011a6e): dropped the --max_memory_usage=16Gi cap; kept only the four external-group_by/sort disables.

The previous head's cap was wrong. The heaviest eqmed.sql queries genuinely allocate ~28 GiB of tracked memory (input cross-joined with numbers(1,10000) + medianExactForEach), so the 16 GiB cap just converted the Code: 243 (temp-disk reservation) into Code: 241 (query memory limit) at exactly 16 GiB on the same 5/6 arm batches. getCurrentQueryMemoryUsage() reads the tracker's amount (not RSS), so this is real aggregation state, not RSS/cgroup inflation.

Since the report/tmp disk cannot hold a ~28 GiB spill anyway, the aggregations must stay in RAM (host has the headroom, and parallel --memsuspend already bounds concurrency). Disabling spill without a cap restores the original in-RAM behavior and removes both the 243 and the 241. Verified locally that with these settings the report group_by never creates a temp file (no reservation possible); the real ~28 GiB path only reproduces on the arm runner, so the arm_release Performance Comparison run on this PR is the confirmation.

@azat azat left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this does not help - https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109397&sha=78cbf6b43dd3e22b9b66f39a3155b6f8b5264b61&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%205%2F6%29

Code: 241. DB::Exception: Query memory limit exceeded: would use 16.06 GiB (attempt to allocate chunk of 64.00 MiB), maximum: 16.00 GiB: While executing MergeSortingTransform. (MEMORY_LIMIT_EXCEEDED)
Code: 241. DB::Exception: Query memory limit exceeded: would use 16.02 GiB (attempt to allocate chunk of 32.00 MiB), maximum: 16.00 GiB: While executing MergeSortingTransform. (MEMORY_LIMIT_EXCEEDED)
Code: 241. DB::Exception: Query memory limit exceeded: would use 16.01 GiB (attempt to allocate chunk of 12.00 MiB), maximum: 16.00 GiB: While executing JoiningTransform. (MEMORY_LIMIT_EXCEEDED)
Code: 241. DB::Exception: Query memory limit exceeded: would use 16.01 GiB (attempt to allocate chunk of 12.00 MiB), maximum: 16.00 GiB: While executing JoiningTransform. (MEMORY_LIMIT_EXCEEDED)
Code: 241. DB::Exception: Query memory limit exceeded: would use 16.01 GiB (attempt to allocate chunk of 12.00 MiB), maximum: 16.00 GiB: While executing JoiningTransform. (MEMORY_LIMIT_EXCEEDED)
Code: 241. DB::Exception: Query memory limit exceeded: would use 16.04 GiB (attempt to allocate chunk of 64.00 MiB), maximum: 16.00 GiB: While executing MergeSortingTransform. (MEMORY_LIMIT_EXCEEDED)
Code: 241. DB::Exception: Query memory limit exceeded: would use 16.05 GiB (attempt to allocate chunk of 64.00 MiB), maximum: 16.00 GiB: While executing MergeSortingTransform. (MEMORY_LIMIT_EXCEEDED)

Let's do one of two:

  • decrease amount of parallelism
  • use tmp folder with a bigger fs - this will not work, we don't have such

@azat

azat commented Jul 5, 2026

Copy link
Copy Markdown
Member

Also PR title should not tell "what I did" but "what I fixed", so "Perf comparison: keep report-build clickhouse-local in RAM to avoid Code 243" is bad, "Fix errors during building report (due to lack of space for temporary data)" better

@azat

azat commented Jul 5, 2026

Copy link
Copy Markdown
Member

Also for to simplify things for yourself, expose those errors to the log, so that you will not need to download big archive with all the data

@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from 9011a6e to e109885 Compare July 5, 2026 18:32
@groeneai groeneai changed the title Perf comparison: keep report-build clickhouse-local in RAM to avoid Code 243 Fix errors during building report (due to lack of space for temporary data) Jul 5, 2026
@groeneai

groeneai commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

Done in e109885:

  • Report parallel now caps -j to host-RAM/30G (m8g.4xlarge -> 2), so concurrent report queries no longer collectively hit Code 241. The 16Gi per-query cap was already dropped (single heavy jobs legitimately need >16G in RAM).
  • Title renamed as suggested.
  • report/errors.log is now printed to the job log when non-empty.

Squashed to one commit; only the two files changed.

Comment thread ci/jobs/scripts/perf/compare.sh Outdated
parallel -v --joblog analyze/parallel-log.txt --memsuspend 15G --null < analyze/commands.txt 2>> analyze/errors.log
#
# With external aggregation disabled, a single heavy job stays in RAM and can
# peak ~30G, so bound concurrency by host RAM to avoid Code 241.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# peak ~30G, so bound concurrency by host RAM to avoid Code 241.
# peak ~30G, so bound concurrency by host RAM to avoid Code 241.

Please, don't use magic numbers, not 241, but MEMORY_LIMIT_EXCEEDED

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also why do we need this, why "--memsuspend" does not helps?

@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from e109885 to 6913803 Compare July 9, 2026 07:38
@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Done in 6913803.

  1. Magic numbers: replaced Code 243/Code 241 with NOT_ENOUGH_SPACE/MEMORY_LIMIT_EXCEEDED in the comments (both compare.sh and performance_tests.py).

  2. Why the -j cap on top of --memsuspend: --memsuspend only suspends jobs that have not started yet, based on a free-memory watermark. It cannot reclaim RAM from jobs already running. With external aggregation disabled a single heavy report query stays fully in RAM (peaks ~30G), so once enough heavy jobs have already started concurrently they can collectively exceed host RAM before the watermark suspends any new ones, giving MEMORY_LIMIT_EXCEEDED. The -j cap bounds how many can be running at once (host_ram/30G), which --memsuspend alone does not guarantee.

@azat

azat commented Jul 9, 2026

Copy link
Copy Markdown
Member

--memsuspend only suspends jobs that have not started yet

This is 95% wrong (and even the comment above says this), please do not give far fetched results, it takes way more time to validate you, then fix on my own.

Comment thread ci/jobs/scripts/perf/compare.sh Outdated
#
# With external aggregation disabled, a single heavy job stays in RAM and can
# peak ~30G, so bound concurrency by host RAM to avoid MEMORY_LIMIT_EXCEEDED.
report_jobs=$(( $(awk '/MemTotal/ {print int($2/1024/1024)}' /proc/meminfo) / 30 ))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "/15" not "/30", after it it will suspend some jobs anyway, and it is already 4x reduction of parallelism (now it is 16, and will be 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we need also some reserve, but this will decrease parallelism, which we do not want, so this is OK

… data)

The report-building clickhouse-local tries to use external aggregation and the
disk does not have enough space (NOT_ENOUGH_SPACE), so limit memory and disable
external aggregation. Query settings must be passed before -- (settings after
-- are treated as server/config overrides and silently ignored). With external
aggregation off a single heavy job stays in RAM (~30G peak), so bound parallel
concurrency by host RAM (host_ram/15) to avoid MEMORY_LIMIT_EXCEEDED;
--memsuspend cannot reclaim RAM from already-running jobs. Also expose
report/errors.log to the job log for easier diagnosis.
@groeneai
groeneai force-pushed the groeneai/perf-report-disable-tmp-spill branch from 6913803 to 9bd7cda Compare July 9, 2026 11:21
@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Changed the divisor from host_ram/30 to host_ram/15, so on the 64 GiB host it is now -j4 (16 -> 4, a 4x reduction) instead of -j2. Pushed as 9bd7cda. performance_tests.py needs no mirror: its report-build clickhouse-local calls are serial single subprocess runs with no -j knob.

@azat
azat enabled auto-merge July 9, 2026 11:24
@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

You are right, I was wrong. `--memsuspend` does suspend already-running jobs: when free memory drops below 2*size it SIGTSTPs running jobs (down to a single running job below size), then resumes them as memory frees. It is not limited to not-yet-started jobs.

The explicit `-j` cap just puts a deterministic ceiling on concurrency; `--memsuspend` does the memory-pressure smoothing on top of that. Sorry for the noise and thanks for validating.

@azat
azat added this pull request to the merge queue Jul 9, 2026
Merged via the queue into ClickHouse:master with commit f5b6dcb Jul 9, 2026
175 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 9, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…rt-disable-tmp-spill

Fix errors during building report (due to lack of space for temporary data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants