Repository navigation
Do not throttle local reads that are served from the OS page cache - #118495
Conversation
`max_local_read_bandwidth_for_server` and the per-query `max_local_read_bandwidth` exist to keep the load that ClickHouse puts on the block devices within a budget, but they accounted the bytes copied from the OS page cache exactly like the bytes that hit the disk. A query whose data is fully cached in RAM was slowed down to the configured disk bandwidth while producing almost no block device I/O, which makes the setting useless for its purpose: it has to be set at the disk bandwidth or above (and then it protects nothing), or below it (and then it penalizes cached reads). `ThreadPoolReader` already knows whether a read was served from the page cache - it tries `preadv2` with `RWF_NOWAIT` first and falls back to the thread pool on `EAGAIN`. Report that in `IAsynchronousReader::Result` and skip the throttler for such reads. This covers the default `local_filesystem_read_method = 'pread_threadpool'`; the synchronous `pread` methods cannot tell whether the data was cached, and reads with `O_DIRECT` always reach the device, so both keep being accounted. Closes: #118463
`02703_max_local_read_bandwidth` and `test_throttling` read data that they have just written, so it is in the OS page cache and is no longer accounted by the local read throttler when the default `pread_threadpool` read method is used. Read with `pread`, which cannot tell a cached read from a device read, and cover the `pread_threadpool` accounting in `05111_local_read_throttler_page_cache`.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [48e5e66] Summary: ✅
AI ReviewSummaryThis PR teaches the local-read throttlers to stop charging bytes that were served from the OS page cache, covering the default Final Verdict✅ No new findings. The previously raised review issues appear to be addressed in the current revision. LLVM Coverage ReportMeasured on commit 48e5e66.
Changed lines: Changed C/C++ lines covered: 98/102 (96.08%) · Uncovered code |
…cache-reads # Conflicts: # src/Core/ServerSettings.cpp
`ReadSettings::local_throttler` is not always the throttler of `max_local_read_bandwidth`: `BackupsWorker` and `MergeTreeSequentialSource` combine it with the throttlers of `max_backup_bandwidth`, `max_merges_bandwidth` and `max_mutations_bandwidth` through `ThrottlerArray`. Skipping the whole composite throttler for the data that came from the OS page cache disabled those limits as well, which broke `02704_max_backup_bandwidth` - a backup of a freshly inserted table was not throttled at all. Only the throttlers created by `Context::getLocalReadThrottler` model the bandwidth of the block device, so mark them with `Throttler::setLimitsBlockDeviceBandwidth` and route the page cache reads through the new `IThrottler::throttleOSPageCacheRead`, which skips exactly those and accounts the read in all the others. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1990 translation units recompiled, 12214 s compile time in total, 1990 of them have a recent master baseline. |
…hrottler The test required `QueryLocalReadThrottlerBytes` to be exactly `ThreadPoolReaderPageCacheMissBytes`, but the query also reads small metadata files synchronously with the `read` method (which cannot tell a cached read from a device read, so it is throttled), and a prefetched buffer can be discarded unconsumed. Reproduced locally with the randomized settings: one 4096-byte synchronous read made the throttler count 4096 bytes with zero thread pool misses. Check instead that the throttler accounts at most the bytes that were not page cache hits. The test cannot pass on macOS, where there is no `preadv2` with `RWF_NOWAIT`, so mark it `no-darwin`. Also address the review: `test_local_read_throttling_reload` now checks that a `pread_threadpool` scan of cached data is not throttled by the `max_local_read_bandwidth_for_server` throttler created on config reload. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118495&sha=816d62734cc54d0ed78a622bb3643de7da03a028&name_0=PR PR: #118495 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # src/Interpreters/Context.cpp
`ThreadPoolReader` reports `ThreadPoolReaderPageCacheHitBytes` only when `preadv2` with `RWF_NOWAIT` is usable. On old kernels, under `seccomp` profiles, or on filesystems rejecting the flag, every read falls back to `pread`, so requiring page cache hits made the tests fail on supported environments. Keep only the accounting invariant in `05111_local_read_throttler_page_cache`, and check the duration in `test_local_read_throttling_reload` only when page cache hits happened. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…age cache The files of the filesystem cache (`CachedOnDiskReadBufferFromFile` and `DiskCacheProvider`) are always read with `LocalFSReadMethod::pread`, so a query served from a hot cache file still consumed the tokens of `max_local_read_bandwidth` and was slowed down to the disk speed. `ReadBufferFromFileDescriptor` with `pread` now tries `preadNoWait` first when there is a throttler, the file is not opened with `O_DIRECT`, and the system call is usable, and reports such reads with `throttleOSPageCacheRead`. This covers the cache files and `local_filesystem_read_method = 'pread'`; the `read` method still cannot tell a cached read from a device read. The new `ReadBufferFromFileDescriptorPageCacheHitBytes` profile event counts the detected bytes. The throttling tests that relied on `pread` being throttled for cached data now use `read`, and `05317_local_read_throttler_filesystem_cache` checks the accounting for a warmed-up filesystem cache. #118495 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re its reads `ReadSettings::local_throttler` can also carry `max_merges_bandwidth`, `max_mutations_bandwidth` and `max_backup_bandwidth` throttlers, which account the reads served from the OS page cache as usual. For them the `preadv2` with `RWF_NOWAIT` probe was an extra system call on every page cache miss without any effect on throttling. Add `IThrottler::ignoresOSPageCacheReads` (true if the throttler, one of its parents, or one of the throttlers of a `ThrottlerArray` limits the block device bandwidth) and enable the detection only when it returns true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118495&sha=ed580b74f8c4042e7540fb9a2141f40d56437854&name_0=PR&name_1=Fast%20test and provide a fix in a separate PR. If the fix is already in progress, link it here. The |
|
Acknowledged. I'm investigating the Fast test timeouts of |
|
🕵 Thanks @groeneai — the analysis is right: the four throttled progress-bar |
With the randomized `use_columns_cache = 1`, the measured query of `05317_local_read_throttler_filesystem_cache` is served from the columns cache and does not read from the filesystem cache at all, so the check `CachedReadBufferReadFromCacheBytes > 0` failed. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118495&sha=fd1b31c7daaec94c8090e5fb5c199ba6a2883831&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 #118495 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hout a limit `Context::reloadLocalThrottlerConfig` keeps the server local read throttler after `max_local_read_bandwidth_for_server` is reloaded back to 0 and only sets its speed to 0. `ignoresOSPageCacheReads` kept returning true for it, so the synchronous `pread` (including the files of the filesystem cache) kept paying for an extra `preadv2` with `RWF_NOWAIT` although nothing was limited anymore. Now it requires an active speed limit. Covered in `test_local_read_throttling_reload`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118495&sha=98758e9e93a9215d0dbb534feac1d292653670dd&name_0=PR&name_1=Fast%20test%20(arm_darwin) and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
This job ran on It is the same class as on #122362 (#122362 (comment)), now on a third host that is not recycling: in the job samples it was at 42G used on 2026-09-29, 48G on 10-04, 77-80G on 10-06, 97G today, and never dropped back to the ~43G post-reboot level. The fix is #113605: it runs the free-space check before every job on macOS too, so a host this full refuses the job and reboots instead of taking it. It is waiting for review and deploy by @ leshikus. #124316 is the diagnostic that prints what fills the disk on such a host. |
…s `RWF_NOWAIT` On filesystems that reject `RWF_NOWAIT` for a real file descriptor (e.g. `tmpfs` answers `EOPNOTSUPP`), the synchronous `pread` path did a failing `preadNoWait` before every `pread`. Turn the detection off after the first such error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118495&sha=7bd5866a7c611e5c932e93d17ac9da36d4dc0203&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%2C%20function_prop_fuzzer%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
Acknowledged. I'm investigating the Repro on master (debug build of 44b568f): |
|
Fix: #124570.
|
…e the window end `executeHop` finds the window end by subtracting the hop until the end is not after the time. ClickHouse#114607 made the loop throw when the subtraction makes the end larger (a wrap around zero), but not when it leaves the end unchanged, and then the loop never exits and cannot be cancelled. That happens for `Date` interval kinds when the bound saturates at the end of the calendar: `addQuarters`/`addMonths`/`addYears` clamp to `0000-01-01` (ExtendedDayNum -719528), which narrows to day 1368 in `UInt16`, and subtracting the hop from 1368 saturates to the same value again. The loop condition compares that day number with the time in seconds, so it stays true for every time below 1368 seconds. It also happens for time kinds when the span of the hop is a multiple of 2^32 seconds (a no-op in the wrapping `UInt32` arithmetic) and the window start computed by `ToStartOfTransform` is after the time, e.g. local midnight 39600 in `US/Samoa` with `toIntervalDay(33554432)`. The loop terminates only if every iteration strictly decreases the end, so require exactly that and throw the existing `Time overflow` error otherwise. Subtracting a positive hop from a representable value always decreases it; the only other inputs affected returned a window that does not contain the time. Found by `FunctionsStress` in `Unit tests (asan_ubsan, function_prop_fuzzer)` on PR ClickHouse#118495, query `hopEnd(CAST('1970-01-01 01:02:07' AS DateTime), ...)` with the test image time zone `Europe/Amsterdam`, i.e. raw time 127. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
max_local_read_bandwidth_for_serverand the per-querymax_local_read_bandwidththrottled the bytes copied from the OS page cache exactly like the bytes that hit the disk. A query whose data is fully cached in RAM was slowed down to the configured disk bandwidth while producing almost no block device I/O, which makes the setting useless for the purpose it was introduced for (#48242, "do not let ClickHouse exceed what the underlying disk can deliver"): it has to be set at the disk bandwidth or above, and then it protects nothing, or below it, and then it penalizes cached reads that never touch the device.ThreadPoolReaderalready knows whether a read was served from the page cache - it triespreadv2withRWF_NOWAITfirst and hands the request off to the thread pool onEAGAIN. This reports that inIAsynchronousReader::Resultand skips the throttler for such reads, so the local read throttler now accounts only what was read from the device.Only the throttlers of
max_local_read_bandwidth_for_serverandmax_local_read_bandwidthare exempted. The throttlers ofmax_backup_bandwidth,max_merges_bandwidthandmax_mutations_bandwidthshare the same read path (they are combined intoReadSettings::local_throttler), but they limit the amount of work regardless of where the data came from, so they keep accounting such reads.This covers the default
local_filesystem_read_method = 'pread_threadpool'. The synchronouspread(also used for the files of the filesystem cache byCachedOnDiskReadBufferFromFileandDiskCacheProvider, regardless of the read method) does the same: when there is a throttler, it triespreadv2withRWF_NOWAITfirst and falls through topreadonEAGAIN; such reads are counted in the newReadBufferFromFileDescriptorPageCacheHitBytesprofile event. Thereadmethod cannot tell whether the data was cached, and reads withO_DIRECTalways reach the device, so both keep being accounted as before.Measured on a 177 MiB scan of a table that is fully in the page cache, with
max_local_read_bandwidth = 20000000(20 MB/s):QueryLocalReadThrottlerBytesQueryLocalReadThrottlerSleepMicrosecondsquery_duration_mspread_threadpool(before)pread_threadpool(after)pread_threadpool+O_DIRECT(unchanged)Closes: #118463
Related: #48242
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reads that are served from the OS page cache no longer consume the budget of the local read bandwidth throttler (
max_local_read_bandwidth_for_serverandmax_local_read_bandwidth), so a query over cached data is not slowed down to the configured disk bandwidth. This works with the defaultlocal_filesystem_read_method = 'pread_threadpool', withpread, and for the files of the filesystem cache; thereadmethod cannot detect cached reads and is accounted as before.Workflow [PR]
Sync PR [sync-upstream/pr/118495]
Version info
26.10.1.1875-master(included in26.10and later)