Maps to: CMU 15-440/640 Spring 2026, Part III (scale and performance); theme “resource scarcity, scheduling, concurrency”. Project: P3 (scalable web service) asks students to scale the tiers of a simulated web store to meet varying load at low cost. This lecture teaches the queueing ideas behind any such design; it contains no P3 code, uses no P3 interface, and its numbers come from its own toy world. Problem set: PS3’s first question involves tier sizing; the scenarios and numbers here are different. Sources:
- L. Kleinrock, Queueing Systems, Vol. 1 (1975);
- M. Harchol-Balter, Performance Modeling and Design of Computer Systems (2013);
- E. D. Lazowska, J. Zahorjan, G. S. Graham, K. C. Sevcik, Quantitative System Performance (1984; operational analysis, MVA);
- J. D. C. Little, A Proof for the Queuing Formula L = λW (Operations Research 1961);
- S. Halfin and W. Whitt, Heavy-Traffic Limits for Queues with Many Exponential Servers (1981);
- M. Mitzenmacher, The Power of Two Choices in Randomized Load Balancing (IEEE TPDS 2001) and How Useful Is Old Information? (IEEE TPDS 2000);
- Y. Azar, A. Broder, A. Karlin, E. Upfal, Balanced Allocations (STOC 1994);
- J. Dean and L. Barroso, The Tail at Scale (CACM 2013).
The slides are not public; this is not a transcript. Every number comes from
code/lecture11/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Service demands and loads are assumptions stated with each demo. Code:code/lecture11/. Reading time: ~80 minutes, plus ~5 to run the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Use Little’s law and the utilization law to reason about any system from measurements, without assumptions about distributions.
- Explain the hockey-stick curve of response time against utilization, compute M/M/1 means and percentiles, and say why variability (of arrivals and of service) multiplies waiting.
- Compare scale-up with scale-out, explain pooling, and size a server pool with Erlang C and square-root staffing.
- Compare load-balancing policies (random, round robin, JSQ, power of two choices, least work) and explain the herd effect of stale information.
- Find a multi-tier service’s bottleneck with the bottleneck law, predict where it moves, and analyze a closed system with MVA.
- Quantify the value of elasticity, and why a provisioning delay costs quality.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 2: tail latency and fan-out;
- Lecture 6: caching as a way to remove load;
- Lecture 10: small edge sites saturate.
- Probability at the level of “the exponential distribution is memoryless”.
- Scope: steady-state queueing and static capacity planning. How to change capacity over time — control loops, delays, oscillation, autoscaling signals — is Lecture 12.
0.3 Section → code map
| Section | Idea | Demo in code/lecture11/ |
|---|---|---|
| §2 | Little’s law, the hockey stick, variability | 01_littles_law_and_the_hockey_stick.py |
| §3 | scale up vs out; pooling; staffing | 02_scale_up_vs_scale_out.py |
| §4 | load balancing; stale information | 03_load_balancing.py |
| §5 | multi-tier bottlenecks; closed systems | 04_multitier_bottlenecks.py |
| §6 | elasticity over a day | 05_elasticity.py |
| all | formulas + simulators | queueing.py |
0.4 Notation
- = arrival rate (requests/s); = mean service time; = service rate of one server; = number of servers.
- Utilization . The offered load is the number of servers’ worth of work arriving.
- = mean time in the system (response time); = mean wait in the queue; = mean number in the system.
- SCV = squared coefficient of variation = variance / mean²: 0 for constant, 1 for exponential, > 1 for bursty or heavy-tailed.
- Kendall notation A/S/k: arrival process / service distribution / servers. M = Markovian (Poisson / exponential), D = deterministic, G = general.
1. The problem
1.1 The intuition
A coffee shop has one barista who takes a minute per drink. If customers arrive once every two minutes, there is rarely a line. If they arrive every 70 seconds, the barista is idle 15% of the time, yet the line sometimes reaches the door. Customers do not arrive evenly: three walk in at once, then nobody for five minutes. The barista cannot store idle time for later, so every burst becomes a queue. The closer the shop runs to capacity, the longer it takes to recover from each burst.
Every scaled-out service is that coffee shop many times over: front ends, application servers, databases, caches, each with a queue in front of it. Scaling a service means answering three questions:
- How many servers? Enough that queues stay short, but not so many that most sit idle and cost money.
- Where does each request go? One shared queue, or a balancer spraying requests at servers with their own queues?
- Which part limits the whole? The bottleneck, and what happens when you fix it.
Queueing theory answers all three with a few formulas, and simulation checks the formulas where they do not apply exactly.
1.2 Why not just measure?
You should measure (Lecture 12). But a measurement says what happens at today’s load. A capacity plan must say what happens at next month’s, or during a flash crowd, before it occurs. The formulas below turn a few measured numbers — arrival rate, service time, its variability — into predictions. They also explain why the measurements look the way they do, which is what you need when they surprise you.
2. Three facts behind every capacity plan
2.1 Little’s law
L = λW: the average number of requests in a system equals the arrival rate times the average time each spends in it.
Little’s law needs no assumption about distributions, scheduling or the number of servers. It is accounting: integrate the number in the system over time two ways, by time and by request. 01_littles_law_and_the_hockey_stick.py Part A measures directly (time-averaged) and compares it with on five very different systems:
| System | λ | W | L measured | λ × W |
|---|---|---|---|---|
| M/M/1 at 80% | 80/s | 48.85 ms | 3.900 | 3.900 |
| M/D/1 at 80% (constant service) | 80/s | 29.85 ms | 2.389 | 2.389 |
| bursty arrivals (SCV 4), 1 server, 70% | 70/s | 64.87 ms | 4.531 | 4.531 |
| M/M/8 at 90% | 720/s | 18.40 ms | 13.253 | 13.253 |
| 8 servers, random dispatch, 70% | 561/s | 33.44 ms | 18.773 | 18.771 |
The largest difference was 0.01%. Measure any two of L, λ and W and you know the third. A service doing 2,000 requests/s with a 50 ms mean latency has 100 requests in flight on average, which sizes its connection pools and thread pools (exercise 1).
Two companions are just as general:
- Utilization law: . Each server is busy for the fraction of time its share of the work takes.
- Response time is at least the total service demand: , where is the service time a request needs at resource , summed over its visits (§5).
2.2 The hockey stick
For one server with Poisson arrivals and exponential service (M/M/1):
Part B, with a 10 ms mean service time:
| Utilization | mean (sim) | 1/(μ − λ) | p99 (sim) | p99 (formula) | mean number in system |
|---|---|---|---|---|---|
| 10% | 11.1 ms | 11.1 | 51.5 ms | 51.2 | 0.1 |
| 50% | 20.0 | 20.0 | 92.1 | 92.1 | 1.0 |
| 80% | 49.6 | 50.0 | 216.1 | 230.3 | 4.0 |
| 90% | 102.2 | 100.0 | 474.3 | 460.5 | 9.0 |
| 95% | 199.2 | 200.0 | 808.8 | 921.0 | 19.0 |
The factor is the hockey stick:
- 2× the service time at 50%, 10× at 90%, 20× at 95%;
- the last 5% of utilization doubles the latency;
- the tail grows the same way from a higher base: at 90% load, 1 request in 100 took 474 ms for a 10 ms job.
Why ? A three-line argument, which works because exponential service is memoryless:
- An arriving request finds, on average, requests already in the system (Poisson arrivals see time averages: the “PASTA” property).
- Each of them, including the one in service, still needs on average more seconds (memorylessness), and then the newcomer needs its own . So .
- Little’s law gives . Substituting, , so .
The “1 +” in step 2 is the request itself; the is everyone ahead of it. As , the number ahead grows without bound, because the server never gets ahead of the arrivals for long enough to empty the queue.
This is why services are run at 50–70% utilization rather than 100%. The “wasted” 30–50% is what buys acceptable latency. It is also why Lecture 2’s tail latency is mostly queueing. And it gives an operational rule: watch utilization, but fear it nonlinearly — the step from 80% to 90% busy costs as much latency as the step from 0% to 80%.
2.3 Variability multiplies waiting
For one server with Poisson arrivals and any service distribution (M/G/1), the Pollaczek–Khinchine formula gives the mean wait exactly:
For general arrivals, Kingman’s approximation puts the two variabilities side by side: . Part C runs each at 80% load with 10 ms mean service:
| Arrivals and service | mean wait (sim) | formula | p99 response |
|---|---|---|---|
| constant service, Poisson arrivals | 20.0 ms | 20.0 (P-K) | 115 ms |
| exponential service, Poisson arrivals | 39.1 | 40.0 (P-K) | 227 |
| erratic service (SCV 4), Poisson arrivals | 102.6 | 100.0 (P-K) | 686 |
| exponential service, bursty arrivals (SCV 4) | 94.2 | 100.0 (Kingman, approx.) | 445 |
| constant service, constant arrivals | 0.0 | 0.0 | 10 |
Same mean, same load, a 5× spread in waiting. With perfectly regular arrivals and service, an 80%-busy server never queues at all. Queues come from randomness, not from load alone. Two practical consequences:
- reducing variability — splitting big requests, separating slow request types into their own pool, smoothing batch jobs — is as effective as adding capacity;
- a benchmark with constant request sizes and evenly spaced arrivals will badly underestimate real latency.
3. Scale up or scale out?
3.1 Same capacity, three designs
Capacity can come from one bigger machine (scale up) or from more machines (scale out). With more machines there is a further choice: one queue shared by all servers (a pool), or a queue per server with requests assigned on arrival. 02_scale_up_vs_scale_out.py compares them at equal total capacity (8 × 100 requests/s); mean / p99 in ms:
| Utilization | one server 8× faster | 8 servers, one queue | 8 servers, own queues, random |
|---|---|---|---|
| 30% | 1.8 / 8 | 10.0 / 46 | 14.3 / 67 |
| 70% | 4.2 / 19 | 11.2 / 48 | 33.6 / 156 |
| 90% | 13.5 / 67 | 19.8 / 79 | 99.7 / 444 |
| 95% | 26.8 / 135 | 33.0 / 140 | 190.5 / 806 |
- Scale-up wins on service time. At light load, one 8× server answers in 1.8 ms; a slow server in a pool still needs its 10 ms. If latency matters at low load, faster servers are worth paying for. Real scale-up is limited by the biggest machine you can buy, and its price grows faster than linearly.
- Pooling nearly closes the gap under load. At 90% the pool’s mean was only 1.5× the big server’s (5.6× at 30%). A request waits only when all 8 servers are busy, and then 8 servers drain the queue.
- Separate queues waste capacity. Random assignment made each server its own M/M/1 at 90%: 99.7 ms mean, 444 ms p99, five times the pool’s, with the same hardware. A long queue at one server while another idles is pure waste. Recovering pooling with separate queues is the load balancer’s job (§4).
3.2 How many servers? Erlang C and square-root staffing
For servers sharing a queue (M/M/k), the probability that an arriving request must wait is Erlang C, , and the mean wait is
queueing.erlang_c computes it through the numerically stable Erlang B recursion. Part B asks how many servers keep the share of requests that wait at all at or below 20%:
| Offered load (servers’ worth) | servers needed | spare | utilization | (k − a)/√a |
|---|---|---|---|---|
| 1 | 3 | 2 | 33% | 2.00 |
| 10 | 14 | 4 | 71% | 1.26 |
| 100 | 111 | 11 | 90% | 1.10 |
| 1,000 | 1,034 | 34 | 97% | 1.08 |
| 4,000 | 4,068 | 68 | 98% | 1.08 |
The spare capacity grows like the square root of the load: with β ≈ 1.1 here (the Halfin–Whitt regime, “square-root staffing”). A service with 1 server’s worth of work must run at 33% utilization to keep waits rare; one with 4,000 servers’ worth can run at 98% with the same quality.
This is the statistical engine of cloud computing. Pooling many customers’ fluctuating loads lets a provider run its machines far busier than any customer could alone. It is also the price paid by many small, separately loaded sites, such as Lecture 10’s cloudlets.
4. Load balancing
4.1 Policies
Large services cannot put all servers behind one literal queue. A front-end balancer assigns each request to a server, which keeps its own queue. The question is how close a policy comes to the shared queue. 03_load_balancing.py, 10 servers, mean / p99 in ms:
| Policy | 50% | 70% | 90% | 95% |
|---|---|---|---|---|
| random | 19.8 / 91 | 33.1 / 151 | 97.5 / 455 | 192.9 / 911 |
| round robin | 13.2 / 60 | 20.0 / 90 | 56.8 / 270 | 107.9 / 612 |
| power of 2 choices | 12.8 / 56 | 16.7 / 69 | 29.6 / 103 | 43.0 / 141 |
| join shortest queue (JSQ) | 10.2 / 47 | 11.6 / 52 | 18.9 / 78 | 29.3 / 115 |
| least work (knows job sizes) | 10.1 / 46 | 10.7 / 47 | 16.5 / 61 | 26.3 / 96 |
| one shared queue | 10.1 / 46 | 10.7 / 47 | 16.5 / 61 | 26.3 / 96 |
- Random turns 10 servers into 10 independent M/M/1 queues.
- Round robin spreads arrivals evenly, which removes the arrival variability at each server, but it ignores the queues and so cannot react to a server that drew a long job.
- JSQ looks at every queue and gets close to the shared queue, but polling every server on every request is expensive at scale.
- The power of two choices (Azar, Broder, Karlin, Upfal; Mitzenmacher) samples just two servers at random and picks the shorter queue. That gave 29.6 ms at 90%, most of the way from random (97.5) to JSQ (18.9). Two random samples rarely both land on long queues. The theory shows the longest queue shrinks from with one choice to with two — exponentially better — and further choices add only a constant factor.
- “Least work” equals the shared queue exactly, in every run: sending each job to the server that will be free first produces the same schedule as one FIFO queue. The shared queue is the ideal balancer, and knowing job sizes is what it takes to emulate one with separate queues.
4.2 When jobs differ in size
Part B makes job sizes highly variable (SCV 4) at 90% load:
| Policy | mean | p99 |
|---|---|---|
| random | 234.4 ms | 1,188 ms |
| round robin | 208.4 | 1,088 |
| power of 2 choices | 50.8 | 275 |
| JSQ | 29.7 | 208 |
| least work = shared queue | 25.4 | 136 |
Round robin collapsed: an even count of jobs per server is a very uneven amount of work when sizes vary. Counting queued requests is a poor proxy for load when requests differ. Balancers that see the backlog in time (outstanding work, latency) do better than those that count connections.
4.3 Old information: the herd effect
A real balancer sees load reports that are slightly old: servers report periodically, and several balancers each see only their own traffic. Part C refreshes the balancer’s view of the queues only every T ms (90% load):
| Refresh period | least loaded (stale) | power of 2 choices (stale) |
|---|---|---|
| 1 ms | 24.0 / 91 | 30.1 / 104 |
| 10 ms | 60.9 / 187 | 32.8 / 112 |
| 100 ms | 419.8 / 986 | 55.7 / 186 |
| 1,000 ms | 4,002 / 8,206 | 234.8 / 818 |
With stale information, “send to the least loaded” sends every request between two refreshes to the same server, the one that looked emptiest. It becomes the most loaded, and the next refresh moves the stampede somewhere else. This is the herd effect (Mitzenmacher, “How Useful Is Old Information?”). At a 100 ms refresh it was 4× worse than random.
Power of two choices degraded far more gracefully: its two random samples spread the herd across servers. But at 1 s even it was worse than random, because information older than the time queues take to change is worse than none.
The problem is not limited to one balancer with old reports. Large services run many balancers, each of which sees only the requests it sent itself. Each one’s picture of the servers is partial, and if they all compute “least loaded” from similar data they herd together. Designs such as Join-Idle-Queue (Lu et al. 2011) reverse the flow: idle servers announce themselves to a balancer, so balancers learn about spare capacity instead of polling for it.
The general lessons:
- randomize decisions made on shared, stale state;
- refresh faster than the load moves;
- or count your own recent assignments locally.
This is Lecture 10’s estimation problem again, a decision about remote state from an old local view.
5. Multi-tier services: find the bottleneck
5.1 Operational analysis
A web request typically visits a front end (parse, render), an application tier (business logic) and a database. Some tiers it visits several times. Write for the total service demand at tier : visits × service time per visit. Two laws need no distributions:
- Utilization law: .
- Bottleneck law: . The tier with the smallest caps the throughput of the whole service, however fast the others are.
04_multitier_bottlenecks.py assumes front end 4 ms, application 12 ms, database 3 queries × 3 ms = 9 ms. With servers (1, 2, 1) the database caps the service at 111 requests/s. Simulated:
| Arrival rate | U front end | U application | U database | mean | p95 |
|---|---|---|---|---|---|
| 33/s (30%) | 13% | 20% | 30% | 30.3 ms | 62 ms |
| 89/s (80%) | 36% | 53% | 80% | 72.5 | 174 |
| 100/s (90%) | 40% | 60% | 90% | 136.8 | 376 |
| 106/s (95%) | 42% | 63% | 95% | 302.5 | 918 |
Where do the demands come from in a real system? The service demand law turns two routine measurements into a demand: . That is the measured utilization of tier (times its servers) divided by the measured throughput. No request needs to be traced: if the database is 45% busy while the service completes 50 requests/s, each request costs it 9 ms. Measure at a few load levels to check that the demand stays constant (it does not if caches warm up, or locks start to contend).
The response time is the sum of the tiers’ delays, but its growth comes almost entirely from the queue at the busiest tier. The front end at 42% and the application at 63% add little; the database at 95% adds hundreds of ms. Find the busiest resource first, because that is where the latency comes from.
5.2 The bottleneck moves
Part B adds one server at a time to whichever tier limits the service, assuming the database can grow to at most 3 servers:
| Step | servers (FE, app, DB) | max throughput | bottleneck |
|---|---|---|---|
| 0 | (1, 1, 1) | 83/s | application |
| 1 | (1, 2, 1) | 111/s | database |
| 2 | (1, 2, 2) | 167/s | application |
| 3 | (1, 3, 2) | 222/s | database |
| 4 | (1, 3, 3) | 250/s | front end (tied with application) |
| 6 | (2, 4, 3) | 333/s | application |
| 7 | (2, 5, 3) | 333/s | database: stuck |
Fixing a bottleneck exposes the next one. The stateless tiers (front end, application) can always be scaled out, since any server can serve any request. The tier that holds state — the database — is where scale-out ends. More database servers need replication (Lecture 19), partitioning (Lecture 25), or both, each with its own costs.
5.3 Caching moves the limit
Before scaling the database, remove work from it. Part C puts a cache in front of the database (Lecture 6), with servers (3, 6, 3):
| Cache hit ratio | DB demand per request | max throughput | bottleneck |
|---|---|---|---|
| 0% | 9.0 ms | 333/s | database |
| 50% | 4.5 ms | 500/s | application |
| 80% | 1.8 ms | 500/s | application |
| 90% | 0.9 ms | 500/s | application |
A 50% hit ratio raised the ceiling by half, after which the application tier became the bottleneck and further hits bought nothing until it was scaled too. A cache is capacity for the tier that cannot be scaled, but only up to the next bottleneck.
5.4 Closed systems: users who wait
The analysis so far was open: requests arrive at a given rate, whatever happens. Many systems are closed: a fixed population of N users, each of whom sends a request, waits for the answer, thinks for Z seconds, and sends the next. A slow system then slows its own users down. Mean Value Analysis (Reiser and Lavenberg) computes such networks exactly for single-server stations, using the arrival theorem: an arriving user sees the network as it would be with one user fewer. Part D, servers (1, 2, 1), Z = 1 s:
| Users | throughput | bound min(N/(D+Z), Xmax) | response | bound max(D, N/Xmax − Z) |
|---|---|---|---|---|
| 1 | 1.0/s | 1.0 | 25.0 ms | 25.0 |
| 50 | 48.3 | 48.8 | 34.8 | 25.0 |
| 100 | 93.3 | 97.6 | 72.0 | 25.0 |
| 120 | 106.2 | 111.1 | 130.1 | 80.0 |
| 150 | 111.1 | 111.1 | 350.4 | 350.0 |
| 200 | 111.1 | 111.1 | 800.0 | 800.0 |
Throughput grows with users along until the knee at users, then stays flat at . Beyond the knee every extra user only adds response time, . In an open system the response time blows up as the arrival rate approaches capacity; in a closed one, throughput saturates instead. Real services are in between: users retry, abandon, or open more tabs. Load tests must say which model they impose, because a closed-loop load generator cannot overload a server the way real traffic can (Lecture 12: coordinated omission).
6. Elasticity
6.1 The value
Cloud capacity can be rented by the hour, or by the minute. If load varies, capacity can follow it. 05_elasticity.py takes a day of traffic: mean 621 requests/s, a noon peak of 1,165, and a 3× flash crowd at 20:00 reaching 1,575. Service time is 10 ms and the target is that at most 20% of requests wait. Each 5-minute interval is sized with Erlang C:
| Provisioning | max servers | server-hours / day | requests missing the target |
|---|---|---|---|
| static for the flash crowd | 21 | 504 | 0% |
| static for the daily peak | 16 | 384 | 5.18% (all in the flash crowd) |
| static for the mean load | 10 | 240 | 64.4% |
| elastic, instant (oracle) | 21 | 230 | 0% |
| elastic, 5 min behind, +10% headroom | 23 | 248 | 0.88% |
| elastic, 20 min behind, +10% headroom | 23 | 248 | 5.06% |
- Elasticity saved 54% against sizing for the worst five minutes of the day, with the same quality. The saving is set by the load’s peak-to-mean ratio (2.5×).
- Sizing for the daily peak missed exactly the flash crowd: 16 servers could keep up with 1,575 requests/s, but 93% of those requests had to wait.
- Sizing for the mean failed 64% of requests. Averages are not capacity plans.
- Real elasticity lags. A new server takes minutes to start, and a controller reacting to measured load is always behind. Reacting to the load of 5 minutes ago missed 0.9% of requests, 20 minutes ago 5.1%, almost all during the flash crowd and the morning ramp, where load rises faster than servers arrive.
This demo is quasi-static. It treats each interval as steady state and ignores the backlog an overloaded interval leaves behind, which flatters the lagging policies. Lecture 12 simulates the dynamics: what to measure, how often to decide, how to avoid oscillating, and when to predict instead of react.
6.2 Costs beyond servers
Elasticity also has costs of its own:
- cold caches in new servers (Lecture 6), which make a fresh server slower than a warm one;
- state migration for stateful tiers;
- connection draining when removing servers;
- minimum billing periods.
These argue for some headroom and for scaling stateless tiers first.
7. A summary of the tools
| Question | Tool | What it says |
|---|---|---|
| how many requests are in flight? | Little’s law | L = λW, always |
| how busy is a server? | utilization law | U = λS/k |
| how bad is latency at load ρ? | M/M/1, M/G/1 (P-K), Kingman | ∝ ρ/(1 − ρ) × (variability)/2 × S |
| how many servers? | Erlang C, square-root staffing | k ≈ a + β√a |
| one big or many small? | M/M/1(kμ) vs M/M/k vs k × M/M/1 | big wins at low load; pooling closes the gap; separate queues waste |
| how to balance? | JSQ, power of two, least work | sample two at random; beware stale data |
| what limits the service? | bottleneck law | X ≤ min k_i/D_i |
| users who wait for answers? | MVA, asymptotic bounds | knee at N* = (D + Z) X_max |
| fixed or elastic capacity? | per-interval staffing | saving ≈ 1 − mean/peak, minus the cost of lag |
Summary
- Little’s law (L = λW) held within 0.01% on every system; it is accounting, not a model.
- The hockey stick:
- M/M/1 response time is : 2× the service time at 50% load, 10× at 90%, 20× at 95%;
- at 90%, the p99 was 474 ms for a 10 ms job;
- variability multiplies waiting by (1 + SCV)/2: constant service waited 20 ms, exponential 39 ms, SCV 4 103 ms at the same 80% load.
- Scale up vs out: one 8× server won at light load (1.8 vs 10.0 ms); a pool of 8 caught up under load (19.8 vs 13.5 ms at 90%); 8 separate random queues were 5× worse (99.7 ms).
- Staffing: spare capacity grows like √load. Keeping waits rare needed 3 servers at load 1 (33% busy) and 4,068 at load 4,000 (98% busy) — the statistical case for big pools.
- Load balancing:
- at 90% load, random 97.5 ms, round robin 56.8, power of two 29.6, JSQ 18.9, shared queue 16.5;
- least work equals the shared queue exactly;
- stale information makes “least loaded” herd (420 ms at a 100 ms refresh), while two random choices degrade gracefully, though not at any staleness.
- Multi-tier:
- the bottleneck law caps throughput (111/s at the database);
- the queue at the busiest tier is the latency;
- fixing one bottleneck exposes the next, until the stateful tier stops scale-out (333/s);
- a cache lifts that limit, up to the next bottleneck (500/s).
- Closed systems saturate in throughput instead of exploding in latency; beyond the knee, R = N/Xmax − Z.
- Elasticity saved 54% of server-hours with an oracle, but reacting 20 minutes late missed 5% of requests, mostly in the flash crowd.
Common pitfalls
- Planning for average load. Latency is set by peaks, bursts and variability, not the mean.
- Running a server near 100% because “it can still keep up”. It can, at 1/(1 − ρ) times the latency.
- Benchmarking with constant request sizes and evenly spaced arrivals. That removes exactly the variability that causes queues.
- Separate queues with random assignment, then wondering why latency is high while some servers idle.
- “Least connections” with variable request sizes. Count work, not requests.
- Load decisions on stale shared information without randomization. That is the herd effect.
- Scaling the tier you can, not the tier that limits you. Compute first.
- A closed-loop load test against an open-loop world (or the reverse).
- Forgetting the lag in elasticity: boot time plus measurement interval plus decision interval.
Exercises
-
Little’s law at work. A service handles 2,000 requests/s with a mean latency of 50 ms; each request holds a database connection for 20 ms of that. (a) How many requests are in flight on average? (b) How many database connections are in use on average? (c) The connection pool has 30 connections. What happens?
Answer
(a) L = λW = 2,000 × 0.05 = 100 requests. (b) Little's law applied to the connection pool alone: 2,000 × 0.02 = 40 connections busy on average. (c) A pool of 30 is smaller than the average demand of 40: requests queue for connections, waiting adds to latency, and latency adds to connections held — the system saturates at 30 / 0.02 = 1,500 requests/s, below the offered 2,000. The pool needs well over 40 connections (Erlang C on the pool, §3.2). -
The hockey stick by hand. One server takes 5 ms on average (exponential); requests arrive as a Poisson process. Compute the mean and 99th-percentile response at 160 and 180 requests/s.
Answer
μ = 200/s. At 160/s: W = 1/(200 − 160) = 25 ms; p99 = ln(100)/40 ≈ 115 ms. At 180/s: W = 1/20 = 50 ms; p99 ≈ 230 ms. An increase of 12.5% in load doubled both. (Checked with `queueing.mm1` and `mm1_quantile`.) -
Variability. A server is 70% busy with a 10 ms mean service time and Poisson arrivals. What is the mean wait if service is constant, exponential, or has SCV 9 (a few huge requests)? What could you change to get the SCV-9 case closer to the constant one?
Answer
P-K: W_q = 0.7/0.3 × (1 + SCV)/2 × 10 ms: 11.7 ms (constant), 23.3 ms (exponential), 116.7 ms (SCV 9). Remedies: route the huge requests to their own pool so they stop delaying small ones; split huge requests into pieces; or bound their size. Adding servers helps too, but separating the classes attacks the cause. -
Staffing. Requests arrive at 900/s; a server handles 100/s (exponential). How many servers keep the probability of waiting at or below 10%? What is their utilization, and the mean wait?
Answer
`servers_for(900, 100, target_pwait=0.1)` gives k = 14: P(wait) = 8.9% (13 servers give 15.8%), utilization 64%, mean wait 0.18 ms. The square-root rule says k ≈ 9 + β·3; β ≈ 1.7 for this stricter target. -
Two choices. Explain in your own words why sampling two servers is so much better than one, and why sampling three adds little. Then explain why two choices with old information behave better than “least loaded” with the same information.
Answer
With one random choice, a server's load is the sum of many independent random assignments; some servers get unlucky, and the most loaded one is noticeably above average. With two choices, a request lands on a long queue only if *both* samples are long, which is far less likely, so long queues stop growing; the theory says the maximum load improves from log n / log log n to log log n (exponentially). A third choice only changes the constant (log log n / log 3). With stale information, "least loaded" is deterministic: every balancer and every request agrees on the same "best" server. Two random samples disagree from request to request, so the herd is spread over many servers. -
Bottleneck. Demands per request: front end 3 ms (2 servers), application 20 ms (4 servers), database 6 ms (1 server). (a) What is the maximum throughput, and which tier limits it? (b) The team adds 4 application servers. What changes? (c) A cache absorbs 60% of database queries. What now?
Answer
(a) k/D: front end 2/0.003 = 667/s, application 4/0.020 = 200/s, database 1/0.006 = 167/s: the database caps it at 167/s. (b) Nothing: 8 application servers allow 400/s, but the database still caps at 167/s. (c) DB demand becomes 2.4 ms, so the database allows 417/s. With 4 application servers the application (200/s) is now the bottleneck; with 8 it still is (400/s), just below the database (417/s). Always recompute every k_i/D_i after a change. -
A closed system. Demands total D = 25 ms (bottleneck allowing 111 requests/s); users think Z = 2 s between requests. Where is the knee? What response time do 300 users see?
Answer
N* = (D + Z) X_max = 2.025 × 111 ≈ 225 users. At 300 users the system is saturated: X = 111/s and R = N/X − Z = 300/111 − 2 ≈ 0.70 s (MVA gives 0.700 s for this network). Each user beyond the knee adds about 9 ms (1/X_max) to everyone's response time. -
Lag and headroom. A service can add servers, but each takes 10 minutes to become useful. Its load can triple within 2 minutes (a link on a popular page). (a) How much headroom must it keep to survive such a surge without falling behind? (b) What does that do to the benefit of elasticity? (c) Name two other ways out.
Answer
(a) Enough for 3× the current load, since nothing new arrives in time: the pool must be sized for the surge, not for the current load. (b) For services exposed to such surges, reactive elasticity saves little during the hours when a surge is possible. Its value comes back for slow, predictable changes (the daily curve, §6.1). (c) Cut the lag: keep warm standby servers, or use lightweight containers or functions that start in seconds. Predict: forecast from the daily pattern, or from leading signals such as a page's sudden popularity (Lecture 12). Degrade gracefully: shed load, or serve cached or simplified responses until capacity arrives.
Related project and problem set (concepts only)
-
Project 3 scales tiers of a simulated service under changing load at low cost. The concepts in §§2–6 are the background:
- utilization and the hockey stick (why not to run at 100%);
- the bottleneck law (which tier to scale);
- pooling and balancing (how requests should be spread);
- elasticity with lag (why to scale before it hurts).
How to measure load in the project’s framework, when to add or remove servers, and how to balance across them are your design (and Lecture 12’s general subject). No project interface is described here.
-
Problem Set 3’s tier-sizing question uses the same operational laws (§5.1) and queueing formulas (§2–3). Its numbers and answers are not here.
Further reading
- M. Harchol-Balter, Performance Modeling and Design of Computer Systems: Queueing Theory in Action, Cambridge University Press, 2013 — the best modern textbook; chapters on M/M/k, M/G/1 and load balancing.
- E. D. Lazowska et al., Quantitative System Performance, Prentice Hall, 1984 (free online) — operational analysis and MVA.
- J. D. C. Little, “A Proof for the Queuing Formula L = λW”, Operations Research 9(3), 1961.
- M. Mitzenmacher, “The Power of Two Choices in Randomized Load Balancing”, IEEE TPDS 12(10), 2001; and “How Useful Is Old Information?”, IEEE TPDS 11(1), 2000.
- S. Halfin and W. Whitt, “Heavy-Traffic Limits for Queues with Many Exponential Servers”, Operations Research 29(3), 1981.
- J. Dean and L. A. Barroso, “The Tail at Scale”, CACM 56(2), 2013.
- Y. Lu et al., “Join-Idle-Queue: A Novel Load Balancing Algorithm for Dynamically Scalable Web Services”, Performance Evaluation 2011 — balancing with many dispatchers.
Preview of Lecture 12 — Control loops, feedback and instrumentation
The elastic pool of §6 knew the load; a real one must measure it, decide, and wait minutes for new servers, while the load keeps moving. Lecture 12 treats autoscaling as a feedback control loop. Which signal should it watch — utilization saturates, queues lag, latency is noisy? What do delays in the loop do (oscillation)? How do hysteresis, damping and prediction help? And how should a nondeterministic system be measured at all: warm-up, variance, confidence intervals, coordinated omission, and tracing a request through many tiers.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| queueing theory / queue | 排队论 / 队列 |
| arrival rate (λ) / service rate (μ) | 到达率 / 服务率 |
| utilization (ρ) | 利用率 |
| offered load | 提供负载 |
| response time / waiting time | 响应时间 / 等待时间 |
| Little’s law | 利特尔定律 |
| utilization law / bottleneck law | 利用率定律 / 瓶颈定律 |
| operational analysis | 运行分析(操作分析) |
| service demand | 服务需求 |
| Kendall notation (M/M/1, M/G/1, M/M/k) | 肯德尔记号 |
| Poisson process / exponential distribution | 泊松过程 / 指数分布 |
| squared coefficient of variation (SCV) | 平方变异系数 |
| Pollaczek–Khinchine formula | 波拉切克–辛钦公式 |
| Kingman’s approximation | 金曼近似 |
| hockey-stick curve | 曲棍球棒曲线 |
| tail percentile (p99) | 尾部百分位(第 99 百分位) |
| scale up / scale out | 纵向扩展 / 横向扩展 |
| pooling / resource pool | 资源池化 / 资源池 |
| Erlang C / Erlang B | 埃尔朗 C 公式 / 埃尔朗 B 公式 |
| square-root staffing | 平方根配置法则 |
| economies of scale | 规模经济 |
| load balancer / dispatcher | 负载均衡器 / 分派器 |
| round robin | 轮询 |
| join the shortest queue (JSQ) | 加入最短队列 |
| power of two choices | 两选一的力量(随机双选) |
| least work left | 最少剩余工作 |
| stale information / herd effect | 过期信息 / 羊群效应 |
| multi-tier architecture | 多层架构 |
| front end / application tier / database tier | 前端 / 应用层 / 数据库层 |
| stateless / stateful tier | 无状态层 / 有状态层 |
| open system / closed system | 开放系统 / 封闭系统 |
| think time | 思考时间 |
| Mean Value Analysis (MVA) | 均值分析法 |
| asymptotic bounds / knee | 渐近界 / 拐点 |
| capacity planning | 容量规划 |
| elasticity / provisioning | 弹性 / 资源供给 |
| flash crowd | 突发流量(闪电人群) |
| headroom | 余量 |
| peak-to-mean ratio | 峰均比 |