Notes

Continuous Batching

A GPU serving one request at a time is mostly idle — it is waiting on memory, not arithmetic. Batching requests together fixes that, but the obvious way to batch throws most of the gain away: requests finish at different lengths, and the whole batch waits for the slowest. Continuous batching stops the waiting.

How it works

Instead of scheduling whole requests, the server schedules each decoding step. After every token, finished sequences leave the batch and queued requests are admitted in their place, so the batch is reassembled continuously rather than once. A request needing 30 tokens is gone in 30 steps and does not hold a slot hostage to the 2,000-token essay beside it, and a request that arrives mid-flight joins the next step instead of waiting for the batch to drain. It was introduced as iteration-level scheduling in the Orca paper and is the default in vLLM, where it pairs with paged attention to stop the KV cache fragmenting as sequences come and go.

What it buys and what it costs
  • Throughput on mixed-length traffic rises severalfold against static batching on identical hardware — the headline reason to run a serving stack instead of a plain inference loop.
  • Time to first token drops, because a new request waits for the next step rather than the next batch.
  • The trade is predictability: your request shares the GPU with a changing crowd, so per-token latency moves with load, and an admission policy has to decide who gets preempted when the cache fills.

Continuous batching schedules LLM inference one decoding step at a time instead of one request at a time: finished sequences leave the batch after each token and waiting requests take their place immediately. This removes the idle slots static batching leaves when requests in a batch have very different output lengths, raising throughput several times over on mixed traffic. It is the default in serving stacks such as vLLM, paired with paged attention for KV-cache memory.

Imagine a checkout that serves eight customers at once, but will not let anyone new step up until all eight have finished. The person with two items waits for the one with a full trolley, and seven lanes stand empty while that trolley is scanned. Continuous batching is the fix: the moment a customer is done, the next one in the queue takes that spot. For an AI service answering thousands of questions, some needing a sentence and some needing an essay, this keeps the expensive hardware busy and gets you a reply sooner — the same machine serving far more people.