The idea: same servers, different lines

You have two servers, each able to serve 10 customers per second, and 18 customers per second arrive. Every way of arranging them is 90 % busy. Yet how long people wait depends a lot on the arrangement. The canvas runs three of them side by side with the very same customers:

  • A, separate queues: each server has its own line, and each arrival picks a line at random. That is c separate M/M/1 queues, each getting λ/c = 9 per second.
  • B, one shared queue: one line in front of all c servers. The first person in line takes whichever server frees up. This is the M/M/c queue.
  • C, one fast server: a single M/M/1 server c times as fast, 20 per second.
Three designs with the same capacity at λ = 18 per second. A: arrivals split into two lines, each with one server at 10 per second; mean wait Wq = 0.9 s. B: one shared line feeding two servers at 10 per second; Wq = 0.426 s. C: one line and one server at 20 per second; Wq = 0.45 s, time in system W = 0.5 s against 0.526 s for B.
Same load, same capacity: the shared line waits less than half as long as separate lines.

Each customer brings the same amount of work to all three systems: a server at 10/s needs w/10 seconds for it, the fast server w/20. Three seeded random generators (arrival gaps, work, lane choice) make every run repeat exactly, and using the same customers everywhere means the differences come from the design, not from luck. The single-server formulas these rows build on are on the M/M/1 queue page. Demo: watch the first 8 customers follows each customer through all three rows.

Why separate lines lose

With separate lines a customer can stand in a line while the other server has nothing to do. In the first 8 customers it happens twice. At t = 0.168 s C4 picks lane 2 and waits behind the long job of C3 while server 1 is idle; in B it walks straight to server 2. At t = 0.318 s server 1 in A goes idle again while C4 and C6 still wait in lane 2. A shared line never lets a server idle while anyone waits; that is the whole trick of pooling.

The numbers after 100 000 customers at λ = 18/s (Demo: 100 000 customers):

SystemP(wait) run / formulaWq run / formulaW run / formula
A, 2 × M/M/10.901 / 0.9000.945 s / 0.900 s1.045 s / 1.000 s
B, M/M/20.856 / 0.8530.415 s / 0.426 s0.515 s / 0.526 s
C, M/M/1 at 20/s0.902 / 0.9000.438 s / 0.450 s0.488 s / 0.500 s

Erlang C: the chance of waiting

For M/M/c, let a = λ/μ be the offered load in "servers' worth" of work (a = 1.8 here) and ρ = a/c the utilisation. An arrival waits only when all c servers are busy. The probability of that is the Erlang C formula, from the same kind of birth–death chain as M/M/1, except that the departure rate is nμ while n < c servers are busy:

           (aᶜ / c!) · c / (c − a)
C(c, a) = ─────────────────────────────────────────
           Σ (k = 0 … c−1) aᵏ / k!  +  (aᶜ / c!) · c / (c − a)

Wq = C(c, a) / (cμ − λ)        W = Wq + 1/μ        Little: Lq = λ Wq

c = 2, a = 1.8:  C = 16.2 / (1 + 1.8 + 16.2) = 0.853     Wq = 0.853 / (20 − 18) = 0.426 s

For one server, C(1, a) = ρ, and the formula turns back into the M/M/1 one. Note what pooling does: P(wait) only drops from 0.9 to 0.853, but a customer who does wait leaves sooner, because any of the c servers can take them. The mean wait of those who wait is 1/(cμ − λ) = 0.5 s in B and 1/(μ − λ/c) = 1 s in A.

One fast server or many slow ones

C waits a little longer than B (Wq 0.45 s vs 0.426 s): it has only one server, so a customer waits whenever anyone is in service. But its service is twice as fast, so its total time W is shorter: 0.5 s vs 0.526 s. At light load the gap is wide. At ρ = 0.5 (Demo: light load) the run gives W = 0.099 s for C, 0.133 s for B and 0.202 s for A: hardly anyone waits, so the service time decides. A pool of slow servers only catches up when the load is high and waiting dominates. That is why one fast CPU core beats two slow ones for a single stream of work, when the work can use it.

