Sub topic 9
Choosing what to scale on
This chapter assumes you know how dynamic batching works, including max batch size and max queue delay. It also assumes you understand Little's law (in-flight requests = arrival rate × latency) and can read a Kubernetes HorizontalPodAutoscaler (HPA) manifest. The next chapter covers HPA mechanics. This one covers the earlier decision: which number should drive the replica count.
What a scaling signal has to do
An autoscaler compares one measured number to a target and adds or removes replicas. A good signal for a model service has four properties:
- It moves before users feel pain. A signal that only changes after latency has already broken the SLO makes the autoscaler react too late.
- It scales with load. If load doubles, the signal should roughly double, so the proportional math gives the right answer.
- It is comparable across replicas. The autoscaler averages the value over replicas, so each replica must report the same kind of number.
- It is stable under batching. Batching changes how much work each replica does per request. A signal that confuses "busy" with "saturated" will mislead you.
No single metric is best for every service. The usual candidates are compared below.
| Signal | Leads or lags | Scales with load | Main weakness |
|---|---|---|---|
| CPU utilization | Lags | Weakly for GPU models | Measures host work, not accelerator work |
| GPU utilization | Lags | Only until it hits 100% | Saturates early and hides how overloaded you are |
| Request rate (RPS) | Leads | Yes | Needs a known per-replica capacity, and request cost varies |
| In-flight concurrency | Leads | Yes, until saturation | Needs a per-replica target from load tests |
| Queue depth | Leads | Zero until saturation, then rises quickly | Noisy, and meaningless if the queue is unbounded or hidden |
| p99 latency | Lags | Nonlinear | Reacts after the SLO is broken, and feeds back through batching |
Why GPU utilization misleads
The utilization figure reported by nvidia-smi is the fraction of sampling time in which at least one kernel was running. It is not the fraction of compute capacity in use. A replica running a batch of 1 back to back can show 100% while using a fraction of the chip. A replica running a batch of 32 can also show 100%.
Dynamic batching makes this worse. As load rises, batches fill, and utilization climbs toward 100% quickly. Once it is pinned there, a 1.2x overload and a 3x overload look identical. An HPA target of 70% can only ask for about 1.43x the current replica count in one step (100 ÷ 70), however large the overload is.
The proportional rule the HPA uses is:
desired = ceil(current replicas × current metric ÷ target metric)
The script below applies it to three signals under the same 2x overload. It runs as written.
import math
def desired_replicas(current, metric, target, min_r=1, max_r=20, tolerance=0.1):
"""The HPA proportional rule, with a tolerance band around the target."""
ratio = metric / target
if abs(ratio - 1.0) <= tolerance:
return current
return max(min_r, min(max_r, math.ceil(current * ratio)))
current = 4 # replicas, currently handling 2x their capacity
# GPU utilization is capped at 100, so overload is invisible.
print("gpu util: ", desired_replicas(current, metric=100, target=70))
# Average queue depth per replica grows with the backlog.
print("queue depth:", desired_replicas(current, metric=10, target=4))
# In-flight concurrency per replica (capacity 8, target 70% = 5.6).
print("concurrency:", desired_replicas(current, metric=8, target=5.6))The output is 6, 10, and 6. The true need under 2x overload is 8 replicas. Queue depth overshoots slightly, which is the safer error. GPU utilization and concurrency both undershoot because each is capped by a per-replica limit. Each replica can hold only 8 requests at once, so concurrency tops out there. The remaining excess waits in the queue, where only queue depth sees it.
Concurrency: the load signal
In-flight concurrency is the number of requests a replica has accepted but not finished. Little's law ties it to things you can measure: concurrency = arrival rate × average latency. If you measure per-replica concurrency directly (an in-flight gauge in the server), you do not need to know either factor.
Concurrency has useful properties for scaling:
- It rises with load whether latency is flat or growing, so it reflects demand in both cases.
- It is independent of request cost. Ten slow requests and ten fast requests both count as ten.
- A per-replica target comes straight from a load test: find the concurrency at which p99 latency starts to bend upward, then set the target at 60 to 80% of that.
Its limit is that it saturates at whatever the server allows, such as the batch size times the number of model instances plus any admission limit. Beyond that point, concurrency stops telling you how bad things are.
Queue depth: the saturation signal
With dynamic batching, a request waits in a queue for a batch slot. When the replica keeps up, the queue stays near zero. When arrivals exceed service rate, the queue grows without bound. This makes queue depth a sharp saturation signal that continues to grow past the point where concurrency and utilization flatten.
You can turn a latency budget into a queue-depth target with Little's law. Waiting time in the queue is roughly depth ÷ service rate. Suppose a replica serves 160 req/s, and your SLO leaves 30 ms for queueing:
depth ≈ 160 × 0.030 = 4.8
A target of 4 per replica (the value used in the HPA example from the batching chapters) fits that budget. You pick the number from the SLO, and you do not guess it.
Queue depth has traps:
- It is a zero-or-large signal. Under light load it sits at 0 or 1, so it tells you nothing about how much headroom remains. Pair it with a load signal if you need to scale down smoothly.
- Where you measure matters. The batcher's internal queue, a gateway queue, and the pending-request count from the server (for example Triton's
nv_inference_pending_request_count) are different quantities. Pick one and keep it consistent across replicas. - It needs a metrics adapter. The HPA reads custom metrics through an adapter such as Prometheus Adapter or KEDA. Plan for that dependency.
Request rate and latency
Request rate is a leading signal and easy to get from a gateway. It works when every request costs about the same. It fails when cost varies, such as variable-length inputs or LLM generations of different lengths, because 100 req/s of long requests needs far more capacity than 100 req/s of short ones. If you use it, derive the per-replica target from a load test on a realistic traffic mix.
p99 latency is the quantity you care about, but it is a poor control signal. It lags, it is noisy at low traffic, and it is coupled to your own batching settings. Adding replicas lowers queue wait, which lowers latency, which makes the autoscaler remove replicas again. Use latency to verify that scaling is working and to alert, not to drive it.
How the signals fit together
The diagram shows where each signal appears along the request path and which ones stay informative under overload.
A practical choice
For a batched model service on Kubernetes, a sound default is:
- Use queue depth per replica (or queue wait time) as the primary scale-up trigger, with the target derived from your queueing latency budget.
- Use in-flight concurrency as a secondary signal to scale down and to hold capacity at moderate load. The HPA accepts several metrics and picks the largest desired count, so scale-up responds to whichever signal demands more.
- Keep GPU utilization, CPU, and p99 latency on a dashboard for diagnosis.
- Use request rate only when request cost is uniform, or when you need to scale ahead of known traffic.
For LLM-style serving with continuous batching, queue depth and concurrency still work, but add a signal for the resource that actually runs out, such as KV cache occupancy. Slot count alone can hide memory pressure.
Common errors
- Targeting 70% GPU utilization. It looks like a CPU-style rule but caps the scale-up step and cannot see the size of an overload.
- Using a sum instead of an average. Autoscalers divide the per-pod values by replica count. If you export a service-wide total as a per-pod metric, the target means something different at every replica count.
- Choosing the target from intuition. A target that is too high lets queues build before scale-up. One that is too low wastes accelerators. Derive it from a load test and your SLO.
- Scaling on a signal affected by your own action. Latency and utilization both change when you change batch settings or replica count. Re-measure after any batching change.
- Ignoring readiness. New replicas take time to load and warm up. A fast-reacting signal paired with slow startup causes overshoot, which later chapters address.
- Averaging over a window that is too long. A five-minute average of queue depth smooths away exactly the bursts you need to catch. Use a short window for scale-up.
Exercise
A replica serves 100 requests per second. Your SLO leaves 50 ms of the latency budget for queue wait. Using wait ≈ depth ÷ service rate, what is the maximum average queue depth per replica you should target, and why is a GPU utilization target a poor substitute?
Show answer
Depth ≈ service rate × wait budget = 100 × 0.050 = 5 requests per replica, so a target of about 4 to 5 keeps queue wait within budget. GPU utilization is a poor substitute because it saturates near 100% once batches fill, so it cannot distinguish a mild overload from a severe one, and it has no direct link to the queue wait in your SLO.
Exercise
Six replicas each report an average of 9 in-flight requests. Each replica can hold 12 at once, and you want a 75% concurrency target. Using the proportional rule, how many replicas should you run?
Show answer
The target is 12 × 0.75 = 9 per replica. The metric already equals the target (ratio 1.0, inside the tolerance band), so the desired count stays at 6.