Repository navigation
Fix flaky test_server_overload integration test - #96106
Merged
Merged
Conversation
`getCPUOverload` computes the CPU wait/busy ratio cumulatively since server startup (never resets). Startup and idle CPU time dilutes the overload signal, so it takes many seconds for the ratio to reach the `min_os_cpu_wait_time_ratio_to_drop_connection` threshold. With the previous threshold of 2.0 and only 30 retry iterations (9 seconds), the ratio often didn't reach the threshold in time, or too few qualifying attempts remained for the probabilistic check to trigger. Lower `min_os_cpu_wait_time_ratio_to_drop_connection` from 2.0 to 1.0 so the probability curve starts earlier. Increase retry iterations from 30 to 60 and heavy query timeout from 15 to 30 seconds for both tests. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
1 task
rorylshanks
pushed a commit
to rorylshanks/ClickHouse
that referenced
this pull request
Aug 6, 2026
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
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.
getCPUOverloadcomputes the CPU wait/busy ratio cumulatively since server startup (never resets). Startup and idle CPU time dilutes the overload signal, so it takes many seconds for the ratio to reach themin_os_cpu_wait_time_ratio_to_drop_connectionthreshold. With the previous threshold of 2.0 and only 30 retry iterations (9 seconds), the ratio often didn't reach the threshold in time, or too few qualifying attempts remained for the probabilistic check to trigger.Lower
min_os_cpu_wait_time_ratio_to_drop_connectionfrom 2.0 to 1.0 so the probability curve starts earlier. Increase retry iterations from 30 to 60 and heavy query timeout from 15 to 30 seconds for both tests.Changelog category (leave one):
See https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96012&sha=afe59262176650cd4a78ad8c5d2334344874c23e&name_0=PR&name_1=Integration%20tests%20%28amd_binary%2C%204%2F5%29
#96012
This only increases the probability. If it won't help, we will just remove the test.
Version info
26.2.1.288