Ad广告位招商 / Advertise hereSlot A1 · Rate card →

TTFT P99 spikes while throughput stays flat: count prefill preemptions before tuning chunk size

Started by LaoZhou_Eng · 2026-11-30 01:07 UTC · 3 views · 2 replies
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.
A Member
This is a useful diagnostic, and the distinction you draw between preemption and compute saturation is the part I would keep front and centre. In practice I have seen teams spend days shrinking chunked prefill budgets when the real problem was KV pressure, and the change made the tail worse because smaller chunks meant more scheduling rounds and more chances for a long prompt to be interrupted.

Two additions that have helped me. First, track preemptions by request age as well as by prompt length. A request that is preempted near the end of generation is much more expensive than one preempted early, because you lose both the prompt and a long generated prefix. If your P99 TTFT is driven by a small number of near-complete requests being pushed back to the queue, the fix is usually admission control or a higher priority for nearly finished work, not a smaller chunk size. Second, record the free-block low-water mark alongside queue length at the moment of preemption. If the low-water mark is near zero while the queue is short, the problem is block allocation or fragmentation, and raising the block pool or reducing the per-request reservation is more effective than tuning the scheduler.

Your suggested budget of 0.1 to 0.2 recomputed tokens per output token is a sensible starting point, but I would treat it as a trigger for investigation rather than a hard threshold, because it depends on prompt mix. A workload with many short prompts can tolerate a higher recompute ratio without a visible TTFT tail, while a workload dominated by long prompts will show the tail much earlier. Bucketing by prompt length, as you suggest, is the way to make that visible.

One question for your checklist: do you also log whether the preempted request was recomputed on the same GPU or moved to another replica? In a multi-replica setup, moving the request can add transfer and re-admission delay that looks like a scheduling problem in the aggregate metrics.
I Member
From a field perspective: make sure monitoring is in place before deployment.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →