Skip to content

Fix flaky test_server_overload integration test - #96106

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-test-server-overload
Feb 5, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-test-server-overload

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

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.

Changelog category (leave one):

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

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

  • Merged into: 26.2.1.288

`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]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8468fca]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Feb 5, 2026
@alexey-milovidov alexey-milovidov self-assigned this Feb 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Feb 5, 2026
Merged via the queue into master with commit cb3f569 Feb 5, 2026
129 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-test-server-overload branch February 5, 2026 21:31
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 5, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants