Sub topic 1
Latency and throughput in model serving
Prerequisites
This chapter assumes you can serve a trained model behind an HTTP or gRPC endpoint. You should also understand latency, throughput, and percentile metrics such as p50 and p99.
Latency and throughput
Latency is the time one request takes, from arrival to response. Throughput is the number of requests the service completes per second. The two trade off. Serving more requests per second often makes each request wait longer.
Why batching makes accelerators more efficient
GPUs and other accelerators run best when they process many inputs in one pass. A single request uses only part of the hardware. Grouping requests into a batch fills more of the hardware and raises throughput. Each request then waits for the batch to form and finish, so its latency rises.
Static batching and its limits
Static batching groups requests into a fixed size, often in the client. The batch waits until it is full. Under light traffic, requests sit in the queue for a long time. Under heavy traffic, a fixed size may not match the load.
Dynamic batching: grouping requests on the server
Dynamic batching happens on the server. The server collects requests that arrive close together and sends the batch when either the batch is full or the maximum queue delay passes.
max_batch_size: 32
dynamic_batching {
preferred_batch_size: [ 8, 16 ]
max_queue_delay_microseconds: 5000
}This Triton Inference Server configuration allows batches of up to 32 requests and waits at most 5 ms to form one.
Latency objectives and tail latency
A latency objective, or SLO, sets a target such as "p99 under 200 ms." The p99 is the time that 99 percent of requests beat. Tail latency is the slow end of the distribution. Batching adds queue delay, and that delay mostly shows up in the tail. Measure p99 at your expected load, not only the average.
Exercise
A service has a p99 target of 100 ms and a max queue delay of 50 ms. One batch takes 40 ms to run. Can batching settings alone meet the target?
Show answer
Not with much margin. The worst case is about 50 ms of queue wait plus 40 ms of inference, which is 90 ms. That leaves about 10 ms for network and overhead. Measure p99 under load before relying on this setting.