keepcalculator

06 Numbers and Powers

Batching vs Continuous Batching for LLM Inference

Card No. 06·50279 · Updated · Standard formula, shown below

Use ordinary batching when requests arrive together, workloads are predictable, and simplicity matters; use continuous batching for an online LLM service where requests arrive and finish at different times. Continuous batching can keep accelerator hardware busier by admitting new requests as others complete, but it adds scheduling complexity and does not guarantee lower latency for every request.

What batching means in LLM inference

LLM inference typically has two phases. During prefill, the model processes the prompt tokens; during decode, it generates output tokens step by step. A request’s prompt and output lengths vary, so requests in the same group may not need the GPU for the same amount of time.

With static, or conventional, batching, a serving system groups a set of requests and runs them together. In a simple implementation, the batch proceeds through generation steps until its requests finish or reach a configured limit. Requests that finish early may leave unused capacity while longer requests continue. Some systems handle finished sequences more flexibly, so the exact behavior depends on the serving engine.

Batching is not the same as sending one enormous prompt. It is a way to process multiple independent requests together, sharing work across the model’s compute operations. Nor does a larger batch automatically mean higher throughput: memory use, sequence lengths, model size, and hardware all constrain a useful batch.

How continuous batching works

Continuous batching, also called iteration-level or dynamic batching in some systems, makes scheduling decisions between generation steps rather than treating the entire batch as a fixed group. When one sequence completes, the scheduler can add a waiting request to the active set, subject to available compute and memory.

For example, suppose a service is generating answers for four users. One answer finishes after a few tokens while the other three need longer responses. A static batch may have to wait for the remaining work before that batch slot is fully reused. A continuous scheduler can place another waiting request into available capacity without waiting for all three long answers to finish.

Continuous batching is distinct from merely collecting requests for a short time before starting a batch. That collection is often called request batching or dynamic batching at the request level. Continuous batching concerns how active sequences are scheduled during generation, though real serving systems may combine both approaches.

When ordinary batching is the better choice

Choose conventional batching when requests can be collected in advance or processed in predictable groups. It is often a good fit for offline workloads such as embedding a fixed dataset, evaluating a model, or generating a planned set of reports. In these cases, maximizing aggregate processing efficiency can matter more than responding immediately to each arrival.

  • Small or steady workloads: A simple batch may be sufficient when traffic is low, request lengths are similar, or hardware is not heavily loaded.
  • Reproducible processing: Fixed groups can make throughput measurement and job orchestration easier to reason about.
  • Operational simplicity: A fixed-batch setup may require fewer scheduling and tuning decisions, depending on the inference software.
  • Latency is not interactive: If users do not wait for each answer, waiting to form a batch may be acceptable.

For example, a nightly job that runs the same model over 50,000 short text records can submit work in batches and prioritize total completion time. If records have widely varying lengths, however, grouping similar lengths may reduce wasted capacity even in a conventional setup.

When continuous batching is the better choice

Continuous batching is usually worth considering for a live service with concurrent users and variable arrival times or output lengths. It can replace completed sequences promptly, improving utilization and potentially increasing throughput under load. It is especially useful when a server must keep accepting work rather than wait for a fixed batch to end.

  • Interactive chat or completion APIs: Requests arrive throughout the day and users expect responses without waiting for a large group to form.
  • Uneven output lengths: Some generations finish quickly while others continue for many decode steps.
  • Substantial concurrency: There are enough active or waiting requests to refill capacity as sequences finish.
  • Latency and throughput both matter: A scheduler can balance prompt admission, ongoing generation, and queueing rather than optimizing only a fixed group.

It is not automatically the right answer for a lightly used endpoint. If there are few concurrent requests, there may be no waiting sequence to admit when a slot opens. The scheduling machinery can then add complexity without a meaningful utilization gain.

Latency, throughput, and memory trade-offs

Throughput measures work completed over time, often tokens per second or requests per second. Latency measures how long an individual request takes, and may include time to first token and time to finish. These measures can move in different directions: serving more requests concurrently may improve total throughput while increasing queueing or delaying a particular request.

Continuous batching does not remove the cost of generating tokens. Nor does it ensure that every request starts immediately. A system still needs admission control, queue limits, and scheduling policies. If it admits too many sequences, memory pressure can reduce the available space for key-value (KV) cache, which stores attention data needed during generation. The result may be slower execution, rejected work, or reduced concurrency.

Prompt length and output length matter. Long prompts consume substantial prefill work, while long generations occupy decode capacity for more steps. Mixing both freely can make performance less predictable. Serving systems may use limits, priorities, length-aware scheduling, or separate pools to manage that variation.

Common misconceptions and practical selection

A common misconception is that continuous batching always makes a single answer faster. Its main advantage is often better use of shared capacity and higher aggregate service efficiency, not a guaranteed reduction in each request’s latency. A request can still wait behind other work, and its generation speed depends on model, hardware, workload, and scheduler settings.

Another misconception is that “batch size” alone describes capacity. For LLM serving, the number of active sequences is only part of the picture; token lengths, KV-cache allocation, prefill/decode balance, and memory limits matter too. Compare systems with the same model, hardware, prompt and output distributions, concurrency, and latency targets.

To choose, start with a representative workload and measure:

  1. Request arrival rate, concurrency, and prompt/output length distributions.
  2. Time to first token, end-to-end latency percentiles, and tokens per second.
  3. GPU utilization and memory use, including how often requests queue or are refused.
  4. Behavior during bursts and long generations, not only average traffic.

If the workload is an offline job with predictable inputs, begin with ordinary batching. If it is a concurrent, interactive service with irregular arrivals and generation lengths, test continuous batching. Keep the simpler option if measurements show no useful improvement; the best choice is workload- and implementation-specific.

Frequently Asked Questions

Is continuous batching the same as dynamic batching?
Not always. Dynamic batching can mean waiting briefly to group newly arrived requests. Continuous batching usually means adjusting the active generation batch between decoding iterations. Terminology varies by serving framework, so check what its documentation means.

Does continuous batching reduce time to first token?
Not necessarily. It can improve overall utilization, but queueing and prefill scheduling still affect when a request produces its first token. Measure time to first token under realistic load.

Can continuous batching improve tokens per second?
It can increase aggregate throughput when it keeps otherwise idle capacity occupied. The result depends on hardware, model, request mix, memory limits, and scheduler behavior.

Is a larger batch always faster?
No. Larger batches may improve hardware utilization up to a point, but they also consume memory and can increase contention or latency. Maximum practical batch capacity is not the same as the best operating point.

Which approach should a small LLM deployment use?
Start with the serving mode that is simplest and supported by the chosen inference stack. Use a representative test to determine whether concurrency and uneven request lengths justify continuous scheduling.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →