Repository navigation
Follow server memory in both directions when shedding test workers - #119793
Merged
Merged
Conversation
`clickhouse-test` shed one parallel worker every 30 s while the server's RSS stayed above 80% of `max_server_memory_usage`, and nothing ever started one again. The trigger is a level crossing, so a run whose memory *hovers* at the threshold - not one that runs away - loses its whole pool one worker at a time. On `Stateless tests (arm_asan_ubsan, azure, parallel)` for #119685, eleven sheds in 8 min 47 s took 12 workers down to 1, throughput fell from 144.8 to 11.6 tests/min - 12.5x, exactly the pool ratio - and the 9000 s job timeout killed the run at 8970 of 13957 tests with every test that ran reporting `OK` and no failing test anywhere. The fraction printed 80% or 81% at every one of the eleven sheds and spent 3 min 36 s below the threshold in between; and taking the pool from 12 workers to 4 did not move it by a printed point, because under ASan the server's RSS is allocator state and caches that do not shrink when queries stop. The mechanism was paying throughput for relief it was not getting. Add the missing direction: at or below `MEMORY_RECOVERY_THRESHOLD` a request no worker has claimed yet is withdrawn, or else one shed worker is started again against the same shared queue. The gap to the shed threshold is the hysteresis band that keeps a fraction sitting on the threshold from draining the pool. Give the pool a floor of `jobs // 2` where workers share a queue. Halving concurrency is the largest cut whose worst case, paid from the very first test, still fits a budget sized at about twice the median run; dropping to one worker fits it from no point in the run, so it trades a server that survived for a job killed mid-suite. Where each worker owns its queue (`--no-self-parallel`, used only with `--flaky-check`) a shed worker cannot be started again without re-running its own tests, and those runs are bounded by a time limit rather than a test count, so the pool may still drain to a single worker there, as before. Compute the shed cap from `jobs + workers_restored - shed_requests` instead of `len(processes) - workers_to_shed.value`. A worker claims a request, and commits to stopping, by decrementing `workers_to_shed`, but it stays in `processes` until it has actually exited, so the old cap lags by that window and lets one extra request through - enough, in a streak, to reach zero workers, which ends the parent loop and prints `All tests have finished` with part of the suite never run. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119685&sha=db7f44938b24dba4e56b3ebf049784c7a65532d1&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29 Pull request: #119685 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [08186aa] Summary: ✅ AI ReviewSummaryThis PR makes Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 08186aa.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +233 lines in 62 files (-117 lines lost coverage) · Details |
`jobs + workers_restored - shed_requests` is the pool left once every
issued request is honoured only where workers leave by shedding alone.
With `--no-self-parallel` the parallel tests are dealt out by hash, so a
worker whose share comes out empty exits immediately - and under
`--flaky-check`, the only user of that mode, every rerun of a selected test
hashes into the same queue, so with few enough tests selected the rest of
the pool is gone before the first memory check. The cap still read the
whole configured fan-out there and would stop the single worker carrying
the run: the `while processes:` loop then ends with that worker's queue
unrun and nothing to report it, since a shed worker is not a failure.
Take the smaller of that count and `len(processes) - workers_to_shed.value`.
Each is blind to something the other sees - the first counts a worker that
has claimed a request and not exited yet, the second counts the workers
that exited on their own - so a request is only issued while both agree
there is room.
Measured with a stub worker driving the real `do_run_tests` against a
scripted memory fraction (`--jobs 4`, 4000 stub tests of 5 ms, the memory
constants scaled down 25x), every rerun hashed into one queue and the
fraction pinned at 0.85:
master 4000 of 4000 tests, 20.8 s
before 196 of 4000 tests, 1.1 s, reported as a complete run
after 4000 of 4000 tests, 20.4 s
The shared-queue lane is untouched by this commit: pinned at 0.85 the pool
still stops at its floor (4 of 8 workers, 23.6 s, against master's one
worker and 78.9 s), and a spike that clears still gets its workers back.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov
added a commit
that referenced
this pull request
Sep 14, 2026
A signed return address on the stack is only readable by an unwinder that strips the signature, and the sanitizer runtimes shipped with the toolchain do not. `compiler-rt`'s frame-pointer unwinder (`BufferedStackTrace::UnwindFast`) collects the allocation and deallocation stacks behind every ASan and LSan report, and the `STRIP_PAC_PC` it applies to a saved return address expands to the identity unless `compiler-rt` itself was compiled with `-mbranch-protection` (`sanitizer_ptrauth.h` gates the `xpaclri` path on `__ARM_FEATURE_PAC_DEFAULT`). The runtime linked into this pull request's own `arm_asan_ubsan` build has no `xpaclri` in `UnwindFast`, so signed frames reach the reports verbatim: the signature sits in the bits above the virtual address, and every frame past the innermost one symbolizes to `<unknown module>`. It is also a memory leak in disguise. `paciasp` mixes `SP` into the signature, so one call site yields a different value at every stack depth, and each one takes a fresh entry in the stack depot, which is never freed. That is visible in CI: `Stateless tests (arm_asan_ubsan, azure, parallel)` hit the 9000 s budget at 8955/13957 on both runs of `db7f4493` with every test `OK`, having peaked at 80.8 and 81.9 GiB where 30 consecutive master runs of the same job peaked at 64 to 74 GiB and finished in ~4500 s. The server crossed the memory-pressure threshold of `clickhouse-test` 11 times and the worker pool drained from 12 to 1 (that regulator only sheds and never restores - issue #119791, fix #119793 - which turned the extra memory into a timeout instead of a slowdown). Our own unwinding is unaffected, which is why nothing else in CI noticed: `StackTrace` and jemalloc's profiler go through `unw_backtrace`, whose DWARF stepper follows `DW_CFA_AARCH64_negate_ra_state`, and the frame-pointer walk that `StackTrace::tryCapture` uses under TSan is abseil's, which strips the signature with `xpaclri` unconditionally. Related: #119791 Related: #119793 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two review findings on the memory-driven worker shedding. The cap on shed requests was read from the parent's own bookkeeping, and both counts it used could be stale at the moment the request is acted on. `len(processes)` still lists a worker that exited on its own until the next reap, and that reap ran at the end of the iteration - after the memory sample. A worker leaving the pool during the sample's own round trip to the server is invisible either way, so the parent could tell the last busy worker to stop and end the run with that worker's queue never run, reported as a complete run because a shed worker is not a failure. The count is now kept by the workers themselves: `live_workers` counts the workers that have not decided to stop, and a worker leaves it inside the same critical section in which it takes a shed request or finds its queue empty, so the two can never be observed out of order. The worker re-checks the floor under that lock before honouring a request, which is the only check taken at the instant it matters; a request it declines stays pending for whenever the pool is larger again. For a worker-local queue (`--no-self-parallel`) taking the next test is inside the same section - the queue is a plain list there. A shared queue is a manager proxy and stays outside the lock: a worker only reaches the end of a shared queue once it is empty, so there is nothing left for the worker that would stop in its place. Stub-worker harness against the real `do_run_tests`, with a worker made to exit during the memory sample (`--jobs 2`, `--no-self-parallel`, one worker holding 20 tests and the other a single one, fraction pinned at 0.85): before: 3 of 21 tests run, reported as a complete run after: 21 of 21 The floor itself was `jobs // 2`, which is below half for an odd pool - `jobs = 3` could shed down to one worker, a 3x slowdown against the 2x the rationale rests on, and `jobs` is clamped to the number of selected tests, so an ordinarily even configuration can come out odd. It is now rounded up. Same harness, `--jobs 3`, 150 tests, fraction pinned at 0.85: before 2 workers shed and 3.5 s, after 1 shed and 2.3 s, all tests run in both. The shared-queue lane is unchanged otherwise: `--jobs 8` under sustained pressure still sheds exactly 4 and runs all 4000 stub tests, and a fraction that recovers still gets the workers back. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Sep 27, 2026
…ned-test-groups-on-abort Resolve the conflict with ClickHouse#119793 in `do_run_tests`: keep its worker pool (`live_workers`, `start_worker`, `reap_finished_workers`, the recovery threshold) inside the `try` whose `finally` reaps, and register each pid in `worker_pids` inside `start_worker`, so a worker started again after a shed is covered by the abort-path reap like the initial ones. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #119791
Related: #119685
Related: #108689
Related: #111789
clickhouse-testsheds one parallel worker every 30 s while the server's RSS is above 80% ofmax_server_memory_usage, and nothing ever starts one again. The trigger is a level crossing, so a run whose memory hovers at the threshold - not one that runs away - loses its whole pool one worker at a time.That is what killed
Stateless tests (arm_asan_ubsan, azure, parallel)on #119685 (report, job log): eleven sheds in 8 min 47 s took the pool from 12 workers to 1, throughput fell from 144.8 to 11.6 tests/min - 12.5x, exactly the pool ratio - and the 9000 s job timeout killed the run at 8970 of 13957 tests with every test that ran reportingOKand no failing test anywhere. Finishing at that rate would have needed 7.1 more hours.Nothing was running away: the fraction printed 80% or 81% at every one of the eleven sheds and spent 3 min 36 s below the threshold in between. And the shedding bought nothing - taking the pool from 12 workers to 4 did not move the fraction by a printed point, because under ASan the server's RSS is allocator state and caches that do not shrink when queries stop. #111789 recorded the same finding for
amd_asan_ubsan, distributed plan, parallel, moving it to a bigger runner so the suite could keep full concurrency "instead of cutting workers - which barely moved peak RSS and only made the job slower".Changes
All three are inside the memory block of
do_run_tests.A reverse gear. At or below
MEMORY_RECOVERY_THRESHOLD(0.75) a shed request that no worker has claimed yet is withdrawn; failing that, one shed worker is started again against the same shared queue. The five-point gap to the shed threshold is the hysteresis band. With a single threshold the pool can only fall, so a fraction sitting on the threshold drains it however brief each excursion above is - eleven single samples, spread over nine minutes, cost this run its entire pool.A floor. Where workers share a queue the pool never drops below
jobs // 2. Halving concurrency is the largest cut whose worst case, paid from the very first test, still fits a budget sized at about twice the median run (p50 4601 s against the 9000 s timeout); dropping to one worker fits it from no point in the run, so past the floor the mechanism is only trading a server that survived for a job killed mid-suite. Where each worker owns its queue (--no-self-parallel, used only with--flaky-check) a shed worker cannot be started again without re-running the tests it already did, and those runs are bounded by a time limit rather than a test count, so a drained pool there costs reruns and not a red job - that path keeps the old drain-to-one behaviour.A cap on two counts.
len(processes) - workers_to_shed.value > 1counts a worker that has already claimed a request, and so committed to stopping, but has not exited yet. The cap can therefore let one extra request through, taking the pool one below its intended minimum and at the limit to zero - which ends thewhile processes:loop and printsAll tests have finishedwith part of the suite never run.jobs + workers_restored - shed_requestsis the pool left once every issued request is honoured, and it does not lag - but it only counts the workers that leave by shedding, and with--no-self-parallelthe tests are dealt out by hash, so a worker whose share comes out empty exits at once: under--flaky-check, the only user of that mode, every rerun of a selected test hashes into the same queue, and with few enough tests selected that count reads the whole configured fan-out while a single worker carries the run. Each count is blind to something the other sees, so the cap is the smaller of them, and a request is only issued while both agree there is room.The pressure signal itself is unchanged, and it is worth naming what it is: the server's RSS against a limit on its tracked memory, two quantities that differ by the sanitizer's own overhead, which is why an ASan job sits near 80% in normal operation. Re-scaling it is a separate question from the regulator having only one direction.
Measurements
A harness drives the real
do_run_testswith a stub worker and a scripted memory fraction, in a copy of the script whoseMEMORY_CHECK_INTERVALandMEMORY_SHED_COOLDOWNare scaled down 25x so an hour of run compresses into half a minute. 8 workers - so the floor is 4 - and 12000 stub tests of 5 ms, identical for both versions.poolis the smallest live worker count reached while a tenth of the suite was still unrun, replayed from the workers' own start and exit events; all ten runs executed all 12000 tests.The flat 0.30 row is each column's own baseline. On master every shape that crosses the threshold drains the pool to a single worker and pays 3.3x to 4.3x of the baseline for it - the CI failure, reproduced from the memory signal alone - and the shape that recovers after six seconds stays at three workers for the remaining 90% of the run, because nothing puts them back. With this PR the pool recovers or holds at its floor and every scenario finishes within 1.1x to 1.8x of the baseline. The
0.78 / 0.82row is the one that matches the failing job: it never drops far enough to trigger a restore, so there the floor alone is what keeps the run finishable.The same harness covers the
--no-self-parallellane, where the cap has to read the live pool:--jobs 4, 4000 stub tests of 5 ms all hashed into one worker's queue (one selected test reran, as--flaky-checkschedules it), fraction pinned at 0.85, so three workers exit before the first memory check and one carries the run.jobsaloneThe middle row is what a cap that cannot see those three exits does: it stops the only worker left, the parent loop ends with the queue unrun, and nothing reports it, because a shed worker is not a failure. Found in review; fixed by taking the smaller of the two counts.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119793]
Version info
26.10.1.804-master(included in26.10and later)