Repository navigation
Make test_server_overload deterministic instead of probabilistic - #113529
PedroTadim merged 1 commit into
Conversation
test_server_overload/test.py::test_drop_connections fails intermittently with
"Expected to drop the connection due to the server being overloaded at least
once". The test asserts an event it only makes probable.
checkCPUOverload computes
probability_to_throw = (clamp(cpu_load, min, max) - min) / (max - min)
so the probability reaches 1 only once cpu_load >= max_ratio. The test
configured min=1.0, max=6.0, demanding a wait/busy ratio of 6.0 for a certain
drop, while its own four-heavy-query load produces roughly 3.3 to 5.3. Every
probe was therefore a Bernoulli draw near p=0.5, and a run in which all draws
fail trips the assertion. That is also why ClickHouse#96106, which doubled the probe
count and the load duration, did not help: more attempts do not remove the
dice.
Measured with a throwaway instrumented build that logs wait_delta, busy_delta,
cpu_load and probability_to_throw on every accept-path evaluation, driven by a
probe loop that does not stop at the first drop. Over 318 loaded evaluations at
the four-concurrent-query shape the test runs, the probability never reached 1
(mean 0.53, range 0.45 to 0.87), and it never reached 1 in any of the 1236
loaded evaluations across every load shape measured. The Bernoulli model is
exact: the summed per-probe probabilities predicted 67.0 drops where 63
occurred. Of the loaded probes about 10 percent had cpu_load == 0, so the
busy-time gate was not the binding term.
Putting max_ratio below the achievable ratio makes an overloaded window drop
with probability 1. One loaded probe then suffices, so the probe count, the
probe pacing and the phase of the 1 Hz asynchronous-metrics reset all stop
mattering. 1.5 sits 2.17x below the weakest ratio observed at the shape the
test runs (3.2551) and above the highest idle raw ratio (1.4015); even a
degraded three-query load stays clear (weakest 1.8588). Contention on a slower
runner raises the wait/busy ratio, so it moves away from the band rather than
into it. The sibling test_overload had the identical band on the query path and
gets the same treatment.
Both cases now also assert that the probability the server logged is 1, so a
regression that reintroduced a fractional probability would be caught rather
than passing on a lucky draw.
The test becomes stricter rather than weaker. The
busy_delta > os_cpu_busy_time_threshold precondition is untouched, so an idle
server still evaluates to cpu_load == 0 and is still admitted: over 254 idle
probes that gate held every time, with a 4x margin (max busy_delta 74241 us
against the 300000 us threshold). Both contains_in_log assertions and the
"Connection reset by peer" check are unchanged.
Validation: 50 randomized repetitions of both cases pass, with the server log
now reporting "probability used to decide whether to drop the connection 1",
while 50 repetitions of the unmodified files reproduce the CI failure once.
Five mutants each turn the test red, including removing the synthetic load,
reverting only max_ratio, and neutering the accept-path connection filter in
Server.cpp.
Related: ClickHouse#112878
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 fix round; final delta
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260805-155700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-9:20260805-155700 |
|
cc @alexkats, could you review this? You wrote the overload connection filter and this test; the test asked for a wait/busy ratio of 6.0 for a certain drop while its own load produces 3.3 to 5.3, so every probe was a coin flip near p=0.5, and this lowers the test config's max ratio below the achievable ratio so an overloaded window drops with probability 1. |
|
Workflow [PR], commit [0be329b] Summary: ✅ AI ReviewSummaryThis PR makes Final VerdictStatus: ✅ Approve |
CI finish ledger - 0be329bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
All 174 check-runs completed, Session id: cron:our-pr-ci-monitor:20260805-230000 |
test_server_overload::test_overload still failed intermittently after ClickHouse#113529, which removed the Bernoulli lottery but left a sampling lottery. checkCPUOverload calls getCPUOverload(os_cpu_busy_time_threshold) with reset defaulted false (ProfileEvents.cpp:1972). getCPUOverload returns 0 at :2039 while the busy time accrued since the last reset is below the threshold, and on 0 the caller's `cpu_load > DBL_EPSILON` test fails, so the ratio, the probability ramp and the draw are never evaluated. The only reset=true caller is AsynchronousMetrics.cpp:2734, so both consumers share one prev_* pair: every reset window opens at zero busy time and its first threshold/busy_rate is a window in which an overloaded server provably cannot throw. The probe loop samples that grid at about 0.99 s per iteration, because each node1.query() spawns a fresh clickhouse-client process against a one-core-pinned server, so the 0.3 s sleep is not the period. Against the reset cadence that is a near-resonance: the phase drifts only about 9 ms per iteration, so a run whose starting phase lands inside the blind window stays inside it for every probe that overlaps the 30 s load, and the loop falls through to the assertion. On the failing CI runner the per-probe busy time was around 8000 us against the 300000 us budget. Setting the fixture's threshold to 0 removes the blind window, so the verdict follows the measured wait/busy ratio rather than the probe's arrival time. 0 is the degenerate in-domain value rather than another calibrated constant: at :2039 the test becomes busy_delta <= 0 || wait_delta <= 0, exactly the liveness precondition the ratio needs to be defined. Anything larger has to encode a busy rate and a reset cadence that the setting cannot observe, which is why a smaller nonzero value was measured to change no outcome at all. This does not weaken the test. What excludes an unloaded server is min_os_cpu_wait_time_ratio_to_throw, not the busy-time budget: measured on an idle node at threshold 0, the ratios that now reach the ramp are 0.14 to 0.47, all giving probability 0 and no throw, while 5 of 9 idle windows are still refused on the wait_delta clause. Both "probability ... 1." assertions from ClickHouse#113529 are kept, so the saturated ramp remains the thing under test, and the test now throws on its first probe instead of iterating. Validated in both directions. With the fix, test_overload passes 10/10 on debug, 10/10 on asan+ubsan and 50/50. With the throttle mutated it still reddens: checkCPUOverload returning early fails 3/3, the probability ramp forced to 0 fails 3/3, and the threshold set unreachably high fails 3/3, each with the assertion CI reported. The pre-fix config plus a disabled throttle also fails 3/3, so the sensitivity was not created by this change. test_drop_connections passes 10/10 with its own config untouched. node2's early_drop.xml keeps the same budget: it shares the blind window but is green today, and its config also carries the drop-connection ratios. The product default os_cpu_busy_time_threshold = 1'000'000 is also unchanged; the shared prev_* pair gives any server a short blind window each period, which is a product question rather than one to settle from a test fix.
… test_server_overload
test_overload asserted the rendered value of the throttle's rejection
probability ("probability used to decide whether to discard the query 1."),
i.e. p == 1. Both setting pairs document p as a linear interpolation between
min and max ratio, and ProfileEvents::checkCPUOverload implements exactly
that: p = (clamp(cpu_load, min, max) - min) / (max - min), followed by one
Bernoulli draw. With the test's min=1, max=1.5, p reaches 1 only when the
runner's wait/busy ratio reaches 1.5. The CI runners that run this test
produce 1.287 - 1.393, so p is fractional and the second assertion fails
while the rejection itself is correct: the observed 1.2870989304812834 gives
0.5741978609625669, matching the failure log exactly. The assertion was a
statement about the runner, not about ClickHouse.
Drop the asserted value on both carriers and keep the message check. The
query-path assertion is rewritten value-free rather than deleted, because
SERVER_OVERLOADED is also raised by the workload scheduler (FifoQueue,
AllocationQueue), so asserting the error code alone would no longer pin the
rejection to the CPU throttle. On the connection path the identical assertion
is deleted outright, since the preceding line already asserts the same string
without its value.
max = 1.5 is kept on both paths: at the ratios CI produces it puts the
per-probe rejection probability at 0.57 - 0.79, so a rejection within the
test's 60 probes is effectively certain. The two comments stating the refuted
premise (that max is below the ratio the load produces, so the ramp
saturates) are rewritten to state the ramp semantics instead.
Verified by constructing the CI condition locally. This box reaches ratios of
3.5 - 7.1, above max, which is why the stock test passes here, so max was
raised above that range to put the ratio inside the band. On the unfixed tree
test_overload then fails 5/5 with the exact CI assertion and fractional
probabilities; with this change, on the same binary and configuration, it
passes 5/5, and 50/50 on the shipping config. Removing only the probability
clause from the server message reddens exactly the two rewritten assertions
while the error-code and log-line assertions still pass; zeroing the ramp,
disabling the check, and removing the synthetic load each still redden the
behavioural oracle.
Follow-up to ClickHouse#113529 and ClickHouse#115905.
Co-Authored-By: Claude Opus 5 <[email protected]>
Related: #112878
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
test_server_overload/test.py::test_drop_connectionsfails intermittently withExpected to drop the connection due to the server being overloaded at least once(report).
Root cause: the test asserts an event it only makes probable.
checkCPUOverloadcomputesprobability_to_throw = (clamp(cpu_load, min, max) - min) / (max - min), so it reaches 1 onlyonce
cpu_load >= max_ratio. The test configuredmin=1.0, max=6.0, demanding a wait/busyratio of 6.0 for a certain drop while its own load produces 3.3 to 5.3. Every probe was a coin
flip near p=0.5, which is why #96106, doubling the probe count and load duration, did not help:
more attempts do not remove the dice.
I instrumented
checkCPUOverloadlocally and sampled every accept-path evaluation with a probeloop that does not stop at the first drop. Over 318 loaded evaluations at the shape the test
runs, the probability never once reached 1 (mean 0.53); the Bernoulli model is exact, predicting
67.0 drops where 63 occurred.
This change puts
max_ratiobelow the achievable ratio (6.0 to 1.5) so an overloaded windowalways drops, and both tests now assert the logged probability is 1. One loaded probe then
suffices, and probe count, pacing and metric reset phase stop mattering. The sibling
test_overloadgets the same treatment.The test becomes stricter, not weaker. The
busy_delta > os_cpu_busy_time_thresholdprecondition is untouched, so an idle server still yields
cpu_load == 0and is not dropped:over 254 idle probes that gate held every time with a 4x margin. Both
contains_in_logassertions and the
Connection reset by peercheck are unchanged.Validation: 50 randomized repetitions of both cases pass, with the log now reporting
probability used to decide whether to drop the connection 1. Five mutants each turn the testred, including removing the load, reverting only
max_ratio, and neutering the accept-pathfilter in
Server.cpp.