Continuous Batching in LLM Serving: How Throughput Scales
Continuous batching (also called in-flight batching) is the technique that made modern LLM serving scalable. Without it, serving 10 concurrent users requires 10x the GPU capacity of 1 user. With continuous batching, GPU utilization becomes near-100% regardless of user count. Understanding it helps you choose and configure serving infrastructure.
The Problem: Static Batching Waste
In naive static batching, requests are grouped before inference starts. If user A's request completes at step 50 while user B's continues to step 200, the GPU is idle for user A's "slot" from step 50-200. At high concurrency, most GPU cycles are wasted waiting for slow requests to complete before the batch can be refilled. Real-world GPU utilization with static batching is often 20-40%.
Continuous Batching Solution
Continuous batching inserts new requests into the batch as soon as a slot frees up — mid-generation. When user A's request completes, user C's request immediately takes the slot. The GPU is always running at maximum batch size, with finished requests cycling out and new ones cycling in dynamically. GPU utilization jumps to 80-95% at sufficient load. This is what powers OpenAI's API serving hundreds of thousands of concurrent users on a fixed hardware cluster.
Implementation in Local Serving
vLLM and TGI both implement continuous batching by default. llama.cpp server uses --cont-batching to enable it. The key configuration: set --parallel N (llama.cpp) or --max-num-seqs N (vLLM) to the maximum number of concurrent requests you want to support. Higher values improve throughput at the cost of slightly higher per-request latency. For a 4-person team, 4-8 concurrent slots is typical; for a 20-person team, 16-32.
Comments
Post a Comment