The idea: one server, random arrivals, random work

Customers arrive at a single server at random. If the server is busy they wait in a line and are served first come, first served. Each one needs a random amount of work. This is the M/M/1 queue, the simplest model in queueing theory, and one of the few with exact answers for how long the line gets and how long people wait.

Arrivals at rate λ = 8 per second enter a FIFO queue holding three waiting customers, then a single server with rate μ = 10 per second, then leave. A bracket over the queue is labelled Lq and Wq (waiting); a bracket over the queue and the server is labelled L and W (in the system). Below: Kendall notation M / M / 1 read as arrivals / service / servers.
Wq and Lq count only the waiting line; W and L count the line plus the customer being served.

The name is Kendall notation, A/S/m: the arrival process, the service-time distribution, and the number of servers. M stands for Markov (memoryless): arrivals form a Poisson process (exponential gaps, rate λ) and service times are exponential (rate μ). D means deterministic, a constant time; G means any distribution. Unless more letters follow, the line has unlimited room and serves in FIFO order. Why exponential gaps fit random arrivals is on the exponential distribution page.

The canvas uses μ = 10 customers per second (mean service 100 ms) and λ = 5, 8, 9 or 9.5 per second. Two seeded random generators, one for gaps and one for service times, make every run repeat exactly. Demo: watch the first 10 customers follows each box from the source, through the queue, to the exit.

Utilisation and stability

ρ = λ/μ is the utilisation: the share of time the server is busy. At λ = 8 and μ = 10, ρ = 0.8, so the server is idle 20 % of the time. The simulation measures it as busy time ÷ elapsed time, and it lands on 0.801. The queue is stable only if ρ < 1. At ρ ≥ 1 work arrives at least as fast as it can be done, and the line grows without limit.

The formulas

Let N be the number of customers in the system. Because both gaps and service times are memoryless, N moves up by one at rate λ and down by one at rate μ, like a Markov chain with states 0, 1, 2, … In the long run, the flow from state n to n + 1 equals the flow back: P(n) · λ = P(n + 1) · μ. So each state is ρ times as likely as the one below it:

P(N = n) = (1 − ρ) · ρⁿ          (P(0) = 1 − ρ: the server is idle)

L  = ρ / (1 − ρ)       mean number in the system
Lq = ρ² / (1 − ρ)      mean number waiting       (L − Lq = ρ)
W  = 1 / (μ − λ)       mean time in the system
Wq = ρ / (μ − λ)       mean time waiting         (W − Wq = 1/μ)
Top: states 0, 1, 2, 3, 4 in a row with arrows to the right labelled λ and arrows to the left labelled μ. Bottom: bars of P(N = n) = 0.2 × 0.8ⁿ for ρ = 0.8: 0.20, 0.16, 0.13, 0.10, 0.08 and so on, falling slowly, with the mean L = 4 marked.
Each step up the chain is ρ times as likely as the one before, so N has a geometric distribution with mean ρ/(1−ρ).

The four numbers are tied by Little's law, L = λW and Lq = λWq. The table on the canvas checks it on the measured numbers: at ρ = 0.8, λ̂ · W = 8.02/s × 0.494 s = 3.963 = L. Little's law holds for any queue, not only this one; Latency vs Throughput shows it on a server with threads and a bounded queue, together with the "hockey stick" of latency against load.

Run (100 000 customers)ρL measured / formulaW measured / formula
λ = 5/s0.50.997 / 10.199 s / 0.2 s
λ = 8/s0.83.963 / 40.494 s / 0.5 s
λ = 9/s0.98.805 / 90.976 s / 1 s
λ = 9.5/s0.9518.398 / 191.932 s / 2 s

Near ρ = 1 waiting explodes

W = 1/(μ − λ) depends on the spare capacity μ − λ, not on the load. From ρ = 0.5 to 0.8 the spare capacity falls from 5/s to 2/s and W grows from 0.2 s to 0.5 s. From 0.8 to 0.95 the load rises by only 1.5 customers per second, but the spare capacity falls from 2/s to 0.5/s, so W grows four times, to 2 s: 20 times the 100 ms of actual work (Demo: ρ = 0.95: waiting explodes). In that run up to 104 customers were in the system at once. Demo: sweep ρ = 0.5 … 0.95 puts all four runs on the L vs ρ chart, on top of the curve ρ/(1 − ρ).

M/D/1: less variability, half the line

Make every service take exactly 100 ms. The load is the same, ρ = 0.8, and the arrivals are the same customers at the same times. Yet the line is half as long. The Pollaczek–Khinchine formula for a single server with any service distribution (M/G/1) says why:

Lq = ρ² · (1 + Cs²) / (2 (1 − ρ))      Cs = standard deviation / mean of the service time

exponential service:  Cs² = 1   →  Lq = ρ² / (1 − ρ)          = 3.2  at ρ = 0.8
constant service:     Cs² = 0   →  Lq = ρ² / (2 (1 − ρ))      = 1.6  at ρ = 0.8

The simulation measures Lq = 3.162 for M/M/1 and 1.600 for M/D/1 (Demo: M/D/1: constant service halves Lq). Waits come from load and from variability: a few long jobs make everyone behind them wait. The arrivals are still random, so the line does not go away.

Two horizontal bars at ρ = 0.8: M/M/1 with exponential service, Lq = 3.2, and M/D/1 with constant 100 ms service, Lq = 1.6, half as long. Below, the Pollaczek–Khinchine formula Lq = ρ²(1 + Cs²) / (2(1 − ρ)).
Same arrivals, same load: removing the variability of service time halves the waiting line.

