Repository navigation
Fix flaky test 04103_user_network_bandwidth_throttler - #106680
alexey-milovidov merged 1 commit into
Conversation
The test asserts that ProfileEvents['UserThrottlerSleepMicroseconds'] is greater than half of the target query duration. The throttler only sleeps when the natural read rate exceeds the configured throttle limit; when the natural rate drops close to the limit the token bucket never goes negative and the throttler skips its sleep path (see `Throttler::throttle` in `src/Common/Throttler.cpp`). PR ClickHouse#103586 added `no-random-settings` to remove S3-prefetch settings as one source of slow natural rate, but contention on the `Stateless tests (amd_tsan, parallel, 2/2)` runner still occasionally drives the natural S3 read rate close to or below the previous 1 MB/s limit. Post-merge CIDB: `pull_request_number != 0 AND check_start_time > 2026-06-05` shows 4 sightings (PRs ClickHouse#106222, ClickHouse#102039, ClickHouse#49966, ClickHouse#106184) all on amd_tsan parallel 2/2 with the `read 1 1 0` shape (duration ok, bytes ok, sleep below threshold). All four PRs already include the `no-random-settings` tag, so the remaining flakiness is contention-driven, not random-settings driven. Drop the throttle limit and dataset 5x so the throttle is well below any plausible natural rate (200 KB/s vs ~0.9 MB/s observed worst case = 4.5x safety margin). Test wall-clock stays at ~8s. Local 10/10 runs against an S3 disk produced sleep_us between 16.8s and 17.3s, comfortably above the 3.5s threshold. Closes: ClickHouse#103422 Related: ClickHouse#103586 Related: ClickHouse#106184 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-ci-task-worker:20260607-150400 |
|
Workflow [PR], commit [b92612e] Summary: ✅ AI ReviewSummaryThis PR narrows the flaky Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 863 line(s), 110 function(s) across 145 file(s) · Details Top files
|
Corrected narrative for the fix in a2a3a41, which restores the throttler rate headroom in `02703_max_local_read_bandwidth`, plus the reference to the pull request that surfaced the flake appended to the test's leading comment. The executable content of the test is byte-identical to a2a3a41. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113107&sha=8f0f86485d192241fd2ed5bc0f5cb0b7630d244c&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 Related: ClickHouse#113107 The test intermittently failed on `pread_threadpool` with only its 4th column wrong (`1 1 1 0`): the query was demonstrably slow and all bytes had passed the throttler, but `QueryLocalReadThrottlerSleepMicroseconds` came out 0. The 4th assertion is a coupled oracle. `Throttler::throttle` increments the bytes counter unconditionally (`Throttler.cpp:63-64`), but the sleep counter only inside `if (block)` (`:78-82`), and `block` requires `tokens_value < 0` (`:70`). The token bucket (`:110-125`) only goes negative while bytes arrive faster than the cap, so once a loaded runner's read rate falls to about the cap the throttler correctly does not sleep and the assertion fails. The fixture had no margin to lose. `M` is the decimal suffix in `readTextWithSizeSuffix` (the binary form needs a trailing `i`, as `01039_test_setting_parse` pins), so the old cap was 1 MB/s = 1e6 B/s and the 8 MB payload owed exactly (8e6 - 1e6) / 1e6 = 7.0 s. That is exactly what the `query_duration_ms >= 7e3` column also demands, so column 1 was passing on unrelated overhead, and column 4 had only 2.0x over its 3.5 s threshold. The pre-existing comment `(8-1)/1=7 seconds` was right; the fixture's problem was the absent margin, not the arithmetic. The sleep time is not lost or misattributed to a pool thread. In the reported failure `QueryLocalReadThrottlerBytes` exceeded 8e6 while its sibling sleep counter was 0, and both are charged through the same `CurrentThread::getProfileEvents` a few lines apart in `Throttler::throttle`, so a thread detached from the query would have lost both; the bytes recorded, therefore the thread was attached and the sleep branch simply never ran. Structurally there is also no pool thread to lose it on: for `pread_threadpool` the throttle call runs on the consuming pipeline thread in `AsynchronousReadBufferFromFileDescriptor::nextImpl`, and `ThreadPoolReader` never throttles. The change co-reduces the payload (1e6 -> 2e5 rows) and the cap (1e6 -> 160000 B/s), which raises the owed sleep from 7.0 s to 9.0 s at comparable wall clock: 1.29x over the duration floor, 2.57x over the sleep threshold, and the read rate must degrade 6.25x further before the token bucket stops going negative. The two byte thresholds drop 8e6 -> 1.5e6, which still requires 93.75% of the nominal payload to pass through the throttler. All four assertions, both time thresholds and the reference file are unchanged. This is the same fix that was merged for the sibling `04103_user_network_bandwidth_throttler` in ClickHouse#106680 (issue ClickHouse#103422). Reproduced deterministically by capping the arrival rate with `max_execution_speed_bytes` and `max_threads=1`: the unmodified test prints `1 1 1 0` on all three read methods, and `1 1 1 1` with the injection absent. The modified test stays green under the same injection, and also at arrival rates below its own cap. 50/50 clean local runs; runtime 23.9 s -> 28.3 s. No source change: the throttler behaved correctly at every arrival rate measured, so there is no product defect here. Co-Authored-By: Claude Fable 5 <[email protected]>
The test asserts
ProfileEvents['UserThrottlerSleepMicroseconds']is greater than half the throttled query duration. The throttler only enters its sleep path when the natural read rate exceeds the configured limit; when the natural rate drops close to the limit, the token bucket never goes negative and the assertion flaps.PR #103586 added
no-random-settingsto remove S3-prefetch settings as one source of slow natural rate. Post-merge CIDB shows 4 sightings onStateless tests (amd_tsan, parallel, 2/2)(PRs #106222, #102039, #49966, #106184), all with theread 1 1 0shape (duration ok, bytes ok, sleep below threshold). All four already carry theno-random-settingstag, so the residual flakiness is contention-driven, not random-settings driven.Drop the throttle limit and dataset 5x (1 MB/s -> 200 KB/s, 1e6 -> 2e5 rows). Wall-clock stays at ~8s. The 200 KB/s limit is well below the worst observed natural S3 read rate on contended TSAN parallel runners (~0.9 MB/s), giving a 4.5x safety margin. Local 10/10 iterations on an S3 disk produced
sleep_usbetween 16.8s and 17.3s, comfortably above the 3.5s threshold.Closes: #103422
Related: #103586
Related: #106184
CI report (post-merge sighting on PR #106184): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106184&sha=31a83e8fe57d67ba3f402133ba620f7b99a63ebd&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required.
Version info
26.6.1.481