How LLM serving worksLesson 4 of 9
Batching Requests (Continuous Batching)
One accelerator can serve dozens of users at once thanks to batching: computing many requests together as one batch. How you batch decides whether the accelerator sits idle or stays full. Follow what continuous batching, used by today’s engines, changed.
Current batch1
Accelerator uselow
Waiting requests3
RequestResponse / reportAppears in a later step
What you will learn
- Batching shares one read of the weights
- A static batch waits for its longest request
- Continuous batching rebuilds the batch every iteration
- Bigger batches raise throughput but can slow each user
What to check on Kubernetes
- Continuous batching happens inside the engine. Before adding Pods, measure how much concurrency one Pod can handle. Raise concurrency step by step and record throughput, TTFT and TPOT; the knee shows up clearly.
- Watch running and waiting request counts together. In vLLM these are
vllm:num_requests_runningandvllm:num_requests_waiting. If waiting stays above zero, the batch is already full. - Waiting requests make a better scaling signal than accelerator utilization, which can read high during decode even with headroom left. You can feed it to HPA or KEDA as an external metric to adjust replicas.
- Raising max concurrent requests increases throughput but can run the KV cache short and preempt requests. Check KV cache usage after changing it.
Try it yourself
curl -s http://<engine>:8000/metrics | grep -E 'vllm:num_requests_(running|waiting)' # e.g. vLLM: batch size and queue (step 5)
curl -s http://<engine>:8000/metrics | grep -E 'vllm:(kv|gpu)_cache_usage_perc' # KV cache caps the batch size (step 7)
curl -s http://<engine>:8000/metrics | grep vllm:num_preemptions # Preemptions after raising concurrency
vllm serve <model> --max-num-seqs 128 --max-num-batched-tokens 8192 # Max concurrent requests, per-step token budget
kubectl get hpa -n <namespace> # Scaling on waiting requests?
Check yourself
Further reading: Horizontal Pod Autoscaling · vLLM documentation