Batching lets a runtime process work from multiple inputs together or schedule active sequences continuously, which can improve hardware utilization and total throughput. It can also increase queue time, memory, tail latency, and failure impact. Optimize for successful work under a service objective, not the largest batch the GPU accepts.
Distinguish Batching Modes
Static/offline batching groups a known set of jobs. It suits nightly classification or embedding work where completion time matters more than per-item response.
Dynamic/continuous batching schedules tokens from requests that arrive at different times. It can improve online serving utilization, but runtime configuration and request length distribution determine the result.
Application micro-batching waits briefly to accumulate requests. The waiting window creates latency, so it needs a strict maximum and a fallback for low traffic.
Do not assume framework batch_size, number of parallel sequences, and user concurrency mean the same thing. Define each tool’s terms from its current documentation.
Build a Benchmark Grid
Use realistic short, median, and long prompt/output distributions. Test concurrency/batch settings such as 1, 2, 4, and 8 only while safe. Capture:
- requests and successful task items per second;
- TTFT and end-to-end p50/p95/p99;
- queue time, active/queued requests, timeouts, rejections;
- peak VRAM/RAM and cache use;
- output validity/quality and cancellation behavior;
- power, temperature, and recovery.
An apparent throughput gain that doubles p95 beyond the user requirement is not a win for interactive service. Conversely, a nightly batch can accept higher latency if it completes safely within its window.
Worked Example
A local support assistant at concurrency one uses only part of the GPU. Concurrency four increases throughput while p95 remains under the agreed target. Concurrency eight yields little additional throughput, consumes nearly all VRAM, and causes long requests to delay short ones.
The deployment uses four active sequences, a bounded queue, request token limits, and controlled overload response. It publishes the tested workload/configuration, not “supports eight users.”
Control Fairness and Overload
Limit input/output tokens, total active tokens, request duration, queue length, and per-client rate. Consider separating long batch jobs from interactive traffic. Support cancellation so abandoned streams stop consuming resources where the runtime allows.
Reject or defer excess work clearly instead of accepting an unbounded queue. Retries need backoff and jitter; automatic immediate retries can amplify overload. Multi-tenant systems require authentication and quotas before optimization.
Failure Cases
- Benchmarking identical short prompts when production varies.
- Reporting average latency only.
- Using an unbounded queue to hide rejection.
- Letting one long request block every short request.
- Increasing parallelism without KV-cache memory accounting.
- Retrying timeouts immediately and worsening load.
- Calling generated tokens/second successful business throughput.
🇵🇰 Pakistan Angle
A small office may have predictable staff usage and overnight workloads. Separate interactive requests from scheduled jobs so a large content batch does not block customer support. If power transitions are expected, checkpoint batch inputs and make jobs idempotent rather than rerunning unknown work.
Use synthetic requests in load tests and do not send client documents to a benchmark harness. State hardware, room/power conditions, and date when presenting capacity.
Hands-On Exercise
Create a grid across four concurrency/batch settings and three request-length classes. Run a staged authorized benchmark, sample output quality, and chart throughput versus p95 plus peak memory. Choose a setting with headroom, queue cap, overload response, token limits, and rollback.
Completion Rubric
- Complete: realistic distributions, tail latency, goodput, memory, quality, queueing, and overload controls determine the setting.
- Needs revision: throughput improves but long-request fairness, cancellation, or retry behavior is untested.
- Not complete: maximum accepted concurrency is presented as safe capacity without objectives or headroom.
Sources
- llama.cpp server: continuous batching and parallel serving
- vLLM serving benchmark CLI
- Ollama FAQ: parallel requests and queue controls
Key takeaway: Batching is successful when it raises valid completed work while keeping tail latency, memory, fairness, and overload inside policy.