Little’s Law

Little’s law states that in a stable system, the average number of items inside equals the average arrival rate times the average time each item spends inside:

\[ L = \lambda W \]

\(L\) is the average number of items in the system, \(\lambda\) is the average rate at which items enter, and \(W\) is the average time from entering to leaving. For a service, the items are requests: \(L\) is the average number in flight (the concurrency), \(\lambda\) is requests per second, and \(W\) is mean latency in seconds. If 50 requests per second are admitted and each takes 0.8 seconds on average, then \(L = 50 \times 0.8 = 40\) requests are in flight on average. With 8 concurrent slots per replica, that is 5 replicas at full load, or \(40 / (8 \times 0.7) = 7.1\), so 8 replicas, if you want to run at 70 percent.

Why it holds

Draw every request as a horizontal bar on a timeline, from its arrival to its departure. Add up the bar lengths over an observation window of length \(T\). Counted by request, the total is the number of requests times their mean duration, \(\lambda T \cdot W\). Counted by moment in time, it is the number of requests in the system at each instant, summed over the window, which is \(L \cdot T\). Both are the same area, so \(L = \lambda W\). The argument never mentions how arrivals are spaced, how long individual requests take, or in what order they are served, which is why the law holds for any queueing discipline and any distribution.

Conditions and the usual mistakes

  • One boundary for all three quantities. The law applies to the whole service, to the waiting line alone, or to the servers alone, but \(L\), \(\lambda\), and \(W\) must describe the same boundary. Mixing end-to-end latency with a queue-depth gauge produces a number that matches nothing.
  • Stable, long-run averages. The law relates averages over a period long enough that the system is not growing or shrinking. A queue that keeps growing under overload has no steady \(L\), so an average over a window describes only that window.
  • \(\lambda\) counts items that actually enter. Requests rejected at the door never spend time inside. Use the admitted rate, not the offered rate, or \(L\) will be overestimated.
  • Averages only. The law gives no information about percentiles. A 99th percentile latency cannot be multiplied by a rate to get a concurrency.

The check below uses Poisson arrivals at 8 requests per second and exponentially distributed durations with a mean of 0.5 seconds. Each request has its own server, so there is no queueing and \(L\) should approach \(8 \times 0.5 = 4\). For each window length, \(L\) is the time-average number in the system, and \(W\) is the mean duration of requests that finished inside the window. Environment: Python 3.12 on macOS (Darwin 25.6).

import random
def run(T, lam=8.0, mean=0.5, seed=3):
    rng = random.Random(seed)
    # M/M/inf-like: every request gets its own server, so W = service time
    t, reqs = 0.0, []
    while True:
        t += rng.expovariate(lam)
        if t > T: break
        reqs.append((t, t + rng.expovariate(1/mean)))
    # time-average number in system over [0,T]: integrate overlap of each request with the window
    area = sum(min(d, T) - a for a, d in reqs)
    L = area / T
    done = [(a, d) for a, d in reqs if d <= T]
    W = sum(d - a for a, d in done) / len(done)
    return L, len(reqs)/T, W, len(done)/T
print(f"{'window':>8} {'L':>7} {'lambda':>8} {'W':>7} {'lambda*W':>9}")
for T in (2, 10, 60, 600, 6000):
    L, lam, W, lamd = run(T)
    print(f"{T:>7}s {L:7.2f} {lam:8.2f} {W:7.3f} {lam*W:9.2f}")
  window       L   lambda       W  lambda*W
      2s    1.98     6.50   0.270      1.76
     10s    3.89     7.50   0.532      3.99
     60s    3.81     8.07   0.470      3.79
    600s    4.13     8.09   0.511      4.13
   6000s    4.04     8.10   0.499      4.04

In long windows the two columns agree with each other and with the expected value of 4. In the 2-second window, requests still in flight at the end are counted in \(L\) and \(\lambda\) but missing from \(W\), which only sees requests that finished, so \(W\) is biased short and \(\lambda W\) falls below \(L\). The boundary effect shrinks as the window grows relative to \(W\).

The law is most useful as a conversion between quantities that are measured in different places: a gauge of requests in flight, a counter of requests, and a histogram of latency. If two are known, the third follows. A rising in-flight count at a constant request rate means latency has risen, and a latency target together with an expected rate fixes how much concurrency the system has to support.

References


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.