Agentic Pattern Libraryby Vikas Goyal
Patterns / Math models / Little’s Law and queueing
No. M04 Reliability Established Tool/action Coordination

Little’s Law and queueing

\(L = \lambda W\), plus Erlang C for rate-limited model calls

Takeaway

At model calls a second taking s each, a limit of concurrent calls keeps slots 92% busy, and every call waits about 2.5 s in line before it even starts.

Change the blue numbers. Every figure on this page updates with them.

Why care

Agents multiply load, and latency does not grow in a straight line with it.

One user request becomes many model calls and tool calls, and each one holds a slot while it runs: a provider concurrency limit, a GPU, a connection pool, a share of a tokens-per-minute quota. Below about 70% busy, queues are short and invisible. Past about 85%, random bursts stop draining and waiting time climbs steeply. Little's Law tells you how much is in flight; queueing theory tells you how long it waits. Together they size concurrency limits and capacity before the latency complaints arrive.

The intuition

Picture a coffee shop. If 2 customers arrive a minute and each stays 15 minutes, about 30 people are inside at any moment. That is Little's Law, and it holds whatever the shop looks like inside.

Now look at the line. When the baristas are busy half the time, a customer rarely waits. When they are busy 90% of the time, every small burst of arrivals builds a line that never quite clears before the next burst. For a single server, total time in the shop relative to service time looks like this:

50% busy
2×
80% busy
5×
90% busy
10×
95% busy
20×

More servers sharing one line soften the curve a lot, which is why one shared pool of model capacity beats many small dedicated ones. But no pool escapes the steep climb near 100%.

The math

Little's Law holds for any stable system, with no assumptions about arrival or service patterns:

$$L = \lambda W$$

For \(c\) slots serving calls that arrive at random, the Erlang C model gives the probability a call has to wait and the average wait:

$$a = \lambda S,\quad \rho = \frac{a}{c},\qquad C(c,a) = \frac{\dfrac{a^c}{c!}\dfrac{c}{c-a}}{\displaystyle\sum_{k=0}^{c-1}\frac{a^k}{k!} + \frac{a^c}{c!}\frac{c}{c-a}},\qquad W_q = \frac{C(c,a)\,S}{c-a}$$
\(\lambda\)
arrival rate: model calls (or tasks) per second, at peak
\(S\)
average time one call holds a slot, in seconds; \(\mu = 1/S\)
\(c\)
number of slots: concurrency limit, GPUs, workers
\(a,\ \rho\)
offered load in Erlangs (busy slots on average), and utilization per slot; needs \(\rho < 1\)
\(C(c,a)\)
probability an arriving call finds every slot busy and waits
\(W_q,\ W\)
average wait in line, and total time per call \(W = W_q + S\)
\(c_a,\ c_s\)
variability of arrivals and of call times (standard deviation over mean); 1 for purely random

Real traffic is burstier than random and LLM call times vary with output length. A standard correction scales the wait by the variability:

$$W_q \approx W_q^{\text{Erlang C}} \cdot \frac{c_a^2 + c_s^2}{2} \qquad\qquad \Pr(\text{wait} > t) \approx C(c,a)\, e^{-(c-a)\,t/S}$$
  • Little's Law at two levels: conversations in flight = conversations per second × conversation length sizes session state; calls in flight = calls per second × time per call sizes the slot pool.
  • The wall: \(W_q\) has \(c-a\) in the denominator. As load approaches capacity, the wait grows without bound.
  • The tail: waiting time beyond \(t\) falls off exponentially at rate \((c-a)/S\), so spare capacity buys short tails.

Where each of these comes from is worked through in Derivations at the end of the page.

Interactive calculator

Enter peak load, call time and your slot limit. The curve shows how latency bends as utilization rises; the second view shows what each extra slot buys.

1 is random arrivals. Batch jobs and retry storms push it above 1.
Standard deviation of call time divided by its mean, from your logs.
–
Slot utilization
–
Calls that have to wait
–
Average wait per call
–
Average total time per call
–
Calls in flight, \(L=\lambda W\)
–
Slots to keep waits under 10% of call time
Your slots, one shared queue Same slots, split into separate queues Your utilization now

Worked example: a customer-support agent

A support agent handles 1,800 conversations an hour at peak. Each conversation makes 8 model calls that average 3 seconds, and lasts about 4 minutes including the customer's typing. The model deployment allows 13 concurrent requests. From the logs, arrivals are somewhat bursty (\(c_a = 1.3\)) and call times vary (\(c_s = 0.8\)).

Little's Law first, at both levels. Conversations: \(0.5/\text{s} \times 240\,\text{s} = 120\) open at once, which sizes the session store. Calls: \(0.5 \times 8 = 4\) per second, each holding a slot for 3 s, so \(a = 12\): on average twelve of the thirteen slots are busy.

