Repository navigation
Conversation
A query that parked its CPU lease N times kept its slot for about N quanta of CPU without renewing it, so queries of other workloads waited for seconds (issue ClickHouse#126133). `parkLease` gave a not yet consumed slot back (it finished the oldest request early or cancelled the pending one) without touching `requested_ns`, and `unparkLease` -> `schedule` asked for a full quantum on top. The new request expired at the new, higher `requested_ns`, so every park/unpark cycle moved the expiry of the next slot one quantum further. Implement the proposal from the issue: a new request expires one quantum after the latest held slot (or after the current consumption when none is held), and costs only the part of that horizon the budget (`requested_ns - consumed_ns`) does not cover yet, down to 1 ns. The preemption check `consumed_ns >= requested_ns` is unchanged. Two park-side changes keep the budget exact: - a park still finishes the oldest request, but gives back the latest expiry, so the remaining slots keep the earliest ones; - the cost of a request cancelled before the scheduler processed it leaves `requested_ns`, because it was never granted. For a query that never parks, the expiry and the cost of every request are the same as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`test_parked_query_still_renews_cpu_slot` discarded every exception of query `a`. If `a` stopped early for another reason, its slot was free, query `b` waited only a few ms and the test passed without checking that the slot is renewed. Record the errors of `a`, require `a` to still be running when `b` finishes, and accept only the cancellation caused by the test's own `KILL QUERY`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; round 1: 2 findings, round 2 on the fix: 0) plus my own cold review (nits only).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261016-152000 |
|
Workflow [PR], commit [a0888fa] Summary: ❌
AI ReviewSummaryThe PR makes Final VerdictStatus: ✅ Approve |
CI finish ledger - 4f3abe1Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261017-083009 |
|
@groeneai please do more extensive performance testing against master and against master w/o cpu slot parking. Focus on use cases that you suspect can be impacted by parking you can also add the new performance test specifically for this corner case because it's quite important to make sure that scheduling-related stuff does not impact query performance as much as we can in any kind of load. Specifically, it's important for workloads with concurrent query execution, with mixed query types, and other things that look like a production workload and not just benchmarking. |
|
These tests can be done in a separate pull request if necessary. |
|
Acknowledged. I'm benchmarking this PR against master and against master with |
|
I benchmarked this PR (4f3abe1) against its master base (67e362e), each with
Loads 1-5 show no regression: throughput within 1%, per-query medians within 2%, interactive p99 unchanged. Load 6 is the corner case in a production shape: on master the short queries stall for up to 2.9 s behind parked credit; with the PR the worst is 0.32 s while the throttled queries keep the throughput parking gives them (24 per 40 s, vs 17-21 with parking off). One trap for anyone repeating this: most of the PR binary's page-cache pages first sat on another NUMA node than the server, which alone made it 10% slower on load 3, with parking off too. The runs above are after migrating both binaries' pages to the server's node. The CI performance tests run one query at a time, so they cannot reproduce load 6; the integration test in this PR covers it. I'll add a performance test for park-heavy single queries under a CPU workload (idle workers in a window step, throttled reads, Load 6 queriesThrottled reads use -- workload small_io, max_threads = 2
SELECT count() FROM numbers(200000000) WHERE cityHash64(number) NOT IN (SELECT cityHash64(URL) FROM hits WHERE CounterID BETWEEN 2000 AND 2100);
SELECT sum(cityHash64(URL)) FROM hits WHERE CounterID BETWEEN 2000 AND 2400;
-- workload small_cpu, max_threads = 2
SELECT count() FROM numbers(10000000) WHERE cityHash64(number) % 3 = 0;
SELECT sum(cityHash64(number)) FROM numbers(5000000);
SELECT * FROM hits WHERE CounterID = 42 ORDER BY EventTime DESC LIMIT 10; |
|
The performance test is in #126515. A correction to my earlier comment: a shell item can run a concurrent case, so the test includes one like load 6 (a CPU query sharing a slot with a sibling workload's query that parks), and this PR makes it 30% faster. A |
|
Dear @serxa, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
serxa
left a comment
There was a problem hiding this comment.
That is good enough. Lets resolve conflicts. Ping me when its ready to be merged
…t-aware-request-cost Resolve the conflict in CPULeaseAllocation.h: keep master's [[nodiscard]] on the RequestChain getters and add it to the two getters this branch adds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged master in 75415bd. The only conflict was master's |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 10 s compile time in total, 8 of them have a recent master baseline. |
…sNotExtendSlotLease `CPULeaseAllocation::release` computes the last consumption report from `CLOCK_THREAD_CPUTIME_ID` of the calling thread minus `last_report_ns`, which `startConsumption`/`renew` took on `master_thread`. The test destroyed the master lease on the gtest thread, so the report mixed two thread clocks: measured with gdb, it charged 374.5 ms of the gtest thread's CPU to the query (thread_time_ns 385594101 vs last_report_ns 11052820), and it would trip `chassert(thread_time_ns >= lease.last_report_ns)` if the gtest thread had used less CPU than `master_thread`. Reset `master_slot` inside the async task after its last renewal. The release then reports 1071 ns on the same clock. The later assertions are unaffected: `downscale` does not cancel the pending renewal and `effectiveMaxSlots` does not depend on the master lease. Mutation (drop the cancelled-cost undo in `parkLease`) and master's `CPULeaseAllocation` still fail the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…speed The merge queue dropped this PR after the test saw `parks = 0` (MergeQueueCI, `Integration tests (amd_binary, targeted)`, sha 59fd0a7). Query `a` read its set with O_DIRECT 4 KiB `pread`s, so the read throttler only sleeps (and parks the CPU lease) when the device serves those reads faster than `max_local_read_bandwidth` (1 MB/s, about 250 IOPS). On that runner the 740 reads took 6.65 s (DiskReadElapsedMicroseconds, OSReadBytes 3.03 MB) and ThrottlerSleepMicroseconds was 0. Without O_DIRECT, `pread` skips the block-device throttler for page cache hits, so the test switches to `local_filesystem_read_method = 'read'`, which throttles every read. The just-written part is read from the page cache and the throttler sleeps regardless of the device. Measured locally with the node container capped at 100 read IOPS on its data device while query `a` runs: the old settings give 0 parks (the CI failure), the new ones 491-492 parks with OSReadBytes 0. At 50 IOPS: 324-492 parks, pass 3/3. Uncapped: whole module 50/50. Master's CPULeaseAllocation still fails the test (b waits 4.36-4.69 s with 491 parks), so it still covers the bug. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test checked how long a slot lives after many parks, but not what each unpark asks the scheduler for. A `schedule` that kept the new expiry but charged a full quantum per request passed it, while `max_cpus` and fair scheduling would still bill a parking query one quantum per park. Count the requests and the cost the queue dequeues during the 20 zero-consumption park/unpark rounds: 20 requests, less than one quantum in total. With `cost = settings.quantum_ns` in `schedule` the test fails 3/3 on exactly this check (200000000 vs 10000000) and on nothing else; with the PR's `schedule` it passes 20/20, and `Scheduler*` passes 174/174. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The merge queue removed this PR because
It can be queued again once CI on a0888fa is green. |
CI finish ledger - a0888faEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261120-050026 |
Closes: #126133
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Implements the proposal from #126133. A query whose CPU lease parked N times kept its CPU slot for about N x
cpu_slot_quantum_nsof CPU, so other workloads waited seconds. A park gave a slot back unconsumed whilerequested_nskept its cost, and the unpark asked for a full quantum on top. Every request expired atrequested_ns, so each park/unpark moved the next expiry one quantum further.Now each
ResourceRequestis sized from the lease state:consumed_nswhen none is held), so the horizon is one quantum per acquired slot and a partially consumed slot is not paid twice;requested_ns - consumed_ns) does not cover yet, down to 1 ns.Preemption (
consumed_ns >= requested_ns) is unchanged. A park now gives back the latest expiry instead of the earliest, and a cancelled request's cost leavesrequested_ns, as it was never granted. A query that never parks gets the same costs and expiries. While threads stay parked, the budget they gave back is still credit for the running thread (at most one quantum per parked thread), but no longer holds a slot.Not for changelog: parking (#117711) is unreleased.
Validation: the issue's reproducer, added to
test_scheduler_cpu_parking, fails on master 6/6 (~490 parks, the other workload waits 4.6-4.8 s) and passes 50/50 with the fix (up to 31 ms). Its threshold is 2 s, not 0.5 s: with the fix that wait follows the other query's CPU time (~0.4 s on ASan). A gtest covers the multi-thread park and the cancel; it fails on master and with either park-side change reverted. Giving a slot back walks at mostallocatedrequests, ~130 ns per park at 256 slots. Existing scheduler tests pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126336]