L
Member
When a serving cluster gets busy, the first symptom is usually a long-tail TTFT: P50 barely moves, P99 doubles, tokens/s stays where it was. The intuitive fix is to lower max_num_batched_tokens or shrink the chunked-prefill budget so prefill "stops hogging the batch". For this symptom class that tuning frequently makes things worse, because the tail is not caused by prefill being too aggressive. It is caused by KV cache pressure forcing preemptions of running requests, and every preemption costs a recompute.
1. The mechanism
Under continuous batching, admission of a new request depends on free KV blocks, not on compute. When free blocks fall below the request's worst-case need, the scheduler either queues the request or preempts a running one. Recompute is the expensive path: the preempted request's prompt plus its already-generated prefix must be run again as a fresh prefill. Per-request cost therefore jumps by roughly prompt length plus generated tokens, and a request that was almost finished goes back to the queue.
Two consequences that look like unrelated bugs:
- Throughput stays flat or drops slightly, because part of the GPU work is now redundant.
- The TTFT tail appears in long-prompt buckets first, because long prompts need more blocks per request and are more likely to be queued or preempted.
If you only watch aggregate tokens/s and P50 TTFT, the cluster looks healthy while the tail grows.
2. Three measurements that separate preemption from compute saturation
a) Preemption rate per 1k requests, plus recomputed tokens per output token. If the recompute ratio climbs while GPU utilization is flat, preemption is the driver. A workable starting budget is 0.1–0.2 recomputed tokens per output token; above that the tail is structural, not scheduling noise.
b) TTFT bucketed by prompt length × concurrency, never aggregated. Preemption-driven tails show up as a knee that moves with prompt length; compute saturation shows up as a slope that moves uniformly with concurrency.
c) KV block occupancy: reserved-vs-used ratio (fragmentation), free-block low-water mark, and the sawtooth of allocation over time. If free blocks hit zero periodically while the running batch sits below max_num_seqs, admission is blocked by memory, not by the batch limit.
3. Checklist before touching chunk size
- Log preemption events with request id, prompt length, generated length at preemption, and recompute token count.
- Emit gauges: preemptions/s, recompute ratio, KV free-block low-water, waiting queue length, running batch size, SM occupancy.
- Run a fixed grid: prompt length in {short, medium, long} × concurrency in {1, 2, 4, 8} at fixed output length, with sampling parameters and max_new_tokens held constant.
- Only after the grid shows the preemption signature, change one knob at a time: max_num_seqs, then gpu_memory_utilization, then the chunked-prefill token budget. Re-run the same grid after each change.
- Acceptance: at target concurrency, P99 TTFT inside SLO, recompute ratio under budget, and no free-block zero crossing during steady state.
One more trap worth naming: raising gpu_memory_utilization to "get more blocks" can push the process into allocator retries and OOM-kill risk under burst load. Watch retry counts and reserved memory, not just the utilization number. If you have a preemption log and a length-bucketed TTFT plot, you can usually rule this in or out in one sweep, without changing any scheduling parameter.
1. The mechanism
Under continuous batching, admission of a new request depends on free KV blocks, not on compute. When free blocks fall below the request's worst-case need, the scheduler either queues the request or preempts a running one. Recompute is the expensive path: the preempted request's prompt plus its already-generated prefix must be run again as a fresh prefill. Per-request cost therefore jumps by roughly prompt length plus generated tokens, and a request that was almost finished goes back to the queue.
Two consequences that look like unrelated bugs:
- Throughput stays flat or drops slightly, because part of the GPU work is now redundant.
- The TTFT tail appears in long-prompt buckets first, because long prompts need more blocks per request and are more likely to be queued or preempted.
If you only watch aggregate tokens/s and P50 TTFT, the cluster looks healthy while the tail grows.
2. Three measurements that separate preemption from compute saturation
a) Preemption rate per 1k requests, plus recomputed tokens per output token. If the recompute ratio climbs while GPU utilization is flat, preemption is the driver. A workable starting budget is 0.1–0.2 recomputed tokens per output token; above that the tail is structural, not scheduling noise.
b) TTFT bucketed by prompt length × concurrency, never aggregated. Preemption-driven tails show up as a knee that moves with prompt length; compute saturation shows up as a slope that moves uniformly with concurrency.
c) KV block occupancy: reserved-vs-used ratio (fragmentation), free-block low-water mark, and the sawtooth of allocation over time. If free blocks hit zero periodically while the running batch sits below max_num_seqs, admission is blocked by memory, not by the batch limit.
3. Checklist before touching chunk size
- Log preemption events with request id, prompt length, generated length at preemption, and recompute token count.
- Emit gauges: preemptions/s, recompute ratio, KV free-block low-water, waiting queue length, running batch size, SM occupancy.
- Run a fixed grid: prompt length in {short, medium, long} × concurrency in {1, 2, 4, 8} at fixed output length, with sampling parameters and max_new_tokens held constant.
- Only after the grid shows the preemption signature, change one knob at a time: max_num_seqs, then gpu_memory_utilization, then the chunked-prefill token budget. Re-run the same grid after each change.
- Acceptance: at target concurrency, P99 TTFT inside SLO, recompute ratio under budget, and no free-block zero crossing during steady state.
One more trap worth naming: raising gpu_memory_utilization to "get more blocks" can push the process into allocator retries and OOM-kill risk under burst load. Watch retry counts and reserved memory, not just the utilization number. If you have a preemption log and a length-bucketed TTFT plot, you can usually rule this in or out in one sweep, without changing any scheduling parameter.