Repository navigation
Fix flaky 02703_max_local_read_bandwidth: restore throttler headroom - #113365
PedroTadim merged 4 commits into
Conversation
…headroom
The test intermittently failed on pread_threadpool with only its 4th column
wrong (1 1 1 0): QueryLocalReadThrottlerSleepMicroseconds came out 0 while the
query was demonstrably slow and all bytes had passed the throttler.
The 4th assertion is a coupled oracle. Throttler::throttle increments the bytes
counter unconditionally, but the sleep counter only inside `if (block)`, and
block requires tokens_value < 0. The token bucket only goes negative when 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. With a
1 MiB/s cap over an 8 MB payload the fixture had only 1.115x of margin between
the cap and the arrival rate at which the assertion breaks (measured), which a
contended sanitizer runner erases. The nominal required sleep was also
8e6/1048576-1 = 6.63 s, already below the 7 s the first column demands, so that
column had been passing on unrelated overhead; the in-file comment claiming
"(8-1)/1=7 seconds" was wrong because '1M' is 1048576, not 1e6.
The sleep time is not lost or misattributed to a pool thread:
ThrottlerSleepMicroseconds is 0 as well in the reproduced failure, so no thread
slept at all. Both counters are charged through the same
CurrentThread::getProfileEvents() a few lines apart, and the pread_threadpool
throttle call runs on the consuming pipeline thread in
AsynchronousReadBufferFromFileDescriptor::nextImpl, not on a pool thread -
ThreadPoolReader never throttles.
Co-reduce the payload (1e6 -> 2e5 rows) and the cap ('1M' -> 160000 B/s)
together, which raises the required sleep to 9 s at comparable wall clock, and
rescale the two byte thresholds by the same factor so they keep asserting that
the whole payload passed 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 (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 arms, and 1 1 1 1 with the injection absent. The measured
failure boundary moves from 1.115x of the cap to at most 1.006x, and the test
now also passes 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.
Corrected narrative for the fix in a2a3a41, which restores the throttler rate headroom in `02703_max_local_read_bandwidth`. The previous commit message misread the size suffix `M` as binary and drew three wrong conclusions from it; this commit states the arithmetic correctly and adds the same figure to the test's leading comment. The executable content of the test is byte-identical to a2a3a41. The test intermittently failed on `pread_threadpool` with only its 4th column wrong (`1 1 1 0`): `QueryLocalReadThrottlerSleepMicroseconds` came out 0 while the query was demonstrably slow and all bytes had passed the throttler. 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: `ThrottlerSleepMicroseconds` is 0 as well in the reproduced failure, so no thread slept at all. Both counters are charged through the same `CurrentThread::getProfileEvents` a few lines apart, and the `pread_threadpool` throttle call runs on the consuming pipeline thread in `AsynchronousReadBufferFromFileDescriptor::nextImpl`, not on a pool thread - `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 1600982 B 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` (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]>
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]>
Internal review before publication (2 blockers, 4 major, 1 nit)Before opening this PR I ran three rounds of independent cold review of the resulting diff, each
The load-bearing correction is finding 1, and it strengthens the case: at 1e6 B/s the old fixture Derived purely from the fixture constants and the token bucket, the sleep assertion used to break Session id: cron:clickhouse-review-slot-49:20260804-171931 |
Pre-PR validation gate (click to expand)
Measured invariants: owed sleep No source change: the throttler behaved correctly at every arrival rate measured, so there is no product defect here. Session id: cron:clickhouse-review-slot-49:20260804-171931 |
|
cc @serxa, could you review this? The test's sleep assertion is coupled to the arrival rate: |
|
Workflow [PR], commit [07c76df] Summary: ✅ AI ReviewSummaryThis PR lowers the payload and Final Verdict✅ No new review findings. |
…bandwidth The headroom fix lowered both byte checks from `> 8e6` to `> 1.5e6` along with the payload, but 2e5 `UInt64` rows are 1.6e6 raw bytes, so `> 1.5e6` left 100600 measured bytes of slack. That is a real loss of contract: the two byte columns exist to prove the whole scan went through the local-read throttler, and a regression letting about 100 KB bypass it would still have printed `1 1 1 1`. Measured on the fixture (all three read methods, warm and cold mark cache): `ReadBufferFromFileDescriptorReadBytes` and `QueryLocalReadThrottlerBytes` are both 1600600 warm and 1600777 cold, deterministic over 9 runs. `CODEC(NONE)` makes the compressed file the raw payload plus a 25-byte header per compressed block, so the counter is always strictly above 1.6e6. Raising both checks back to `> 1.6e6` restores the same relative margin the pre-fix fixture had against `> 8e6` (0.0375% versus 0.0381%). Verified the tightened threshold is not vacuous by shrinking the payload: at 187500 rows (the 100 KB bypass the reviewer described) the counter is 1500746, which passes `> 1.5e6` and fails `> 1.6e6`; even 199900 rows, 800 bytes short, is caught. The sleep oracle this PR fixes is unaffected: the test passes three times with no injection and twice under a rate injection at 1.05x of its own cap, which is the arm that reproduces a loaded runner. CI: 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
CI finish ledger - 07c76dfCI fully finished on this head: 174 of 174 check-runs completed (51 success, 123 skipped,
Nothing failed on this head, and CIDB holds zero Session id: cron:our-pr-ci-monitor:20260805-023000 |
Related: #113107
Related: #106680
Related: #103422
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
02703_max_local_read_bandwidthintermittently fails onpread_threadpoolwith only its 4th columnwrong (
1 1 1 0), most recently on thisreport.
Root cause: the 4th assertion is a coupled oracle.
Throttler::throttleincrements the bytescounter unconditionally (
Throttler.cpp:63-64) but the sleep counter only insideif (block)(
:78-82), andblockrequirestokens_value < 0(:70). The token bucket (:110-125) goesnegative only 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 while bytes still record. The fixture had no
margin: at a 1e6 B/s cap over an 8 MB payload it owes exactly 7.0 s, exactly what column 1 also
demands, and column 4 had only 2.0x over its 3.5 s threshold.
The sleep is not lost or misattributed. In the reported failure
QueryLocalReadThrottlerBytespassedwhile its sibling sleep counter was 0, and both are charged through the same
CurrentThread::getProfileEventsa few lines apart, so a detached thread would have lost both. Nopool thread is involved either: for
pread_threadpoolthe throttle call runs on the consumingpipeline thread (
AsynchronousReadBufferFromFileDescriptor.cpp:141-142), not inThreadPoolReader,which never throttles.
The change co-reduces the payload (1e6 -> 2e5 rows) and the cap (1e6 -> 160000 B/s), raising the
owed sleep to 9.0 s at comparable wall clock: 1.29x over the duration floor and 2.57x over the
unchanged 3.5 s sleep threshold. Byte thresholds track the payload at 8e6 -> 1.6e6,
still requiring the whole scan be throttled. All four assertions, both time thresholds and
.referenceareunchanged. Same fix as #106680 for the sibling
04103_user_network_bandwidth_throttler.Validation. Capping the arrival rate (
max_execution_speed_bytes,max_threads=1) reproducesthe signature: unmodified prints
1 1 1 0on all three arms,1 1 1 1without the injection;modified stays green. 50/50 clean local runs, runtime 1.18x.
Version info
26.8.1.797(included in26.8and later)