Repository navigation
Conversation
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 rounds, 2 findings) plus my own cold review.
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261017-164200 |
|
cc @serxa, could you review this? With |
|
Workflow [PR], commit [f0fa18a] Summary: ✅
AI ReviewSummaryThe PR returns CPU slots when every thread of a Final VerdictStatus: ✅ Approve |
CI finish ledger - ed9e688Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The only other Session id: cron:our-pr-ci-monitor:20261018-073006 |
|
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. |
|
@groeneai, let's update this PR. A few other fixes have been merged around the existing algorithm. Take a look to see if the problem is still there, and if so, how to fix it properly |
`effectiveMaxSlots()` is `current_max_slots - parked_count`, and `current_max_slots` is the executor's desired thread count. When the workload grants a query fewer slots than it wants (`max_concurrent_threads` below `max_threads`), parking all of its threads leaves `allocated` equal to `effectiveMaxSlots()`, so `parkLease` keeps every slot. With no running thread nothing reports consumption or spawns a thread, so the slots stay idle. A `remote()` query whose shard runs on the same server under the same workload then hangs: the coordinator waits for the shard, and the shard's thread waits in `renew` for a slot the coordinator holds. Make `effectiveMaxSlots()` zero while no thread is running or preempted and at least one is parked, so the last park gives back every held slot. A worker that times out in preemption while the others are parked enters the same state with a request still pending; `grantImpl` now returns a grant that arrives then (the surplus loop of `parkLease` is moved to `finishSurplusRequests` and called from both). This is the parking counterpart of ClickHouse#123640. Tests: a stateless test with a one-slot workload and a loopback `remote()` GROUP BY (times out at 60 s without the change), and a unit test for the late grant after a preemption timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A grant that arrives in any other state is kept, so a `setMax` shrink still does not reclaim granted slots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The result rows are the same without CPU scheduling, so the test also checks `ConcurrencyControlParks` of the query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove two comments that restate the code below them (the allParked() doc and the grantImpl give-back note). Co-Authored-By: Claude Opus 5.5 <[email protected]>
ed9e688 to
f0fa18a
Compare
|
I rebased this on master (now f0fa18a, the change itself is the same) and re-measured: the problem is still there.
Why the merged changes don't reach it: How to fix it: I think the allocation is the right layer, with the rule "keep a slot only while a thread of the query can use it now". A running thread can (it spawns a thread for a granted slot after its task), and so can a preempted one ( This conflicts with #126336 in the |
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, 15 s compile time in total, 8 of them have a recent master baseline. |
Related: #117711
Related: #123640
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a hang of a
remote()query whose shard runs on the same server in the same CPU workload when the workload'smax_concurrent_threadsis lower than the query'smax_threads. The coordinator's idle threads kept every CPU slot, so the shard never got one and the query ended only atmax_execution_time.Description
On 26.10.2.9, with
CREATE RESOURCE cpu (MASTER THREAD, WORKER THREAD)and a workloadw1withmax_concurrent_threads = 1,SELECT number % 10 AS k, count() FROM remote('127.0.0.2', numbers(20000000)) GROUP BY k SETTINGS workload = 'w1', max_threads = 2never finishes (5/5TIMEOUT_EXCEEDED). Master still hangs the same way withcpu_slot_parkingon.CPULeaseAllocation::effectiveMaxSlots()iscurrent_max_slots - parked_count, wherecurrent_max_slotsis the number of threads the query wants. When the query holds fewer slots than that and all its threads park,allocatedequalseffectiveMaxSlots(), soparkLeasegives nothing back. No thread runs, so nothing reports consumption or uses the slots, while the shard waits inrenewfor one of them.Now
effectiveMaxSlots()is 0 while no thread is running or preempted and at least one is parked, so the last park returns every slot.grantImplalso returns a grant that arrives in that state (a worker that timed out in preemption leaves a request pending), through the surplus loop ofparkLease, moved tofinishSurplusRequests. This is the parking counterpart of #123640.Tests: a stateless test (times out at 60 s before the change, 50/50 after) and a unit test for the late grant; each fails without its half of the change. A park-heavy local query in capped and wide workloads has the same median time before and after (177 vs 178 ms, 102 vs 103 ms). With
cpu_slot_parking = 0the query still hangs, as before;async_socket_for_remote = 0is fixed by #126524.This touches the same
parkLeaseloop as #126336; whichever lands second moves its body into the helper.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126512]