Sub topic 14
Metrics to Watch for Batching and Scaling
Assume you understand HTTP or gRPC model endpoints, p50 and p99 latency, Python, and basic Kubernetes Deployments. This chapter uses those ideas to connect inference metrics to batching and autoscaling decisions.
Start with the request path
A request usually passes through an ingress, a model server queue, a batch formation step, and the model execution step. Measure each part separately. End-to-end latency alone cannot show whether requests are waiting for a batch, waiting for a replica, or running slowly on the accelerator.
Track these latency values:
- Queue time: how long a request waits before execution starts.
- Batch wait time: how long the server collects requests for a batch.
- Compute time: how long the model takes to execute.
- End-to-end latency: the time from arrival to response.
- p50, p95, and p99 latency: the median and upper-tail behavior.
A rising p99 with a stable p50 often means that a small group of requests is waiting in a queue or encountering overloaded replicas. A larger batch may improve throughput while making this tail worse.
Metrics for batching
Record the batch size for every inference call, or at least a histogram of batch sizes. Compare the observed distribution with the configured maximum. If batches are almost always size one, increasing the maximum batch size will not help. The request rate may be too low, or the queue-delay limit may be too short.
Useful batching metrics include:
- Average and p95 batch size.
- Batch formation count and failed batch count.
- Batch queue depth.
- Time spent waiting to form a batch.
- Requests processed per second.
- Accelerator utilization and memory usage.
Throughput should be measured as completed requests per second. For language models, also measure tokens per second because request counts hide differences in prompt and output length.
| Metric | What it reveals | Common response |
|---|---|---|
| Batch wait p95 | Delay introduced while forming batches | Lower the queue delay |
| Average batch size | Whether batching is effective | Check arrival rate or raise the delay |
| Queue depth | Backlog before execution | Add replicas or reduce work |
| Accelerator utilization | Hardware occupancy | Improve batching or inspect bottlenecks |
Metrics for scaling
Autoscaling needs a signal that changes before users experience unacceptable latency. Queue depth is often useful because it shows unserved work directly. Track both the average and the maximum queue depth per replica. A global average can hide one overloaded replica.
Concurrency, the number of in-flight requests, is another useful signal. Utilization metrics such as GPU duty cycle, CPU use, and memory use explain why capacity is limited, but utilization alone is not always a good trigger. A GPU can report high utilization while the service still meets its latency objective, or low utilization while requests wait on a CPU or network bottleneck.
Instrument and compare
Keep metric windows consistent. Compare queue depth, batch size, throughput, and p99 latency over the same interval. A short spike may need no scale-out, while sustained queue growth indicates insufficient capacity.
def summarize(arrivals, completions, queue_depth, p99_latency_ms):
arrival_rate = sum(arrivals) / len(arrivals)
completion_rate = sum(completions) / len(completions)
average_queue = sum(queue_depth) / len(queue_depth)
return {
"arrival_rate_rps": round(arrival_rate, 2),
"completion_rate_rps": round(completion_rate, 2),
"average_queue_depth": round(average_queue, 2),
"p99_latency_ms": p99_latency_ms,
"backlog_growing": arrival_rate > completion_rate,
}
print(summarize([100, 120, 110], [98, 115, 108], [2, 5, 7], 180))Exercise
Batch wait p95 is 2 ms, average batch size is 1.2, and GPU utilization is 35%. What should you investigate before raising the maximum batch size?
Show answer
Investigate request arrival patterns, traffic distribution, and whether the server is receiving enough concurrent requests. The short wait and small batches suggest that the batcher is rarely given more work, so a larger maximum may not change behavior.