How LLM serving worksLesson 2 of 9
Reading the Question, Writing the Answer (Prefill and Decode)
The previous lesson showed that answers are built one token at a time. But the first step, reading the question, behaves very differently. Splitting a request into prefill, which computes the whole prompt at once, and decode, which writes one token at a time, explains why "time to the first word" and "gap between words" move independently.
Current phaseWaiting
Time to first token (TTFT)—
Time per token (TPOT)—
Main bottleneck—
RequestResponse / reportAppears in a later step
What you will learn
- Prefill computes the whole prompt at once
- TTFT is decided during prefill
- Decode is limited by memory reads, not compute
- Mixing both phases on one accelerator causes interference
Running it on Kubernetes
- vLLM exposes a TTFT histogram (
vllm:time_to_first_token_seconds) and per-token latency histograms on/metrics: per-request TPOT (vllm:request_time_per_output_token_seconds) and the gap between streamed tokens (vllm:inter_token_latency_seconds). Look at p95 and p99 rather than the mean, and alert on TTFT and TPOT separately. - If only TTFT got worse, inputs usually got longer or the queue grew; check waiting requests (
vllm:num_requests_waiting) alongside it. If only TPOT got worse, suspect more concurrent decoding or long prefills cutting in. - Decode is bound by memory bandwidth, so a high GPU utilization reading can still leave plenty of compute headroom. Do not size replicas on utilization alone.
- Give models with very different workloads their own replicas, and run load tests with realistic input and output length distributions. Testing with short prompts only hides the prefill cost.
- Splitting prefill and decode across separate Pods is covered in Splitting Prefill and Decode (P/D Disaggregation).
Try it yourself
curl -s http://<engine>:8000/metrics | grep vllm:time_to_first_token_seconds # TTFT histogram: prefill (step 4), e.g. vLLM
curl -s http://<engine>:8000/metrics | grep vllm:request_time_per_output_token_seconds # Per-request TPOT: decode (step 6)
curl -s http://<engine>:8000/metrics | grep vllm:inter_token_latency_seconds # Gap between streamed tokens
curl -s http://<engine>:8000/metrics | grep vllm:num_requests_waiting # Queue behind a TTFT rise
Check yourself
Further reading: vLLM documentation · llm-d