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.
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/μ)
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 / formula | W measured / formula |
|---|---|---|---|
| λ = 5/s | 0.5 | 0.997 / 1 | 0.199 s / 0.2 s |
| λ = 8/s | 0.8 | 3.963 / 4 | 0.494 s / 0.5 s |
| λ = 9/s | 0.9 | 8.805 / 9 | 0.976 s / 1 s |
| λ = 9.5/s | 0.95 | 18.398 / 19 | 1.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.
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.