Skip to content

Size integration test workers from the job cgroup limit instead of host RAM - #115785

Closed
leshikus wants to merge 5 commits into
ClickHouse:masterfrom
leshikus:ci/flaky-integration-mem-budget
Closed

leshikus wants to merge 5 commits into
ClickHouse:masterfrom
leshikus:ci/flaky-integration-mem-budget

Conversation

@leshikus

@leshikus leshikus commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #115277
Related: #107529

The flaky/targeted integration checks size their xdist pool as min(ncpu // MAX_CPUS_PER_WORKER, mem_gb // MAX_MEM_PER_WORKER_DIST_EACH), but mem_gb came from Utils.physical_memory. ci/defs/job_configs.py starts the job container with --memory=LIMITED_MEM (physical_memory() - 2 GiB), so sizing over-counted by exactly that headroom: the failing job logged mem_gb: 61 against an enforced 59 GiB and started three --dist=each workers.

Each worker then ran test_storage_hdfs/test.py plus test_storage_s3/test.py in its own Docker cluster. host_metrics.jsonl shows memory climbing monotonically across the 15-minute test_storage_s3 module - 57% at its start, 99.5% at 04:40:52, iowait already 20% from 04:33. From 04:41:09 the runner holds 100% CPU and 99.5% memory for twenty minutes with no test progress, the kernel reaps the servers and then the workers ([gw0] node down: Not properly terminated), and the job ends on Timeout exceeded [3244], exit code 137. No single test is responsible: the two slowest-looking ones insert 20 rows and write 10 objects.

Utils.memory_limit resolves the job's cgroup through /proc/self/cgroup and reads memory.max or memory.limit_in_bytes, falling back to physical memory when unlimited. Resolving the path matters - CI passes --cgroupns=host, so /sys/fs/cgroup/memory.max is the host root and reads max. The check now gets min(16 // 5, 59 // 20) = 2 workers, so MAX_MEM_PER_WORKER_DIST_EACH stays at 20; loadfile runs keep 3.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115277&sha=8a253f5b442c2503d40d0606fc79197de555a851&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29

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):


Workflow [PR]
Sync PR [sync-upstream/pr/115785]

Flaky and targeted integration checks size the pool as
`min(ncpu // MAX_CPUS_PER_WORKER, mem_gb // MAX_MEM_PER_WORKER_DIST_EACH)`.
An `amd-medium` runner logs `ncpu: 16` and `mem_gb: 61`, so the 20 GB budget
still yields three workers. Each `--dist=each` worker runs the whole changed
module set in its own Docker cluster, and three of them - a Hadoop JVM,
`minio`, the S3 proxies and several ASan servers each - exhaust the 62.7 GB
container cgroup. The kernel OOM killer takes `pytest` and then `dockerd`,
the run reports `node down: Not properly terminated` and overruns its
session timeout.

24 GB per worker gives two workers here and three from 72 GB up. Sequential
repeats stay at `max(3, workers)`, so the flakiness signal is unchanged.

ClickHouse#107529 introduced the 20 GB
budget against the same failure and intended two workers on a 60 GB runner;
the runner reports 61 GB, one GB above the point where the division changes.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115277&sha=8a253f5b442c2503d40d0606fc79197de555a851&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29
Related: ClickHouse#115277

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@leshikus leshikus added the can be tested Allows running workflows for external contributors label Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d7f7499]

Summary: ✅


AI Review

Summary

This PR changes integration-test worker sizing so flaky and targeted runs use the job cgroup limit instead of host RAM, and it rejects worker plans that exceed that enforced limit. The sizing logic looks consistent with the failure report, but I would not clear the review yet because the new Utils.memory_limit parser still has no focused regression coverage.

Tests
  • ⚠️ [ci/praktika/utils.py:567] Utils.memory_limit now carries the correctness contract for worker sizing across cgroup v2, cgroup v1, inherited-parent limits, and unlimited fallbacks, but the branch still adds no dedicated ci/tests coverage for those layouts. The assertion in ci/jobs/integration_test_job.py:932 only exercises the one runner shape the job happens to see today, so it would not catch a future parser regression that falls back to host RAM on another supported cgroup layout. Please add a small unit matrix that stubs those file reads and proves the returned limit for each case.
Final Verdict

⚠️ Changes needed before merge: add focused regression tests for Utils.memory_limit.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 21, 2026
Comment thread ci/jobs/integration_test_job.py Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 093a4b98d with master 494c47005 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4399d6c6a; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 708.92 MiB 705.88 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

Review pointed out that the previous commit raised `MAX_MEM_PER_WORKER_DIST_EACH`
to compensate a measurement error rather than fixing it, and that the reserved
headroom would drift again. That is right, and the gap is by construction:
`ci/defs/job_configs.py` starts the integration container with
`--memory=LIMITED_MEM`, i.e. `physical_memory() - 2 GiB`, while the sizing code
inside that container reads host RAM through `Utils.physical_memory` and so
over-counts by exactly the reserved 2 GiB - the failing job logged `mem_gb: 61`
against an enforced limit of 59 GiB.

