Sub topic 7
Queueing Basics and Little's Law
Assume you already understand an HTTP or gRPC model endpoint, latency percentiles such as p50 and p99, Python, and basic Kubernetes Deployments. This chapter uses those ideas to connect request traffic with the number of model replicas you need.
A model service is a queue
A request usually passes through several stages:
- It waits in an ingress or service queue.
- It waits for an available model worker.
- The model performs inference.
- The response returns to the client.
The time from request arrival to response is the request's latency. It includes queueing time and service time. A busy accelerator can make service time stable while the queue grows. The result is rising p95 and p99 latency even if the model itself has not changed.
Little's law
Little's law relates three averages:
L = \lambda WLis the average number of items in the system, including queued and running requests.λis the average arrival rate.Wis the average time each item spends in the system.
For inference, you can read this as:
\text{average in-flight requests}
=
\text{requests per second}
\times
\text{average latency in seconds}For example, at 200 requests per second and 120 milliseconds of average latency:
L = 200 \times 0.120 = 24The service has about 24 requests in flight on average. This is not the same as saying that 24 requests are waiting. Some are running inference.
Little's law describes a stable system. If requests arrive faster than the service can complete them, the queue grows without reaching a meaningful steady-state average.
Estimating replica count
Suppose one replica can handle eight concurrent requests. Do not plan to use all eight indefinitely. A target utilization of 70% leaves room for bursts and variation.
import math
def required_replicas(
arrival_rate_rps,
avg_latency_s,
concurrency_per_replica,
target_utilization=0.7,
):
in_flight = arrival_rate_rps * avg_latency_s
usable_concurrency = concurrency_per_replica * target_utilization
return math.ceil(in_flight / usable_concurrency)
replicas = required_replicas(200, 0.120, 8)
print(replicas) # 5The calculation gives five replicas because 24 / (8 × 0.7) rounds up to five. Treat this as a starting estimate, not proof of capacity. Benchmark the actual model with realistic input sizes, batch settings, and traffic patterns.
| Quantity | Example | Unit |
|---|---|---|
| Arrival rate | 200 | requests/second |
| Average latency | 0.120 | seconds |
| In-flight requests | 24 | requests |
| Usable concurrency per replica | 5.6 | requests |
| Starting replica count | 5 | replicas |
What the law cannot tell you
Little's law uses averages. It does not predict burst behavior, p99 latency, maximum queue length, or the time needed to start a new replica. A service can satisfy the average calculation while violating its latency objective during short traffic spikes.
Use queue depth and concurrency to detect immediate pressure. Use measured throughput and tail latency to validate the estimate. Scaling only on average CPU can miss a model that is waiting on accelerator memory or an internal request queue.
Exercise
A service receives 80 requests per second and has 250 ms average latency. How many requests are in flight on average?
Show answer
Little's law gives L = 80 × 0.250 = 20 in-flight requests. This includes both queued and actively running requests.