Reading a simulation

The measured numbers are averages over time (L, Lq, ρ) or over customers (W, Wq). They wander before they settle. At ρ = 0.8, L after 20 000 customers is 3.70 and after 100 000 it is 3.96. At ρ = 0.95 it is 12.5 after 20 000 and 18.4 after 100 000: near ρ = 1 the queue has long busy spells, and a run must cover many of them before the average means anything. The strip on the canvas shows N(t) over the last 20 seconds, so you can see those spells at ρ = 0.95.

This page runs only two kinds of event, the next arrival and the next departure. A general simulator keeps a sorted event list for many kinds; see Discrete-Event Simulation. Several servers sharing one line (M/M/c) are on pooled queues, and networks of queues on Mean Value Analysis.

See also Binomial vs Poisson (the Poisson count of arrivals in a window), CPU Scheduling (waiting time of jobs on one CPU) and router queues (a queue that is not unlimited).

See also Discrete-Event Simulation, which runs this same queue one event at a time: the event list, the clock jumps and the counters behind the measured numbers.

See also Mean Value Analysis, which solves a closed network of several queues one population at a time.

See also 2^k Factorial Design for planning which settings to measure and how much each one matters.

See also Simulation Output Analysis, which shows why a simulated W at ρ = 0.9 needs warm-up deletion, replications or batch means before its error bar can be trusted.

What the page leaves out

The page stays with one server and a line with unlimited room. A finite line (M/M/1/K) turns some arrivals away, and other service orders (last in first out, priorities, processor sharing) change who waits but, for M/M/1, not the mean L. It does not prove the Pollaczek–Khinchine formula, show the full distribution of waiting times (for M/M/1 it is exponential too), or give confidence intervals for the simulated numbers. Real servers are rarely exactly M/M/1: service times often have heavier tails than exponential, which by the same formula makes waits longer still.

On the mind map

Open the Distributed Systems mind mapDistributedSystemsReplication: copies of data · what reads seeReplicationPartitioning: split data over nodesPartitioningTime and membership: order events, know who is aliveTime and membershipConsensus: agree on one value or logConsensusTransactions: one change across many servicesTransactionsMessaging: send events between systemsMessagingKafka internals: a replicated append-only logKafka internalsRedis internals: one thread, data in memoryRedis internalsKubernetes: reconcile desired stateKubernetesResilience and speed: stay up and fast under loadResilience and speedCache strategiesCache strategiescache-aside, write-through, write-behindCircuit breakerCircuit breakerstop calling a failing serviceTMR and N-VersionTMR and N-VersionMajority masks one fault, not a shared bugFault Tree AnalysisFault Tree AnalysisMinimal cut sets; AND multiplies, OR 1−ΠToken vs leaky bucketToken vs leaky buckettoken allows bursts; leaky smoothsBackpressureBackpressurebounded queue: block, drop or ask lessLatency vs throughputLatency vs throughputnear full load, queues blow up p99M/M/1 queueW = 1/(μ−λ): waits explode as ρ → 1Pooled queues M/M/cPooled queues M/M/cOne shared line beats separate linesMean Value AnalysisMean Value AnalysisRk = Dk(1 + Qk(N−1)), row by rowDiscrete-event simulationDiscrete-event simulationPop earliest event, jump clock, run handlerSimulation Output AnalysisSimulation Output AnalysisCorrelated data: batch it or replicate itMonolith vs microservicesMonolith vs microservicesfunction call vs network callDistributed tracingDistributed tracingtraceparent links spans across servicesRate limit windowsRate limit windowsfixed window lets 2x burst at the edgeRetry, backoff and jitterRetry, backoff and jitterWait 2^n plus random, or retries stampedeHedged requestsHedged requestsSlow? Send a copy; take the first replyOpen the Distributed Systems mind mapDistributed Systemsstay up and fast under loadResilience and speedCache strategiesCache strategiescache-aside, write-through, write-behindCircuit breakerCircuit breakerstop calling a failing serviceTMR and N-VersionTMR and N-VersionMajority masks one fault, not a shared bugFault Tree AnalysisFault Tree AnalysisMinimal cut sets; AND multiplies, OR 1−ΠToken vs leaky bucketToken vs leaky buckettoken allows bursts; leaky smoothsBackpressureBackpressurebounded queue: block, drop or ask lessLatency vs throughputLatency vs throughputnear full load, queues blow up p99M/M/1 queueW = 1/(μ−λ): waits explode as ρ → 1Pooled queues M/M/cPooled queues M/M/cOne shared line beats separate linesMean Value AnalysisMean Value AnalysisRk = Dk(1 + Qk(N−1)), row by rowDiscrete-event simulationDiscrete-event simulationPop earliest event, jump clock, run handlerSimulation Output AnalysisSimulation Output AnalysisCorrelated data: batch it or replicate itMonolith vs microservicesMonolith vs microservicesfunction call vs network callDistributed tracingDistributed tracingtraceparent links spans across servicesRate limit windowsRate limit windowsfixed window lets 2x burst at the edgeRetry, backoff and jitterRetry, backoff and jitterWait 2^n plus random, or retries stampedeHedged requestsHedged requestsSlow? Send a copy; take the first reply
This page on the Distributed Systems mind map · 100 pages in 10 branches · open it to see the whole map and test yourself in recall mode.