Load (c = 2)W formula: ABCW run: A / B / C
ρ = 0.5, λ = 10/s0.200 s0.133 s0.100 s0.202 / 0.133 / 0.099 s
ρ = 0.8, λ = 16/s0.500 s0.278 s0.250 s0.520 / 0.275 / 0.247 s
ρ = 0.9, λ = 18/s1.000 s0.526 s0.500 s1.045 / 0.515 / 0.488 s

Demo: sweep ρ = 0.5, 0.8, 0.9 puts all three runs on the W vs ρ chart, on top of the three curves. The runs differ from the formulas by a few percent; how far a run of a given length can be trusted is the topic of Simulation Output Analysis.

A bigger pool gains more

With c = 4 servers and λ = 36/s (Demo: c = 4) the load is still ρ = 0.9. Four separate lines are four M/M/1 queues at λ = 9/s each, so A waits just as long as before: 0.942 s in the run. The shared queue of four waits 0.192 s (Erlang C: P(wait) = 0.788, Wq = 0.197 s), less than half its c = 2 value. The fast server at 40/s gets W = 0.244 s against 0.292 s for B.

Square-root staffing

Turn the question around: how many servers do you need so that at most 20 % of customers wait? Searching c with Erlang C gives the exact answer. The square-root staffing rule gives it in one line:

c ≈ a + β · √a        β depends only on the target: P(wait) ≈ 1 / (1 + β Φ(β) / φ(β))

target P(wait) = 0.2  →  β = 1.06      (Φ, φ: the standard normal CDF and density; Halfin–Whitt)
Offered load aFewest c (Erlang C)⌈a + 1.06 √a⌉ρ = a/cP(wait)
2440.500.174
812120.670.140
3239390.820.166
1281411410.910.182
Bars for offered loads a = 2, 8, 32 and 128: the busy part a and the spare servers c − a = 2, 4, 7 and 13 needed for P(wait) at most 20 percent. Utilisation rises from 0.50 to 0.67, 0.82 and 0.91.
Spare servers grow like √a, so a large pool can run far hotter for the same chance of waiting.

The spare capacity c − a grows like √a, not like a (Demo: square-root staffing). Sixteen small call centres with a = 8 need 16 × 12 = 192 agents; one merged centre with a = 128 needs 141. It is the same economy of scale as in the rows above.

Two readings: supermarket lanes and thread pools

Supermarket lanes are design A: you pick a till and hope. Banks and airport desks with one snake line are design B. People can switch lanes, which helps A a little, but a single line is still better, and it is also fairer: nobody is overtaken by a luckier lane.

Thread pools face the same choice. A pool with one shared work queue (Java's ThreadPoolExecutor with one BlockingQueue) is design B: any idle thread takes the next task. Giving each thread its own queue is design A unless idle threads may steal work from busy ones, which is what work-stealing pools do. Thread Pool shows the pool itself, and Latency vs Throughput how its queue grows near full load.

See also Discrete-Event Simulation (the general event list behind runs like these), Mean Value Analysis (several queues in a network) and 2k factorial design (measuring the effect of factors such as c and ρ with few runs).

What the page leaves out

The page splits arrivals in A at random. Round-robin or "join the shortest line" does better than random, but still worse than one shared line. It keeps every line unlimited (no M/M/c/K and no Erlang B for lost calls), every customer patient (no abandonment, the Erlang A model) and every server identical. It does not show switching costs between lanes, priorities, or service times that are not exponential. The square-root rule is an approximation for large a; the table shows it matches the exact search here, but it can be off by one server for other targets.

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 queueM/M/1 queueW = 1/(μ−λ): waits explode as ρ → 1Pooled 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 queueM/M/1 queueW = 1/(μ−λ): waits explode as ρ → 1Pooled 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.