L
Member
Most "p99 ITL is bad, p50 is fine" reports on continuous-batching servers come down to one structural fact: prefill tokens and decode tokens are spending from the same per-iteration token budget. Once you see it that way, the tuning stops being guesswork.
**Why the spike exists**
In continuous batching the scheduler builds each iteration under a token budget (vLLM calls it `max_num_batched_tokens`). Prefill chunks and decode steps compete for that budget. A long prompt chunk can eat the whole budget, so that iteration contains zero decode tokens for every other sequence in the batch — those sequences simply do not advance. ITL is measured per generated token, so the pause shows up as an ITL spike for every co-batched request. It is not a bug; it is bursty prefill.
Four things make it worse:
1. Prefill attention is quadratic in prompt length, so a chunk of N tokens is far more expensive than a decode step of N tokens. Tuning by token count alone hides this.
2. Arrival pattern. A burst of mixed-length prompts means the chunk size chosen "in tokens" produces wildly different step latency depending on what else is in the batch.
3. KV growth. Decode cost scales with context length and batch size, so long-context requests get slower per token even with no prefill present.
4. One knob, two currencies. Prefill budget and decode budget are different resources; using a single number to tune both gives you a good p50 and a bad p99.
**Diagnose before you tune**
- Tag every scheduler step as prefill-bearing or decode-only, then split the ITL distribution by tag. If p99 ITL comes only from steps that carried a prefill chunk, you have your answer. If not, look at KV pressure and preemption instead.
- Sweep chunk size at a fixed arrival pattern (256 / 512 / 1024 / 2048 tokens) and plot p99 ITL against total prefill throughput. There is a knee: throughput flattening while ITL keeps climbing. Configure just below the knee.
- Check prefill token share per step: prefill tokens / budget. If one request routinely takes the large majority of the budget, chunking is not really in effect.
**Fixes that actually move the number**
- Chunked prefill sized from the decode protection you need, not from hardware FLOPs: chunk ≈ budget − (decode tokens required to keep ITL under target).
- Separate prefill and decode scheduling, with decode priority and prefill filling the remainder. This decouples p99 ITL from prompt arrival bursts.
- Admission control: cap prompt length per pool, or route long prompts to a separate pool with a looser SLO. Mixing 1k and 32k prompts in one pool guarantees a bimodal latency profile no amount of chunk tuning fixes.
- Bound batch size by KV memory as well as tokens. Near the KV limit the scheduler preempts and recomputes, and recompute spikes look exactly like prefill spikes in the latency trace.
**Verification checklist**
1. Per-step prefill/decode tagging, ITL split reported.
2. `max_num_batched_tokens` pinned and documented; chunk size in config rather than default.
3. Separate prefill/decode scheduling verified with an arrival-burst test, not a steady-state one.
4. Long-prompt routing rule written down, with its own SLO.
5. KV budget and token budget tracked separately; preemption/recompute count monitored.
6. Scenario matrix: single long prompt, burst of short prompts, mixed 1:32 lengths, steady state at target QPS.
7. p50/p99/p99.9 ITL, throughput, and the fraction of steps carrying prefill in one table.
8. Regression gate: when p95 prompt length doubles, p99 ITL must not degrade beyond the agreed margin.
**Why the spike exists**
In continuous batching the scheduler builds each iteration under a token budget (vLLM calls it `max_num_batched_tokens`). Prefill chunks and decode steps compete for that budget. A long prompt chunk can eat the whole budget, so that iteration contains zero decode tokens for every other sequence in the batch — those sequences simply do not advance. ITL is measured per generated token, so the pause shows up as an ITL spike for every co-batched request. It is not a bug; it is bursty prefill.
Four things make it worse:
1. Prefill attention is quadratic in prompt length, so a chunk of N tokens is far more expensive than a decode step of N tokens. Tuning by token count alone hides this.
2. Arrival pattern. A burst of mixed-length prompts means the chunk size chosen "in tokens" produces wildly different step latency depending on what else is in the batch.
3. KV growth. Decode cost scales with context length and batch size, so long-context requests get slower per token even with no prefill present.
4. One knob, two currencies. Prefill budget and decode budget are different resources; using a single number to tune both gives you a good p50 and a bad p99.
**Diagnose before you tune**
- Tag every scheduler step as prefill-bearing or decode-only, then split the ITL distribution by tag. If p99 ITL comes only from steps that carried a prefill chunk, you have your answer. If not, look at KV pressure and preemption instead.
- Sweep chunk size at a fixed arrival pattern (256 / 512 / 1024 / 2048 tokens) and plot p99 ITL against total prefill throughput. There is a knee: throughput flattening while ITL keeps climbing. Configure just below the knee.
- Check prefill token share per step: prefill tokens / budget. If one request routinely takes the large majority of the budget, chunking is not really in effect.
**Fixes that actually move the number**
- Chunked prefill sized from the decode protection you need, not from hardware FLOPs: chunk ≈ budget − (decode tokens required to keep ITL under target).
- Separate prefill and decode scheduling, with decode priority and prefill filling the remainder. This decouples p99 ITL from prompt arrival bursts.
- Admission control: cap prompt length per pool, or route long prompts to a separate pool with a looser SLO. Mixing 1k and 32k prompts in one pool guarantees a bimodal latency profile no amount of chunk tuning fixes.
- Bound batch size by KV memory as well as tokens. Near the KV limit the scheduler preempts and recomputes, and recompute spikes look exactly like prefill spikes in the latency trace.
**Verification checklist**
1. Per-step prefill/decode tagging, ITL split reported.
2. `max_num_batched_tokens` pinned and documented; chunk size in config rather than default.
3. Separate prefill/decode scheduling verified with an arrival-burst test, not a steady-state one.
4. Long-prompt routing rule written down, with its own SLO.
5. KV budget and token budget tracked separately; preemption/recompute count monitored.
6. Scenario matrix: single long prompt, burst of short prompts, mixed 1:32 lengths, steady state at target QPS.
7. p50/p99/p99.9 ITL, throughput, and the fraction of steps carrying prefill in one table.
8. Regression gate: when p95 prompt length doubles, p99 ITL must not degrade beyond the agreed margin.