The idea: a simulation gives a series, not a sample

A simulation of a queue prints one number per customer: W1, W2, W3, …, the time each one spends in the system. We want the long-run mean W and an error bar on it. The trouble is that these numbers are not like coin tosses. Customer 2 waits behind customer 1, so a long wait is usually followed by another long wait. And a run that starts with an empty queue begins with short waits that the real, busy system would not have. Output analysis is the set of rules for turning such a series into an honest interval.

A sketch of W against customer number. The curve starts near 0.1 s, climbs during the warm-up period, and then wanders around the true W = 1 s. The first ℓ = 500 customers are shaded as deleted; the rest is the steady-state part used for the estimate.
The start of a run from empty is biased low; delete it, and estimate W from what is left.

The page uses one queue the whole time: an M/M/1 queue with arrivals at λ = 9 per second and service at μ = 10 per second, so the server is busy ρ = 0.9 of the time. The formula gives the true answer W = 1/(μ − λ) = 1 s, so every interval can be checked against it. A real study would not know W; that is why it simulates. Each run uses the event-by-event logic in a compact form, Lindley's recursion: the next customer's wait in line is Di+1 = max(0, Di + Si − Ai+1), and Wi = Di + Si. Every run has a seed, so the same button gives the same numbers.

Initialization bias and the warm-up period

The first customer finds an empty system and only waits for its own service, about 0.1 s. Queues build up over the next customers. Averaged over 10 runs, the first 50 customers spend only 0.649 s in the system, well below 1 s. This is initialization bias: the starting state is not typical. The usual fix is warm-up deletion: throw away the first ℓ customers and average the rest. The part you keep is called the steady state.

The bias is small in one long run, because 500 slow customers are lost among 10 000. It matters when you make many short runs: each run carries the same downward pull, and averaging many runs shrinks the noise but not the pull (Demo: skipping the warm-up deletion).

Welch's method

How large must ℓ be? Looking at one run does not work. Replication 1 alone has its first 500 customers at 1.79 s on average, above the true mean, because it happened to hit a busy spell early. Welch's method removes most of that noise in two steps:

  1. Make several replications (here 10) and average them customer by customer: the mean of customer 1 over all runs, of customer 2, and so on.
  2. Smooth that average with a moving average of window w (here w = 100): each point is the mean of the 2w + 1 values around it. Near the start, where there is no room, the window shrinks to 0 … 2i.

Plot the result and pick ℓ where the curve stops climbing. Here it starts at 0.08 s and reaches 95 % of its later level, 0.990 s, at customer 55. After that it only wobbles. Taking ℓ = 500 leaves a clear margin and costs just 5 % of a 10 000-customer run (Demo: warm-up by Welch's moving average). Erring on the long side is cheap; erring on the short side leaves bias in.

Independent replications

The clean way to get independent numbers is to make independent runs. Run 10 replications, each from empty with its own seed, delete ℓ = 500 customers in each, and let Yr be the mean W of the remaining 9500. The 10 values Y1 … Y10 are independent because the runs share nothing. Then build the usual confidence interval, with the t value because s is estimated from only 10 numbers:

x̄ ± t(n − 1, 0.975) · s / √n
n = 10:  x̄ = 0.9866,  s = 0.1630,  t(9) = 2.262
half-width = 2.262 × 0.1630 / √10 = 0.117      interval [0.870, 1.103]  ✓

Even with 95 000 customers kept, the error is ±12 %. At ρ = 0.9 the line drifts slowly: a crowded spell can last minutes, so one run holds only a handful of the long ones (Demo: 10 independent replications).

Batch means

Replications pay the warm-up cost 10 times. Batch means pays it once: make one long run of 100 500 customers, delete the first 500, and cut the remaining 100 000 into k batches. Each batch mean is one number. If the batches are long compared with a busy spell, neighbouring batch means are nearly independent, and the same t interval works.

One run of 100 000 kept customers cut two ways. Top: 10 batches of 10 000, batch means scattered with lag-1 correlation r1 = −0.10, interval 0.922 ± 0.090, which contains 1. Bottom: 1000 batches of 100, neighbouring batch means alike with r1 = 0.58, interval 0.922 ± 0.045, which misses 1.
The same run and the same x̄: short batches only look more precise.

With 10 batches of 10 000 the batch means have lag-1 correlation r1 = −0.10, close to 0, and the interval 0.922 ± 0.090 contains 1 (Demo: batch means from one long run). The lag-1 scatter on the canvas plots each value against the next one: a round cloud means neighbours are unrelated.

Why the naive interval is too narrow

Cut the same run into 1000 batches of 100 and the mean x̄ = 0.922 does not change, but the half-width halves to 0.045. Nothing was gained: 100 customers last about 11 seconds, shorter than a busy spell, so a long batch is followed by another long batch (r1 = 0.58). The formula s/√n assumes independence and counts each correlated batch as new information.

The extreme is the naive interval that treats all 100 000 customers as independent. Their lag-1 correlation is 0.986, and the half-width comes out as 0.0053 s, about 17 times narrower than the 10-batch one. The interval [0.917, 0.927] says the answer is known to half a percent, and it is wrong (Demo: short batches and raw data → too narrow). For a positively correlated series, the true variance of x̄ is σ²/n · (1 + 2 Σ ρk), where ρk is the correlation at lag k; the naive formula keeps only the 1.

Coverage: checking the method itself

A 95 % interval promises that 95 of 100 experiments of this kind contain the truth; one interval either does or does not. Because this queue's W is known, the page can repeat each method with 100 sets of seeds and count. That count is the coverage.

Method (100 experiments)CoverageMean half-width
10 replications, ℓ = 50094 %0.126
10 batches of 10 00092 %0.122
1000 batches of 10068 %0.054
naive: every customer17 %0.0061
100 short runs of 2000, no deletion68 %0.072
100 short runs of 2000, ℓ = 50096 %0.088
Bar chart of coverage over 100 seeds against the 95 % target line: 10 replications 94 %, 10 batches 92 %, 1000 batches 68 %, naive 17 %, 100 short runs without deletion 68 %, with deletion 96 %.
Correlated numbers and an unremoved warm-up both break the 95 % promise.

The narrow intervals are the ones that fail: precision you did not earn shows up as missed coverage (Demo: coverage of 100 replication intervals, Demo: coverage, batch means vs naive). The 100 short runs show the other failure. Without deletion every run is pulled low, x̄ settles near 0.92 instead of 1, and a tight interval around the wrong value misses a third of the time. Deleting 500 customers brings coverage back to 96 %.

The same √n law makes Monte Carlo estimates slow to sharpen, and the central limit theorem is why a mean of many customers is close to normal. When the network is simple enough, Mean Value Analysis gives the exact means with no simulation at all. When you compare designs with several factors, a 2k factorial design plans which runs to make, and each of its cells needs replications like the ones here.

See also Pooled Queues: M/M/c, where runs of 100 000 customers land within a few percent of the Erlang C formulas.

What the page leaves out

The page looks only at the mean time in system of a stable queue. It leaves out terminating simulations (a bank that closes at 5 pm has no steady state, and replications are the only method), quantiles and other measures, and time averages such as the mean queue length. It does not show automatic warm-up rules (MSER-5, Schruben's test), overlapping or standardized batch means, sequential procedures that run until the interval is narrow enough, the regenerative method, or variance reduction such as common random numbers and antithetic variates.

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/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 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/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 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.