Repository navigation
Conversation
…ckHouse#118550) - Pipeline in-flight CPU lease requests (up to K=4) during ramp-up and ceiling increases to eliminate serialized single-request round trips. - Add OpenTelemetry spans (CPU_LEASE_REQUEST, CPU_LEASE_REQUEST_FINISH) with queue wait timestamps, sequence IDs, and slot types. - Increment ProfileEvents::ConcurrencyControlSlotsAcquiredNonCompeting when noncompeting slots are acquired in CPULeaseAllocation. Fixes ClickHouse#118550.
|
Workflow [PR], commit [846a83e] Summary: ❌
|
| // This code runs in the scheduler thread, so we have to keep it fast and simple | ||
| std::unique_lock lock{mutex}; | ||
| requests.scheduled(); | ||
| requests.recordGrantTime(); |
There was a problem hiding this comment.
This assumes the callback always belongs to next_grant, but CPULeaseAllocation explicitly supports different master_link and worker_link resources (PipelineExecutor mode 3 / the documented master_cpu + worker_cpu setup). Those are different scheduler queues and can execute out of order. Request::execute still only calls lease->grant() and does not identify itself, so if a worker request fires before the older master request, this code advances the wrong node. After that free()/cancel() can call cancelRequest(&*next_grant) on the wrong queue; FifoQueue::cancelRequest explicitly says cross-queue cancellation corrupts the intrusive list. Please thread the Request * through grant/failed (or keep separate in-flight state per queue) before allowing more than one request in flight.
|
📊 Cloud Performance Report 🔴 AI verdict: Q1 on tpch_adapted_1_official shows +26.0% (median 50→63 ms), confirmed by both tests, with CPU time rising 110→178 ms. This PR rewrites the CPU-lease concurrency-control scheduler (CPULeaseAllocation), moving from a single enqueued request to up to 4 in-flight requests plus added grant-time bookkeeping and tracing hooks — all on the per-query execution path, so a regression here is plausible rather than off-target. That said, this query is intrinsically noisy and it is a very short query where scheduler overhead is proportionally largest, so the +13 ms delta warrants a confirmation run before treating it as a firm regression. clickbench🟢 No significant changes tpch_adapted_1_official🔴 1 regressed Flagged queries (1 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
…ouse#120614) - Pass concrete Request* through execute() and failed() to identify the granted request. - Add RequestState enum to manage circular buffer states (FREE, INFLIGHT, GRANTED, FAILED, CONSUMING). - Buffer out-of-order grants and process them in-order from next_grant to maintain FIFO consumption. - Fix RequestChain::cancel() to target INFLIGHT requests on their matching queue, avoiding intrusive list corruption in FifoQueue. - Process buffered grants in free() before teardown to prevent scheduler constraint leaks. - Add regression unit tests in gtest_workload_resource_manager and integration test in test_scheduler_cpu_preemptive.
Closes: #118550
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce per-query CPU-slot acquisition latency under concurrency by pipelining in-flight resource requests in
CPULeaseAllocation, add OpenTelemetry tracing forResourceRequestlifecycle, and trackConcurrencyControlSlotsAcquiredNonCompetingevents.Detailed Description
1. Background & Problem
When running multi-threaded queries under concurrency with the Workload Resource Manager (
cpu_slot_preemptionenabled), queries previously experienced high CPU-slot acquisition latency during initial ramp-up.Upon investigation,$N$ CPU execution slots required $N$ sequential round-trips through the scheduler thread:
CPULeaseAllocationserialized resource requests through a strict 0-or-1 in-flight constraint (bool enqueued = false;inRequestChain). AcquiringUnder high query concurrency, this sequential "ping-pong" caused significant latency simply allocating threads for pipeline execution.
Additionally:
ResourceRequestqueue wait and grant durations lacked OpenTelemetry tracing.ProfileEvents::ConcurrencyControlSlotsAcquiredNonCompetingwas never incremented forCPULeaseAllocation, leaving the event counter at0.2. Key Changes
Pipelined In-Flight Requests (
RequestChainRefactoring):enqueuedfrom abooltosize_t enqueued_countbounded bystatic constexpr size_t max_inflight_requests = 4;.headiterator intonext_enqueueandnext_grantto manage a 3-region cyclic buffer:[tail, next_grant): Granted / actively consuming slots[next_grant, next_enqueue): In-flight requests pending in scheduler queues[next_enqueue, tail): Free buffer slotssetMax()to pipeline up tocurrent_max_slotsis reached.cancel()drains all pending in-flight requests cleanly).OpenTelemetry Request Lifecycle Tracing:
enqueue_time_ns,grant_time_ns, andrequest_seqtoRequest.CPU_LEASE_REQUESTspan upon grant with attributes:workload,lease_id,request_seq,is_master,is_noncompeting, andwait_queue_us(microseconds spent waiting in queue).CPU_LEASE_REQUEST_FINISHspan inRequestChain::finish()when quantum consumption completes.Non-Competing Profile Event Accounting:
noncompeting_grantedtracking inCPULeaseAllocation.ProfileEvents::ConcurrencyControlSlotsAcquiredNonCompetinginsideacquireImpl()when acquiring non-competing slots, matchingCPUSlotsAllocationandConcurrencyControl.Verification & Testing
enqueue,grant,finish,renew,setMax, andcancel.allocated + enqueued_count <= current_max_slots <= max_threadsholds in all branches.settings.trace_cpu_schedulingis false.Workflow [PR]
Sync PR [sync-upstream/pr/120614]