Repository navigation
Conversation
With `async_socket_for_remote = 0`, `RemoteSource` blocks inside `RemoteQueryExecutor::read` -> `connections->receivePacket()` while the shard computes. Nothing parked the thread's CPU lease there (the async path waits in `PollingQueue`, which parks), so the initiator kept its CPU slot. When the shard runs on the same server in the same CPU workload and the initiator holds every slot of that workload, the shard waits in `CPULeaseAllocation::renew` for that slot forever, and the query ends only at `max_execution_time` (or `receive_timeout`). Put only the `receivePacket` call in a `CPULeaseParkGuard`. At that point no `RemoteQueryExecutor` or connection mutex is held (`was_cancelled_mutex` is released just above, `cancel_mutex` is taken inside `receivePacket`), so park/unpark add no lock-order edge. The `finish()` drain and the synchronous `sendQuery` run under `was_cancelled_mutex` and stay unparked: parking under it closes a cycle with `ExecutorTasks::mutex` (via `processParallelReplicaPacketIfAny`) and the lease mutex (via `on_resume`). The guard also covers decoding the packet inside `receivePacket`, so a workload can briefly run one thread per synchronous remote source above its limit, the over-subscription that ClickHouse#117711 already documents. 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; 2 findings) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261017-192900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261017-184100 |
|
cc @serxa, could you review this? With |
|
Workflow [PR], commit [88c505f] Summary: ❌
AI ReviewSummaryThe PR parks the CPU lease around synchronous Findings
Tests
Final VerdictStatus: Merge the CPU-budget accounting correction and verify CPU-limit enforcement after repeated synchronous packet reads before landing this change. |
| Packet packet; | ||
| { | ||
| /// Non-CPU wait for the remote side: park the CPU lease while blocked | ||
| CPULeaseParkGuard cpu_park; |
There was a problem hiding this comment.
This adds a park/unpark pair for every received packet, but the current CPULeaseAllocation::parkLease leaves returned/cancelled quanta in requested_ns, and unparkLease adds another quantum. A stream of packets therefore accumulates CPU credit that survives into subsequent CPU-only work, preventing renew from enforcing workload limits.
I reproduced this with the PR's Fast Test binary, a resource covering MASTER THREAD and WORKER THREAD, and workload settings max_concurrent_threads = 8, max_cpus = 0.1, max_burst_cpu_seconds = 0.01:
SELECT count()
FROM numbers(30000000)
WHERE cityHash64(number) NOT IN
(SELECT cityHash64(number)
FROM remote('127.0.0.2:19845', numbers(500000)))
SETTINGS workload = 'review_wl', max_threads = 1, max_block_size = 1000,
async_socket_for_remote = 0, async_query_sending_for_remote = 0,
use_hedged_requests = 0, use_concurrency_control = 1;With parking enabled, the initiator parks 507 times, consumes 2.248 CPU seconds in 2.258 elapsed seconds, and never preempts; the scheduler charges only 30 ms. Disabling parking gives 23.722 elapsed seconds and 207 preemptions, respecting max_cpus = 0.1. The excess credit thus bypasses CPU limits after the remote set has been built and can also delay competing workloads.
Please land the budget-accounting correction before this new park site and add coverage for CPU renewal after the synchronous read.
Related: #126133
Related: #126336
There was a problem hiding this comment.
Agreed on the mechanism, but the extra credit comes from parkLease keeping requested_ns (#126133), and #126336 fixes it there: with #126336 applied your query keeps the limit (debug build: 69-72 preemptions, 7.8-8.1 s, vs 0 and 0.72 s without it). The description states that this PR needs #126336 to land first, and the renewal-after-park coverage is in #126336 (ParkingDoesNotExtendSlotLease, test_parked_query_still_renews_cpu_slot).
…-remote-read # Conflicts: # src/QueryPipeline/RemoteQueryExecutor.cpp
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
…-remote-read # Conflicts: # src/QueryPipeline/RemoteQueryExecutor.cpp
Related: #117711
Related: #126512
Related: #126336
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 withasync_socket_for_remote = 0whose shard runs on the same server in the same CPU workload. The thread waiting for the shard's data kept its 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 = 1, async_socket_for_remote = 0never finishes (3/3TIMEOUT_EXCEEDED). Master hangs the same way, hedged or not, also for a two-replicaparallel_replicas_mode = 'sampling_key'read.#117711 parks the CPU lease while the asynchronous remote read waits in
PollingQueue, and lists the synchronous path as not covered. There,RemoteSourceblocks inRemoteQueryExecutor::read->connections->receivePacket()with the lease running, so it keeps the slot while the shard on the same server waits for it inCPULeaseAllocation::renew.Now only that call runs in a
CPULeaseParkGuard. NoRemoteQueryExecutoror connection mutex is held there, so parking adds no lock-order edge; thefinish()drain and the synchronoussendQueryholdwas_cancelled_mutexand stay unparked. The guard also covers the call's CPU work (decoding; on a hedged failover, resending external tables), so a workload can run one thread per synchronous remote source above its limit, the over-subscription #117711 already documents.A synchronous read of several shards asks for one slot per source, so it also needs #126512: two shards hang with either PR alone and finish with both.
It also needs #126336 first: parks keep their returned quanta in
requested_nsand unparks request new ones (#126133), and this site parks once per packet, somax_cpusstops applying after the read (debug build, 1 thread,max_cpus = 0.1: 0.72 s, 0 preemptions; master 7.5 s, 66; with #126336 8 s, 70).Tests: a stateless test (times out at 60 s before, 50/50 randomized runs after). Parks equal unparks on the initiator. A 300M-row synchronous remote read keeps its median time (5392/5417/5398 vs 5400/5390/5405 ms: no workload, 8-slot workload non-hedged and hedged).
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126524]