SlotsUtilizationCalls that waitAvg wait per callAdded per conversation
13 (current)92%70%2.5 s19.7 s
1486%48%0.84 s6.7 s
1675%21%0.18 s1.4 s
2060%2%0.01 s0.1 s

Customers were waiting an extra 20 seconds per conversation, entirely in queues, while dashboards showed the model answering in 3 seconds. Raising the limit from 13 to 16, 23% more capacity, cut the added wait by 93%. The team also found that their retry-on-timeout logic fired hardest exactly when the queue was longest, pushing \(c_a\) up at the worst moment; adding backoff with jitter fixed that.

Assumptions and where it breaks

  • The system must be stable over the window. Little's Law relates long-run averages. During a spike, the number in flight and the time in system lag each other; measure over windows longer than a typical call.
  • The variability correction is approximate. It is accurate to within roughly 10–20% for moderate variability, which is good enough for sizing, not for promising an exact SLO. Validate with load tests near your planned utilization.
  • Rate limits are often tokens, not requests. Convert a tokens-per-minute quota into slots: capacity in calls per second is quota ÷ 60 ÷ tokens per call, and that plays the role of \(c/S\).
  • Retries and timeouts feed back. A slow queue triggers timeouts, timeouts trigger retries, and retries add load, so \(\lambda\) rises just as capacity runs out. Count retries in \(\lambda\) and back off with jitter.
  • Not all calls are equal. Interactive chat and background batch work sharing one pool will hurt each other. Use priorities or separate pools, and model each class on its own.

How to apply it

  1. Measure peak, not average. Take \(\lambda\) from the busiest 15 minutes of the week, and \(S\), \(c_a\), \(c_s\) from the same logs.
  2. Sanity-check with Little's Law. Calls in flight \(= \lambda \times W\). If that is close to your concurrency limit, you are already queueing.
  3. Keep interactive paths under about 75% busy. Batch work can run hotter; it cares about throughput, not waits.
  4. Pool capacity. One shared pool with routing beats many small dedicated ones at the same total size.
  5. Size retries into the load. Use exponential backoff with jitter, and budget for retry traffic in \(\lambda\).

How to explain it to a stakeholder

"A model endpoint is a checkout lane. At 60% busy there's no line; at 90% busy the line is most of the wait. We buy a few more lanes than the average says, because customers arrive in bunches."

For coding agents

A machine-readable summary and a reference implementation. The same spec is embedded in this page as <script type="application/json" id="model-spec">, and the whole series is listed in models.json.

Model spec (YAML)
id: littles-law
number: M04
name: Little's Law and Erlang C queueing
family: reliability
answers: "How many slots keep model-call latency acceptable at peak load?"
formula:
  littles_law: "L = lam * W"
  offered_load: "a = lam * S"
  utilization: "rho = a / c   (must be < 1)"
  erlang_c: "C(c, a) = P(arriving call waits)"
  mean_wait: "Wq = C(c, a) * S / (c - a)"
  variability_correction: "Wq_GGc ~= Wq * (ca**2 + cs**2) / 2"
  wait_tail: "P(wait > t) ~= C(c, a) * exp(-(c - a) * t / S)"
inputs:
  lam: {type: float, meaning: arrivals per second at peak}
  S: {type: float, meaning: mean seconds a call holds a slot}
  c: {type: int, meaning: concurrent slots}
  ca: {type: float, meaning: coefficient of variation of inter-arrival times}
  cs: {type: float, meaning: coefficient of variation of call times}
assumptions:
  - stable system (rho < 1) over the measurement window
  - one shared first-come-first-served queue
  - variability correction is an approximation
use_when:
  - setting concurrency limits, worker pools or GPU counts
  - explaining queueing delay that does not show up in model latency metrics
related_patterns: [parallelization, orchestrator-workers, routing, agent-harness, budget-aware-planning]
Reference implementation (Python)
import math

def erlang_c(c, a):
    """Probability an arrival waits, for c slots and offered load a = lam * S."""
    if a >= c:
        return 1.0
    b = 1.0                       # Erlang B by stable recurrence
    for k in range(1, c + 1):
        b = a * b / (k + a * b)
    return c * b / (c - a * (1 - b))

def queue_stats(lam, S, c, ca=1.0, cs=1.0):
    a = lam * S
    if a >= c:
        return {"stable": False, "utilization": a / c}
    pw = erlang_c(c, a)
    wq = pw * S / (c - a) * (ca ** 2 + cs ** 2) / 2
    w = wq + S
    return {"stable": True, "utilization": a / c, "p_wait": pw,
            "mean_wait": wq, "mean_time": w, "in_flight": lam * w}