`Utils.memory_limit` resolves the job's own cgroup through `/proc/self/cgroup`
and reads `memory.max` (v2) or `memory.limit_in_bytes` (v1), falling back to
physical memory when there is no limit. Resolving the path is required rather
than reading the mount root: CI passes `--cgroupns=host`, so
`/sys/fs/cgroup/memory.max` is the host root cgroup and reads as `max`.
Verified under Docker with `--memory=2g` on a 7 GiB host: `cgroupns=private`
resolves `/sys/fs/cgroup/memory.max`, `cgroupns=host` resolves
`/sys/fs/cgroup/docker/<id>/memory.max`, both returning 2 GiB.

With the enforced limit, `min(16 // 5, 59 // 20) = 2` workers, so
`MAX_MEM_PER_WORKER_DIST_EACH` goes back to 20. Loadfile runs are unchanged:
`min(16 // 5, 59 // 11) = 3`, as before.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@leshikus leshikus changed the title Fit --dist=each integration test workers into the runner memory cgroup Size integration test workers from the job cgroup limit instead of host RAM Aug 24, 2026
Comment thread ci/praktika/utils.py
return int(subprocess.check_output(["sysctl", "-n", "hw.memsize"]).strip())

@staticmethod
def memory_limit() -> int:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that flaky/targeted worker sizing depends entirely on Utils.memory_limit, this helper needs focused regression coverage for the cgroup layouts it branches on. Please add a small ci/tests matrix for cgroup v2 (memory.max), cgroup v1 (memory.limit_in_bytes), and the unlimited cases (max / v1 sentinel) so a parsing regression here cannot silently send these jobs back to sizing off host RAM.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 671dd59

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The current head still only changes ci/praktika/utils.py:567-592 and adds the runtime preflight in ci/jobs/integration_test_job.py:933-939; there is still no focused ci/tests coverage for the v1, v2, inherited-parent, and unlimited branches of Utils.memory_limit.

That startup allocation exercises only the one live runner layout the job happens to see today, so it does not protect the parser itself from regressing back to sizing off host RAM on the other cgroup shapes this helper now has to support.

Picks up 81699bd, which fixes the version-pinned
`test_settings_history_source_gate` self-test that failed `CI Tests` on this
branch. Praktika reuses a cached result for an unchanged digest, so a re-run
alone could not pick it up.
Comment thread ci/praktika/utils.py Resolved
leshikus and others added 2 commits August 26, 2026 16:48
… clusters

Review raised two points on `Utils.memory_limit`.

A cgroup v2 leaf reading `max` does not mean unlimited, because limits are
inherited: with `/parent` at 64G and `/parent/child` at `max`, the process is
still capped at 64G. The helper read only the leaf and fell back to host RAM,
which is the bug this branch removes. It now walks from the leaf up to
`/sys/fs/cgroup` and keeps the smallest numeric value it finds, which is what
the kernel enforces and which also absorbs the v1 unlimited sentinel. Note that
`base/base/getMemoryAmount.cpp` does not do this - its loop climbs only while
`memory.max` cannot be opened and returns "unlimited" as soon as it opens one
holding `max`, so it has the same blind spot rather than being a model for it.

Verified in containers running this function. With `--memory=2g` it returns
2048 MiB under both `--cgroupns=private` and `--cgroupns=host`. In a child
cgroup with no `memory.max` of its own under a root limited to 2g, it returns
2048 MiB where the previous single-level read returned the 7933 MiB of host RAM.

The second point asked for a unit matrix over synthetic cgroup layouts. A test
built on fake trees pins the parser, not the outcome that matters, so instead
the job now allocates and touches `workers * mem_per_worker` before starting any
cluster. A runner that cannot back the plan fails within seconds of the job
starting instead of thrashing for 45 minutes and reporting nothing, which is the
failure mode of the report below. `mem_per_worker` moves above the branch so it
is defined on both paths, and local runs skip the check. Cost measured at
5.5-6.0 GiB/s: about 7s for the flaky check's 2 x 20GB.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115277&sha=8a253f5b442c2503d40d0606fc79197de555a851&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The budget check added in the previous commit committed `workers * mem_per_worker`
of pages before starting the clusters. Under Linux overcommit that allocation
almost never returns `MemoryError`: on a runner that cannot back the plan the
cgroup OOM killer fires instead, and with `oom_score_adj=1000` inherited from the
job container it kills the harness. That turns jobs which previously completed
under pressure into OOM kills, and it burns seconds of every integration job to
learn nothing the kernel has not already told us.

Assert the sizing invariant instead: `workers` must not exceed what the enforced
limit affords, `max(1, mem_gb // mem_per_worker)`. It costs nothing, cannot push
the cgroup anywhere, and still fails immediately on the case this branch is
about - the failing report planned 3 workers of 20GB against an enforced 59GB.
The `max(1, ...)` mirrors the `or 1` floor in the sizing, so a runner smaller
than one worker's budget keeps running with a single worker rather than refusing
to start.

It also covers `--workers`, which bypasses the sizing entirely: `--workers 8`
with a 20GB budget on a 59GB runner now fails at once instead of thrashing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Dear @leshikus, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@leshikus

Copy link
Copy Markdown
Collaborator Author

Master solves the same problem with nested_budget_gb, worker_plan and mem_limit_gb in ci/jobs/integration_test_job.py

@leshikus leshikus closed this Nov 11, 2026
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 comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant