Reliability and Cost Engineering › Concurrency, Capacity, and Little's Law
Language AI HandbookAll chapters The retry simulator changes the number of calls without tracking a queue. Little's law relates time in a queueing system to its occupancy.
Here is the long-run mean number of requests inside a boundary, is the rate of requests entering that boundary, and is the mean time those requests spend inside it. For a stable system with finite long-run averages, requests per second times seconds per request gives mean occupancy in requests. The identity includes queued work if the boundary includes the queue. Little's original proof states the conditions on the stochastic process and its means.
At 50 requests per second and a mean time in the system of 1.2 seconds, mean occupancy is 60 requests. Use a load test to decide how many active slots or how much headroom a latency target needs. In the idealized M/M/1 queue with Poisson arrivals and exponential service times, for arrival rate below service rate . It grows as the arrival rate approaches capacity. The next example keeps service time fixed, so its curve is for a different queue.
The simulation is a continuous-time single-server FIFO queue with exponential interarrival gaps and deterministic service. It starts empty and drops the first 5,000 jobs from the latency measurement.
PythonIn [14]Expand
def simulate_queue(arrival_rate, service_time, n_slots=200_000, seed=3):
"""Single-server FIFO queue with continuous event times.
arrival_rate: Poisson arrivals per second.
service_time: deterministic service time per request.
Returns average latency W over the run (excluding warmup)."""
rng = np.random.default_rng(seed)
# Exponential gaps generate the Poisson arrival times.
gaps = rng.exponential(1.0 / arrival_rate, size=n_slots)
arrival_times = np.cumsum(gaps)
# Single server: each job starts at max(arrival, previous_finish).
finish = np.empty(n_slots)
prev_finish = 0.0
for i in range(n_slots):
start = max(arrival_times[i], prev_finish)
finish[i] = start + service_time
prev_finish = finish[i]
warm = 5_000
latency = finish[warm:] - arrival_times[warm:]
return latency.mean(), latency
mu = 1.0 / 0.05 # server capacity = 20 jobs/second
results = {}
for frac in (0.3, 0.6, 0.8, 0.9, 0.95):
lam = frac * mu
W, _ = simulate_queue(lam, service_time=0.05)
results[frac] = (lam, W)ConsoleOut [15]Expand
server capacity mu = 20.0 jobs/s, service time = 0.05 s util lambda W(measured) L=lambda*W 0.30 6.00 0.061 0.36 0.60 12.00 0.087 1.05 0.80 16.00 0.149 2.38 0.90 18.00 0.272 4.89 0.95 19.00 0.510 9.69
At 95% utilization, a 10% relative increase in arrival rate raises offered load to 104.5% of capacity. If that rate persists in this unbounded model, a finite steady-state queue cannot be maintained. In a real service, test admission limits and burst headroom against the measured tail rather than relying on a fixed utilization target.
PythonIn [16]Expand
utilizations = np.linspace(0.1, 0.98, 60)
service_time = 0.05
drawn_latencies = np.array(
[
simulate_queue(
rho / service_time, service_time, n_slots=35_000, seed=5
)[0]
for rho in utilizations
]
)
# M/D/1 mean waiting time plus the fixed service time.
modeled_latencies = service_time * (1 + utilizations / (2 * (1 - utilizations)))VisualizationOut [17]Expand

The dashed curve adds mean waiting time to fixed service time seconds. If is utilization, the M/D/1 mean is . The waiting term grows as utilization approaches one. The sample mean varies with the seed, especially close to capacity. Use the table and Little's law to connect time in the queue to mean in-flight work. A system that scales after a planning window can still queue during a short burst. Load-test the headroom and scaling delay around the operating point you intend to use.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!