def slots_for_wait(lam, S, max_wait, ca=1.0, cs=1.0, c_max=10_000):
    for c in range(max(1, math.floor(lam * S) + 1), c_max):
        if queue_stats(lam, S, c, ca, cs)["mean_wait"] <= max_wait:
            return c
    return None

if __name__ == "__main__":
    print(queue_stats(lam=4, S=3, c=13, ca=1.3, cs=0.8))
    # utilization 0.923, p_wait 0.704, mean_wait 2.46 s, in_flight 21.8
    print(slots_for_wait(lam=4, S=3, max_wait=0.3, ca=1.3, cs=0.8))  # 16

Derivations

For the math-curious: where each result in The math comes from. Nothing above depends on reading this.

Little's Law from one picture

Plot \(N(t)\), the number of calls in the system, over a long window of length \(T\). The area under that curve can be counted two ways. Over time, it is \(\int_0^T N(t)\,dt = L\,T\), where \(L\) is the average number in the system. Over calls, each call contributes its own time in the system, so the area is also \(\sum_i W_i = (\lambda T)\,W\), where \(\lambda T\) is the number of calls and \(W\) their average time. Equating the two, \(L T = \lambda T W\), so \(L = \lambda W\). Nothing about arrival patterns or service order was assumed.

One slot: why the wait blows up near capacity

With random arrivals at rate \(\lambda\) and random service at rate \(\mu\), the number in the system is a birth-death chain. In steady state, flow up between \(n\) and \(n+1\) equals flow down: \(\lambda p_n = \mu p_{n+1}\). So \(p_n = \rho^n(1-\rho)\) with \(\rho = \lambda/\mu\). The mean number in the system is \(L = \rho/(1-\rho)\), and by Little's Law \(W = L/\lambda = S/(1-\rho)\). That is the 2×, 5×, 10×, 20× table in the intuition: at \(\rho = 0.9\), \(1/(1-\rho) = 10\).

Many slots: the Erlang C formula

With \(c\) slots, the down-rate from state \(n\) is \(\min(n,c)\,\mu\). Balancing flows gives

$$p_n = p_0\,\frac{a^n}{n!}\ (n < c), \qquad p_n = p_0\,\frac{a^c}{c!}\,\rho^{\,n-c}\ (n \ge c).$$

A call waits when it arrives to find \(n \ge c\). Summing the geometric tail, \(\sum_{n\ge c} p_n = p_0\,\frac{a^c}{c!}\frac{1}{1-\rho}\). Normalizing so all \(p_n\) sum to 1 gives \(C(c,a)\) as stated. The expected queue length is \(L_q = C\,\rho/(1-\rho)\), and Little's Law applied to the queue alone gives \(W_q = L_q/\lambda = C\,S/(c-a)\).

The waiting-time tail

Given that a call must wait, all \(c\) slots are busy and they free up at combined rate \(c\mu\), while new arrivals join behind it at rate \(\lambda\). The line ahead drains at net rate \(c\mu - \lambda = (c-a)/S\), and with first-come-first-served order the conditional wait is exponential with that rate. So \(\Pr(\text{wait} > t) = C(c,a)\,e^{-(c-a)t/S}\). Each extra slot adds \(1/S\) to the drain rate, which is why a little spare capacity shortens the tail so much.

Variability and the pooling effect

For a single server with general arrival and service patterns, Kingman's approximation is \(W_q \approx \frac{\rho}{1-\rho}\cdot\frac{c_a^2+c_s^2}{2}\cdot S\). With random arrivals and service, \(c_a = c_s = 1\), the factor is 1 and the formula matches the exact single-slot result. The Allen–Cunneen approximation applies the same factor to the multi-slot Erlang C wait.

Pooling: split \(c\) slots into \(c\) separate single-slot queues, each taking \(\lambda/c\). Utilization is unchanged at \(\rho\), but each queue waits \(\frac{\rho}{1-\rho}S\), while one shared queue waits \(\frac{C\,S}{c-a} = \frac{C}{a}\cdot\frac{\rho}{1-\rho}S\), using \(c-a = c(1-\rho)\). Since \(C < 1\), the shared queue waits at least \(a\) times less at the same total capacity: with twelve busy slots, at least twelve times less. The red curve in the calculator shows the split version.

References

  1. Little, J. D. C. (1961). A Proof for the Queuing Formula: L = λW. Operations Research 9(3), 383–387.
  2. Harchol-Balter, M. (2013). Performance Modeling and Design of Computer Systems: Queueing Theory in Action. Cambridge University Press. A practitioner-friendly treatment of M/M/c, variability and pooling.
  3. Kingman, J. F. C. (1961). The single server queue in heavy traffic. Mathematical Proceedings of the Cambridge Philosophical Society 57(4), 902–904. The source of the variability factor \((c_a^2+c_s^2)/2\).