Sub topic 6
Choosing Max Batch Size and Max Queue Delay
Assume you understand HTTP or gRPC model endpoints, p50 and p99 latency, Python, YAML, and Kubernetes Deployments. This chapter focuses on server-side dynamic batching. Dynamic batching is a server technique that briefly holds incoming requests and sends several together to the model.
The two controls
The maximum batch size limits how many requests the server sends in one model call. A larger batch can improve accelerator utilization and throughput, but it may use more memory and take longer to process.
The maximum queue delay limits how long the first request in a forming batch waits for additional requests. A longer delay can create fuller batches. It also adds waiting time, especially when traffic is light.
The server usually sends a batch when either condition occurs:
- The batch reaches the maximum batch size.
- The oldest request reaches the maximum queue delay.
Choose from the latency objective
Measure end-to-end latency, not only model execution time. End-to-end latency includes network time, queue time, preprocessing, model execution, and response handling.
For a latency objective, reserve some of the budget for queueing. For example, if the p99 target is 200 ms and other work consumes about 150 ms, a 10 ms queue delay may be reasonable. A 100 ms delay is risky because it can consume most of the remaining budget before inference starts.
Tail latency matters more than the average for user-facing services. A setting that improves average throughput but causes p99 latency to exceed the service-level objective (SLO) is usually unacceptable.
Tune the parameters
Start with a conservative maximum batch size supported by your model server and GPU memory. Then increase it while measuring throughput, memory use, and p50 and p99 latency.
Use a short queue delay when traffic is unpredictable or latency-sensitive. Use a longer delay when requests arrive steadily and throughput matters more.
For example, this Triton configuration allows batches up to 32 requests and waits at most 5 milliseconds to form a preferred batch:
max_batch_size: 32
dynamic_batching {
preferred_batch_size: [ 8, 16 ]
max_queue_delay_microseconds: 5000
}Preferred sizes encourage efficient batches, but the server can still send a smaller batch when the delay expires. The best values depend on model execution time, request rate, input sizes, and accelerator memory.
| Setting | Increase it when | Main risk |
|---|---|---|
| Maximum batch size | The accelerator has spare capacity and memory | Higher execution time or out-of-memory errors |
| Maximum queue delay | Traffic is steady and throughput is too low | Higher request latency and worse p99 |
A practical tuning loop
- Establish a baseline with batching disabled or with a small batch.
- Load-test at several request rates, including peak traffic.
- Increase the batch size and observe throughput, memory, and tail latency.
- Adjust queue delay in small steps, such as 1 to 5 milliseconds.
- Keep the configuration only if it meets the p99 objective at the required throughput.
- Repeat after changing the model, hardware, input shape, or replica count.
Exercise
A service has a p99 latency objective of 250 ms. Queueing currently contributes 12 ms at p99, and a test with a 20 ms maximum queue delay raises it to 31 ms. Should you keep the 20 ms setting without further testing?
Show answer
No. The setting may still fit the total budget, but it must be tested with full end-to-end latency at peak load. Check model time, memory, throughput, and p99 behavior before keeping it.