Maps to: CMU 15-440/640 Spring 2026, learning outcome “control loops and feedback” (under failures and fault tolerance), and the theme “instrumentation, monitoring and debugging”. Project: P3 must add and remove capacity as load changes. This lecture teaches control-loop ideas in general; it contains no P3 code, uses no P3 interface, and its numbers come from its own toy world. Problem set: PS3 touches scaling decisions; the scenarios and numbers here are different. Sources:
- K. J. Åström and R. M. Murray, Feedback Systems: An Introduction for Scientists and Engineers (2008/2021);
- J. L. Hellerstein, Y. Diao, S. Parekh and D. M. Tilbury, Feedback Control of Computing Systems (Wiley 2004);
- B. H. Sigelman et al., Dapper, a Large-Scale Distributed Systems Tracing Infrastructure (Google Technical Report 2010);
- G. Tene, How NOT to Measure Latency (talks, 2013–2016; coordinated omission);
- J. Dean and L. A. Barroso, The Tail at Scale (CACM 2013);
- R. Jain, The Art of Computer Systems Performance Analysis (Wiley 1991);
- B. Efron and R. Tibshirani, An Introduction to the Bootstrap (1993).
The slides are not public; this is not a transcript. Every number comes from
code/lecture12/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Most numbers are simulations; the RPC timings in §6.1 are real measurements and vary from run to run. Code:code/lecture12/. Reading time: ~85 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:
- Describe an autoscaler as a feedback loop (sensor, controller, actuator, plant), name the delays in each part, and explain how delay causes overshoot and oscillation.
- Use hysteresis, cooldowns, smoothing and asymmetric damping to stop a controller from chasing noise, and say what each costs in reaction time.
- Choose a scaling signal, and explain why utilization saturates, latency lags, and demand (arrival rate plus backlog) leads.
- Say when prediction beats reaction, why it must be combined with feedback, and what headroom insures against.
- Measure a nondeterministic system honestly: warm-up, run-to-run variance, confidence intervals (t and bootstrap), coordinated omission, and the sample sizes that tail percentiles need.
- Explain distributed tracing: spans, trace context, why timestamps from different machines cannot be compared, critical-path analysis, and tail-based sampling.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 11: queueing, utilization, the pooled queue, elasticity;
- Lecture 10: agility vs stability, estimators;
- Lecture 3: the RPC system we time in §6;
- Lecture 1: dsim and per-node clocks.
- Scope: control of capacity, and measurement and tracing of distributed services. Logical clocks (how to order events without synchronized clocks) are Supplement S1. Failure detection — another feedback loop — begins in Lecture 13.
0.3 Section → code map
| Section | Idea | Demo in code/lecture12/ |
|---|---|---|
| §2 | the loop, its delays, overshoot | 01_feedback_loop.py |
| §3 | hysteresis, cooldown, damping | 02_hysteresis_and_damping.py |
| §4 | which signal to control on | 03_scaling_signals.py |
| §5 | prediction, headroom | 04_predictive_scaling.py |
| §6 | measuring nondeterministic systems | 05_measuring_nondeterminism.py |
| §7 | distributed tracing | 06_tracing.py |
| all | a server pool under a controller | autoscale.py |
0.4 Notation and setting
- The simulated service (
autoscale.py): requests take 100 ms on average (exponential), so one server handles 10 requests/s. Servers share one queue, as in Lecture 11’s pool. - The controller runs every tick (10 s), measuring over a window (10 s). A new server is useful only after its boot time (30–300 s).
- SLO: a request slower than 0.5 s misses it. Cost: server-hours, booting servers included.
- Actions: decisions that changed the pool. Reversals: changes of direction (up then down, or down then up).
1. Why control theory?
1.1 The intuition
You adjust a shower that responds slowly. The water is cold, so you turn the tap toward hot. Nothing happens for a few seconds, so you turn it further. Then scalding water arrives, you overcorrect toward cold, and the cycle repeats. Nothing is broken: the valve works and so does your sense of temperature. What causes the oscillation is the delay between your action and its effect, combined with reacting to what you feel now instead of to what is already on its way.
An autoscaler is that shower. It measures load, starts servers, and waits minutes for them to boot while the load keeps moving. It also faces the shower’s other problem: the temperature you feel fluctuates even when nobody touches the tap. A controller that reacts to every fluctuation never settles.
1.2 The loop
Every self-managing system has the same structure:
┌──────────── measurement delay (window) ─────────────┐
▼ │
SENSOR ──► CONTROLLER ──► ACTUATOR ──(boot delay)──► PLANT ─────┘
rate, utilization, desired servers start / stop the queueing system
queue, latency servers (Lecture 11)
Each arrow has a delay:
- the measurement window averages the past;
- the tick spaces decisions apart;
- the actuator takes a boot time to deliver;
- the plant itself has inertia: a backlog built during an overload must still be drained after capacity arrives.
The loop’s behavior — fast or slow, smooth or oscillating — depends on the delays as much as on the rule.
The same loop appears throughout these notes: TCP congestion control (Lecture 9: sense loss, cut the window, wait a round trip), adaptive bitrate (Lecture 10), failure detectors (Lecture 13), and the lease renewals of Lecture 7. Control theory names the parts and the failure modes. Even without its mathematics, its vocabulary — gain, delay, overshoot, stability, dead band, feed-forward — is what lets you design these loops instead of tuning them blindly.
2. Delay: why loops overshoot
2.1 Boot time sets how long users suffer
01_feedback_loop.py triples the load at t = 10 minutes, from 3 to 9 servers’ worth of work. Its controller is proportional: it sets the pool to ready × utilization / 0.6, aiming for 60% utilization. Part A varies the boot delay:
| Boot delay | SLO misses | p99 | enough servers ready after | server-hours |
|---|---|---|---|---|
| 0 s | 1.3% | 0.6 s | 20 s | 13.8 |
| 30 s | 3.4% | 11.1 s | 40 s | 13.7 |
| 60 s | 6.0% | 26.9 s | 100 s | 13.7 |
| 120 s | 17.2% | 77.7 s | 220 s | 13.5 |
Two things slow it down:
- The boot itself. Nothing helps until the new servers exist.
- Saturation of the sensor. Utilization cannot exceed 100%, so one decision can grow the pool by at most 1/0.6 = 1.67×. Tripled load needs about two rounds, and each round waits a full boot.
The p99 of 77.7 s at a 120 s boot is not the boot itself. It is the backlog: requests that arrived while capacity was short must still be served after the servers arrive.
2.2 Forgetting what is on order: overshoot
Part B changes one detail. Each tick, the controller adds its computed shortfall to the servers already ordered, instead of setting an absolute target. It forgets that the servers it ordered last tick are still booting:
| Boot delay | max servers (10 needed) | SLO misses | reversals | server-hours |
|---|---|---|---|---|
| 0 s | 18 | 1.3% | 178 | 13.8 |
| 30 s | 25 | 2.4% | 108 | 14.6 |
| 60 s | 37 | 3.9% | 80 | 16.0 |
| 120 s | 62 | 6.2% | 53 | 19.0 |
With a 120 s boot, every one of the 12 ticks during the boot re-ordered the same shortfall, so the pool reached 62 servers for a load that needed 10. Then the controller had to shed them, and the oscillation continued for the rest of the hour. This is the shower: reacting to the current state while ignoring the correction already in flight. In control terms, delay plus high gain gives overshoot and ringing.
One honest surprise: the over-ordering controller recovered faster (130 s vs 220 s) and missed fewer requests (6.2% vs 17.2%). Over-ordering is a crude form of aggressiveness, paid for with 41% more server-hours and a pool that never settles. The fix is to account for capacity in flight and be aggressive on purpose: order the right amount, once (§4).
2.3 Gain: too little is also a failure
Part C (boot 60 s):
| Controller | enough servers ready after | SLO misses |
|---|---|---|
| threshold: +1 server per tick | 110 s | 6.4% |
| threshold: +1, and wait for each boot | 310 s | 19.1% |
| proportional (absolute) | 100 s | 6.0% |
A cautious rule (one server at a time, and never order more while one is booting) cannot overshoot, but it takes five boot cycles to triple the pool. Gain — how much the controller changes per unit of error — must be large enough to follow real changes, and delay limits how large it can safely be.
3. Noise: hysteresis and damping
3.1 Flapping
A measured utilization fluctuates even when the load’s mean is constant: Poisson arrivals, variable service times, a 10-second window. A controller that reacts to every fluctuation adds and removes servers constantly. That is flapping, and it is not free: every added server is a boot and a cold cache (Lecture 6), and every removal is connections to drain and work to migrate.
02_hysteresis_and_damping.py Part A runs six controllers for two hours on a load that only fluctuates around 60 requests/s (6 servers’ worth):
| Controller | actions | reversals | server-hours | SLO misses |
|---|---|---|---|---|
| single threshold (add above 60%, remove below 60%) | 450 | 90 | 28.7 | 0.69% |
| dead band 40%–80% | 33 | 6 | 25.4 | 0.81% |
| dead band + 5 min cooldown | 8 | 2 | 23.2 | 0.72% |
| proportional on utilization | 425 | 328 | 24.1 | 0.72% |
| target tracking on the arrival rate | 163 | 92 | 24.8 | 0.68% |
| target tracking, EWMA + patient scale-in | 73 | 20 | 24.6 | 0.68% |
Quality was the same for all (SLO misses ≈ 0.7%). That is the floor set by the service time itself: P(a 100 ms exponential job takes > 0.5 s) = e^−5 ≈ 0.7%. The number of actions varied 56-fold. The remedies:
- Hysteresis (a dead band): different thresholds for adding (80%) and removing (40%). Between them, do nothing. A thermostat works this way.
- Cooldown: after acting, wait. This gives the action time to take effect before judging it.
- Smoothing: an EWMA (Lecture 10) on the measured rate removes high-frequency noise, at the price of lag.
- Patience (damping): scale in only after several consecutive ticks agree.
3.2 The price of calm
Part B then steps the load to 2.5× (from 6 to 15 servers’ worth):
| Controller | 16 servers ready after | SLO misses |
|---|---|---|
| single threshold | 100 s | 7.5% |
| dead band 40–80% | 120 s | 8.9% |
| dead band + 5 min cooldown | 1,570 s | 71.5% |
| target tracking (rate) | 70 s | 4.6% |
| target tracking, EWMA + patient scale-in | 80 s | 5.5% |
The cooldown, which made the steady state so calm, made the controller nearly deaf to a real change: +1 server every 5 minutes. Calm and responsiveness pull against each other, as agility and stability did in Lecture 10. The engineering answer is asymmetry:
- react quickly to rising load, because it hurts users;
- react slowly to falling load, because it only costs money.
The damped target tracker does exactly that. Its patience applies only to scale-in, so it took 73 actions instead of 163 on the noisy load and still reacted to the step in 80 s.
4. Which signal?
4.1 What each signal says during an overload
A control loop is only as good as its sensor. 03_scaling_signals.py jumps the load 5× (from 3 to 15 servers’ worth) and prints what each signal reads:
| Time | ready | booting | utilization | arrival rate | queue | p95 latency |
|---|---|---|---|---|---|---|
| 600 s | 5 | 1 | 64% | 29/s | 0 | 0.38 s |
| 610 s | 5 | 1 | 100% | 150/s | 1,031 | 18.9 s |
| 640 s | 5 | 1 | 100% | 150/s | 4,038 | 68.0 s |
| 700 s | 6 | 4 | 100% | 152/s | 9,612 | 97.8 s |
- Utilization saturates. It read 100% whether the load was 1.1× or 5× the capacity, so it says that the pool is too small but not by how much.
- The arrival rate reads the demand directly (150/s means 15 servers’ worth), but it needs to know the cost of a request.
- The queue measures the backlog that the new capacity must also clear.
- Latency is what users feel and what the SLO is written in, but it moves only as the queue builds, so it reports damage already done.
4.2 Controllers on each signal
| Signal | enough servers ready after | back to normal after | SLO misses | max servers |
|---|---|---|---|---|
| utilization threshold, +1 | 160 s | 340 s | 16.3% | 25 |
| utilization, proportional | 170 s | 380 s | 18.6% | 29 |
| arrival rate (target 60%) | 70 s | 170 s | 7.7% | 27 |
| rate + queue (drain in 30 s) | 70 s | 140 s | 5.9% | 66 |
| rate + queue (drain in 120 s) | 70 s | 150 s | 6.8% | 37 |
| p95 latency (+2 when above 400 ms) | 310 s | 660 s | 32.8% | 28 |
Sizing from the arrival rate ordered the right number in one step. “Enough ready” then took one boot plus the measurement window, the minimum any reactive controller can achieve. Adding the queue to drain came back to normal fastest, by briefly ordering 66 servers to clear 10,000 queued requests within 30 s. Choosing the drain target trades a burst of cost against how long the backlog lingers.
The rule: control on signals that measure demand; monitor the signals that measure the outcome. Arrival rate and backlog lead; utilization saturates; latency lags. Latency still belongs on the dashboard and in the alerts, because it is the contract. It is just a poor input for the controller. When request costs vary (a cheap health check and an expensive search are both “one request”), measure demand in work, such as CPU-seconds requested, rather than in requests.
5. Prediction and headroom
5.1 When does forecasting help?
A reactive controller is always at least one boot time late. A predictive one sizes the pool for the load expected one boot time ahead. 04_predictive_scaling.py uses a day-like curve (compressed into a 2-hour cycle, 20–140 requests/s) plus a 2× flash crowd that nobody could predict. Boot time is 120 s:
| Controller | SLO misses | during the flash crowd | rest | server-hours |
|---|---|---|---|---|
| fixed for the peak (27 servers) | 0.65% | 0.11% | 0.55% | 53.9 |
| reactive: target tracking 60% | 4.52% | 3.96% | 0.56% | 29.9 |
| predictive: trend + feedback | 4.52% | 3.96% | 0.55% | 31.2 |
| predictive: known daily curve + feedback | 4.51% | 3.96% | 0.55% | 30.8 |
| oracle (true load one boot ahead) | 0.67% | 0.11% | 0.56% | 30.6 |
Prediction bought nothing here, and the reason is instructive. On a slow curve, the 40% headroom of a 60% target absorbs the ramp while new servers boot, so outside the flash crowd every controller sat at the service-time floor. Inside the flash crowd, no forecaster could know when it would start. Only the oracle avoided those misses.
Prediction pays when the future is known. Part B schedules a 3× surge for 10 minutes — a sale at 10:00, a push notification, the start of a class — and gives one controller the schedule:
| Controller | SLO misses (whole run) | in and after the surge | server-hours |
|---|---|---|---|
| reactive | 14.64% | 14.24% | 36.1 |
| predictive, knows the schedule | 0.68% | 0.29% | 38.9 |
Ordering servers one boot early turned a 14% disaster into the floor, for 8% more server-hours.
5.2 Headroom is insurance against surprises
For what cannot be predicted, the remedy is spare capacity: run at a lower target utilization (Part C, the flash-crowd load):
| Target utilization | SLO misses | during the flash crowd | server-hours |
|---|---|---|---|
| 40% | 0.66% | 0.11% | 44.4 |
| 50% | 0.74% | 0.19% | 35.6 |
| 60% | 4.52% | 3.96% | 29.9 |
| 70% | 5.72% | 5.09% | 25.9 |
| 80% | 7.49% | 6.56% | 22.7 |
Each point of target utilization trades money against the size of the surprise the pool can absorb during one boot. A 2× flash crowd needs the pool to run at 50% or less, or to boot faster (warm pools of pre-started servers, lightweight containers), or to degrade gracefully (shed or simplify work) until capacity arrives.
5.3 A forecast must be checked by feedback
Part D shows the failure of naive prediction: a straight line fitted to the last minute of noisy rate samples and extrapolated one boot ahead.
| Controller | boot | SLO misses | max servers |
|---|---|---|---|
| raw trend | 120 s | 20.6% | 69 |
| trend + feedback safeguards | 120 s | 4.5% | 35 |
| raw trend | 300 s | 99.9% | 129 |
| trend + feedback safeguards | 300 s | 9.4% | 45 |
Extrapolating noise far ahead amplifies it. The raw forecaster ordered 129 servers, then predicted a drop and cancelled servers that were still booting, again and again, until almost no request met its SLO. The safeguards that fixed it are general:
- never size for less than the smoothed measured load (feedback overrides a forecast that missed a surprise);
- never let a wobbling forecast cancel capacity still booting (patient scale-in).
Production autoscalers combine feed-forward (prediction, schedules) with feedback (reaction to measurement) for exactly this reason.
6. Measuring a system that never repeats itself
Everything above depends on measurements. Distributed systems are nondeterministic: caches, schedulers, CPU frequency, network timing and other tenants make every run different. Four traps catch almost everyone.
6.1 Warm-up and run-to-run variance (real)
05_measuring_nondeterminism.py Part A times Lecture 3’s real RPC system over loopback on this machine: 20 runs × 1,000 calls, each run on a new connection. These are real measurements, and they vary between runs of the demo:
| Quantity | value (one run of the demo) |
|---|---|
| median of the first 20 calls | 34.9 µs |
| median after discarding the first 100 calls | 29.3 µs |
| run-to-run range of that median | 25.5 – 34.4 µs |
| coefficient of variation across runs | 6.0% |
| 95% CI, Student t (df = 19, t = 2.093) | 29.3 ± 0.8 µs |
| 95% CI, bootstrap (4,000 resamples) | 28.7 – 30.2 µs |
| runs needed for a ±2% CI at this spread | ~40 |
-
Warm-up: the first calls of each run were ~20% slower. Likely causes are connection setup, cold caches and the CPU leaving a low-power state; we did not instrument which. Discard a warm-up period, and say that you did.
-
Run-to-run variance: one run’s median could be anywhere from 25.5 to 34.4 µs. A single run is an anecdote. Run several times and report the mean with a confidence interval.
- The t interval assumes roughly normal run means.
- The bootstrap makes no such assumption: resample the runs with replacement thousands of times and take the spread of the resampled means.
The two agreed here.
-
Sample size: the CI half-width shrinks as . Halving it costs four times the runs, so decide the precision you need before you measure.
6.2 Coordinated omission
Part B models a server that freezes for 300 ms every 3 s (a garbage-collection pause, say) and otherwise answers in 1 ms. The load generator intends 200 requests/s.
| Load generator | requests measured | p50 | p99 | p99.9 |
|---|---|---|---|---|
| closed loop (waits for each reply, measures from the actual send) | 10,820 | 1.0 ms | 1.0 ms | 300 ms |
| open loop (sends on schedule, measures from the intended time) | 12,000 | 1.0 ms | 277 ms | 301 ms |
During each stall, the closed-loop generator sends one request, waits 300 ms for it, and records one slow sample. The 60 requests that real users would have sent during the stall are never sent, so they are never counted. Tene calls this coordinated omission: the measurement tool coordinates with the system under test and politely omits exactly the samples that matter. It reported a p99 of 1 ms for a system whose real p99 is 277 ms.
Remedies:
- generate load open-loop, on a schedule independent of the responses;
- or correct closed-loop data by measuring each request from its intended send time.
Lecture 11’s closed systems are real, too. Choose the model that matches how your users behave.
6.3 Warm-up bias and noisy tails in simulation
Simulations have the same traps. Part C starts an M/M/1 queue at 90% load empty. Its true steady-state mean response is 100 ms:
| Requests per run | mean latency (10 runs) | range over runs |
|---|---|---|
| 100 | 53.5 ms | 15.8 – 116.6 ms |
| 1,000 | 84.1 ms | 51.7 – 178.9 ms |
| 10,000 | 103.4 ms | 82.2 – 147.3 ms |
| 100,000 | 101.2 ms | 95.9 – 119.6 ms |
Short runs from an empty start are biased low, because the queue has not filled yet, and noisy. This is why every simulation in these notes discards a warm-up period.
Tail percentiles need many samples. p99 estimates from 100 consecutive steady-state samples ranged from 47 to 339 ms (true value 461 ms), and from 10,000 samples, 266–555 ms. Consecutive requests in a busy queue are correlated, since they wait behind the same backlog, so 10,000 of them carry far less information than 10,000 independent samples. A p99 computed from a few hundred requests is mostly noise. A p99.9 needs ten times more samples, and comparisons of tails need several independent runs.
7. Distributed tracing
7.1 Spans and trace context
When one user request touches dozens of services, logs from each service are not enough. You need to know which log lines belong to the same request and how the services’ work nested. Distributed tracing (Dapper; then Zipkin, Jaeger, OpenTelemetry) works like this:
- the entry point assigns a trace id;
- every call carries the trace id and the caller’s span id (the trace context) in its metadata;
- every service records a span — trace id, span id, parent span id, name, start, end — on its own clock;
- spans are shipped to a collector, which assembles them into a tree.
06_tracing.py builds this on Lecture 1’s simulator:
- a gateway calls a front end;
- the front end calls an auth service, then a catalog and a recommender in parallel, then renders;
- the catalog queries a database twice.
The six services’ clocks are offset by −8 to +5 ms, and 2,000 requests are traced.
7.2 Clocks lie; durations and causality don’t
One trace, as each service’s clock recorded it:
service span parent start (local clock) duration
db db-15 catalog-8 139.12 1.53 STARTS BEFORE ITS PARENT
gateway gateway-8 client-7 140.95 14.84
auth auth-8 frontend-8 141.87 0.69 STARTS BEFORE ITS PARENT
...
catalog catalog-8 frontend-8 150.80 6.59
The database’s query “started” 11 ms before the catalog that issued it, because the database’s clock is 8 ms behind and the catalog’s 5 ms ahead. Across all traces, 7,886 of 12,000 parent–child pairs looked impossible on raw timestamps. Clock synchronization (NTP, PTP) shrinks the error, but never to zero; Lecture 1 explained why no global clock exists.
Two things are trustworthy:
- durations, because each span’s start and end come from the same clock;
- causality, from the parent–child links: a child happened during its parent’s call.
Order across machines must come from causal links, not from timestamps. Supplement S1 makes this precise with logical clocks.
7.3 The critical path
Which work actually decided the response time? At each parallel step only the slower branch matters, and the faster one runs in its shadow. Walking down the tree through the slowest child at each fan-out gives the critical path. Self time on it, in ms per request:
| Requests | gateway | frontend | auth | catalog | db | recommend |
|---|---|---|---|---|---|---|
| median or faster | 1.7 | 6.0 | 0.5 | 3.1 | 1.9 | 1.5 |
| slowest 5% | 1.7 | 6.0 | 0.6 | 4.0 | 46.3 | 0.0 |
(End-to-end: p50 18.0 ms, p95 55.3 ms, p99 59.6 ms.)
- Typical requests: the catalog branch was the slower one in 76% of them. The recommender’s own 4.9 ms mostly ran in the shadow of the catalog, so speeding it up would have changed almost nothing.
- The slowest 5%: the database’s occasional 40 ms queries were the whole story, 46 ms per request.
Averages over all requests would have pointed at the front end, the largest contributor in typical requests, and missed the cause of the tail. To fix tail latency, look at the traces of slow requests.
7.4 Which traces to keep
Tracing every request at full detail is expensive, so systems sample:
| Sampler | traces kept | of the 21 slowest (1%) requests |
|---|---|---|
| head-based: 1% chosen at random when the request starts | 20 | 0 |
| tail-based: keep traces that turned out slower than p95 | 101 | 21 |
Head-based sampling (Dapper’s original design) decides at the entry point, cheaply, but keeps the slow traces only by luck. Tail-based sampling decides after the request completes, so it can keep exactly the slow and failed ones. The price is that every span must be buffered until its trace is complete and the decision is made.
7.5 Logs, metrics, traces
The three pillars of observability answer different questions:
- metrics (counters, histograms of rates, utilization, latency percentiles) are cheap and aggregate, and feed the controllers of §§2–5 and the alerts;
- logs record discrete events with detail;
- traces connect the events of one request across services.
A good incident investigation goes from a metric (p99 rose), to traces (which requests, which service on the critical path), to logs (what that service was doing).
8. Design rules for control loops
| Rule | Because | Demo |
|---|---|---|
| Account for capacity in flight; set absolute targets | adding the shortfall every tick overshoots by about (boot / tick) × shortfall | 01 |
| Make gain large enough to follow real changes | +1 per tick needs many boot cycles | 01 |
| Use a dead band and asymmetric damping (fast up, slow down) | noise causes flapping; slowness on the way up costs users | 02 |
| Control on demand (rate, backlog), monitor outcomes (latency) | utilization saturates, latency lags | 03 |
| Predict what is known (schedules, daily curves), react to the rest | prediction removes the boot delay only for foreseeable changes | 04 |
| Never let a forecast override measurements or cancel booting capacity | noise extrapolated is noise amplified | 04 |
| Keep headroom for surprises, or boot faster | a pool absorbs only what fits in its headroom during one boot | 04 |
| Measure with warm-up discarded, several runs, CIs, open-loop load | single runs, closed loops and short runs lie | 05 |
| Order events across machines by causality, not timestamps | clocks disagree | 06 |
| Sample the tail | the interesting traces are rare | 06 |
Summary
- An autoscaler is a feedback loop with delays: measurement window, decision tick, boot time, and the backlog in the plant.
- With a 120 s boot, a proportional controller needed 220 s to recover from a tripled load (17.2% SLO misses vs 1.3% with instant boots).
- Forgetting servers already on order overshot to 62 servers for a need of 10 and kept oscillating; it was faster but cost 41% more.
- Too little gain (+1 per tick, waiting for each boot) took 310 s.
- Noise: a single threshold changed the pool 450 times in 2 hours on a load whose mean never moved. A dead band cut that to 33, a cooldown to 8, damped target tracking to 73, all at the same quality. But a 5-minute cooldown took 1,570 s to follow a real 2.5× step: damp scale-in, not scale-out.
- Signals: in a 5× overload, utilization read 100% and could say nothing more, while the queue reached 9,600 requests. Rate-based sizing had enough servers ready in 70 s (utilization-based: 160–170 s; latency-based: 310 s), and adding the backlog drained it fastest.
- Prediction:
- no help on a slow daily curve (headroom absorbs it) or against an unpredictable flash crowd (only the oracle avoided its 4% of misses);
- decisive for a scheduled surge (14.2% → 0.29% misses);
- headroom insures against surprises (40% target: 0.66% misses for 44 server-hours; 80%: 7.5% for 23);
- a raw trend forecast with a 300 s boot missed nearly every request.
- Measurement:
- real RPC timings showed a 20% warm-up penalty and a 6% run-to-run spread (29.3 ± 0.8 µs over 20 runs; ±2% would need ~40 runs);
- a closed-loop generator reported a p99 of 1 ms for a server whose on-schedule p99 was 277 ms (coordinated omission);
- an M/M/1 at 90% started empty looked half as slow as it is;
- p99 estimates from 100 samples ranged 47–339 ms.
- Tracing:
- raw timestamps from skewed clocks made 66% of parent–child pairs look impossible; durations and causal links are what to trust;
- critical-path analysis showed that tail latency had a different cause (the database) from typical latency;
- head-based 1% sampling kept none of the 21 slowest traces, tail-based kept all of them.
Common pitfalls
- Re-ordering capacity every tick while earlier orders are still booting. Count servers in flight.
- A single threshold, or a cooldown on scale-out. One flaps; the other is deaf.
- Controlling on utilization alone in an overload, or on latency at all. One saturates, the other lags.
- Forecasting without feedback, or letting a forecast cancel booting servers.
- Running at a high target utilization with slow boots and bursty load. Headroom is the insurance.
- One run, no warm-up discarded, no error bars.
- A closed-loop load generator reporting tail latency (coordinated omission).
- Short simulations started empty, and percentiles from a few hundred samples.
- Ordering events across machines by wall-clock timestamps.
- Optimizing what is off the critical path, or diagnosing tail latency from averages.
- Head-based sampling when the goal is to debug rare slow requests.
Exercises
-
Loop delay and headroom. An autoscaler measures over a 30 s window, decides every 10 s, and servers take 90 s to boot. Load can rise by one server’s worth every 20 s. (a) Roughly how stale is a decision by the time its servers serve? (b) How much headroom (in servers) does the pool need to absorb the rise while it waits? (c) What two changes would most reduce the headroom needed?
Answer
(a) The window reports, on average, the load ~15 s ago; a decision may wait up to a tick (~5 s on average); then the boot takes 90 s. About 110 s pass between the load the controller saw and the moment its servers help. (b) In 110 s the load can rise by 110 / 20 ≈ 5.5 servers' worth, so keep about 6 servers of headroom above the measured need. (c) Shorten the boot (warm pools, containers), since it dominates. Or predict the rise (feed-forward) instead of waiting to see it. Shrinking the window helps a little, but makes the signal noisier (§3). -
How far does a forgetful controller overshoot? A controller adds its full computed shortfall D to the pool every tick T, ignoring servers still booting, and servers take B to boot. Estimate the overshoot. Check it against demo 01 (shortfall about 5 servers, B = 120 s, T = 10 s; the pool reached 62).
Answer
Until the first new servers arrive, the shortfall it sees does not shrink, so it re-orders about D every tick: roughly D × B/T servers in total, here 5 × 12 = 60 extra on top of the initial 5, about 65, close to the observed 62. (The shortfall shrinks a little as utilization readings change.) The fix is to compute the shortfall against ready **plus booting** servers, or to set an absolute target. -
Sizing a dead band. At steady state the measured utilization has a mean of 60% and a standard deviation of 5 percentage points per 10 s window (roughly normal). (a) With add-above-60%, remove-below-60%, how often does the controller act? (b) Choose a dead band so that a noise-driven action happens less than about once an hour (360 ticks).
Answer
(a) Every tick: half the samples are above 60%, half below. That is the flapping of demo 02. (b) The chance that a sample leaves the band must be well under 1/360 ≈ 0.28%. For a normal variable, |z| > 3 has probability 0.27%, so the band must reach about 3σ = 15 points on each side: add above 75%, remove below 45%. Smoothing (an EWMA) reduces σ and allows a narrower band, at the price of lag. -
The wrong signal. A service has two kinds of request: a cheap status check (1 ms) and an expensive report (200 ms). One evening, the share of reports jumps from 2% to 20% while the total request rate stays the same. What does a controller sizing from the request rate do? What should it measure instead?
Answer
The request rate is unchanged, so it does nothing, while the work per second has risen about 8×: from 0.98 × 1 + 0.02 × 200 ≈ 5 ms per request on average to 0.8 + 40 ≈ 41 ms. The pool saturates. Measure demand in *work*: CPU-seconds requested, the rate weighted by measured per-type cost, or the backlog in seconds of work. Utilization also notices, but it saturates (§4). A queue-in-seconds signal both notices and says by how much. -
Little’s law on the dashboard. A dashboard shows 400 requests queued and an arrival rate of 200/s, with all servers busy. How long are new requests waiting? If the controller adds capacity for 250/s, how long until the queue is gone?
Answer
Little's law on the queue: wait ≈ 400 / 200 = 2 s. With capacity 250/s and arrivals 200/s, the queue drains at 50/s: 400 / 50 = 8 s, *after* the new servers are ready. This is why the rate + queue controller in §4 sizes for the arrivals *and* for clearing the backlog within a target time. -
Confidence intervals. Ten runs of a benchmark give a mean of 50 ms with a sample standard deviation of 5 ms across runs. (a) Give a 95% CI for the mean. (b) How many runs for ±1 ms? (c) Why is a CI over runs more honest than one over the 100,000 requests inside a single run?
Answer
(a) t(0.975, 9) = 2.262, so 50 ± 2.262 × 5/√10 = 50 ± 3.6 ms. (b) Solve t × 5 / √n ≤ 1: about 99 runs (t ≈ 1.98 there). Note the 4× rule: halving the interval costs 4× the runs. (c) Requests within a run are correlated (they share the run's cache state, CPU frequency, background activity and queue backlog), so treating them as independent makes the interval far too narrow. Runs are the independent units. -
Coordinated omission by hand. A server answers in 1 ms but freezes for 1 s every 10 s. A user population sends 100 requests/s on its own schedule. (a) What fraction of requests are delayed, and what is their mean delay? (b) Estimate the true p99. (c) What does a closed-loop tester with one outstanding request report as p99?
Answer
(a) Requests arriving during the 1 s freeze, 10% of them, wait until it ends: uniformly between 0 and 1 s, a mean of 0.5 s. (b) A latency above x occurs for a fraction (1 − x)/10 of requests (for x < 1 s); setting that to 1% gives x ≈ 0.9 s, so the true p99 is about 900 ms. (c) It sends one request per freeze that takes up to 1 s, and about 9,000 fast ones in the other 9 s: roughly 1 slow sample in 9,000, so its p99, and even its p99.9, is about 1 ms. It reports a 900× better tail than users see. -
Tracing design. Your traces show a child span starting 4 ms before its parent. (a) Is the system broken? (b) How would you order the two events correctly? (c) Your team wants to debug a 1-in-10,000 slow request. Which sampler, and what does it cost?
Answer
(a) Almost certainly not: the two services' clocks disagree by more than 4 ms. Clock offsets of milliseconds are normal between machines. (b) By causality: the parent sent the call before the child received it, which the parent–child link records. For finer ordering inside a service, use that service's own clock. Supplement S1's logical clocks make cross-machine order precise without synchronized clocks. (c) Tail-based sampling: decide after the request completes, keeping all traces above a latency threshold or with errors. The cost is buffering every span of every in-flight trace until its decision, plus a collector that can see whole traces. A 1% head-based sample would keep the slow request about once in 100 occurrences, so you would wait a long time.
Related project and problem set (concepts only)
-
Project 3’s scaling decisions are a feedback loop. §§2–5 give the concepts:
- account for capacity still starting up;
- avoid flapping with hysteresis and asymmetric damping;
- control on demand, not on saturating or lagging signals;
- keep headroom for the delays you cannot remove.
Which measurements the project’s framework offers, and the rules your controller uses, are your design. This lecture describes no project interface and gives no project code.
-
Problem Set 3’s scaling and failure questions draw on Lecture 11’s queueing and this lecture’s loop reasoning. The answers are not here.
Further reading
- K. J. Åström and R. M. Murray, Feedback Systems, Princeton University Press, 2nd ed. 2021 (free online) — chapters 1–2 for the vocabulary, the rest for the theory.
- J. L. Hellerstein et al., Feedback Control of Computing Systems, Wiley-IEEE, 2004 — control theory applied to servers.
- B. H. Sigelman et al., “Dapper, a Large-Scale Distributed Systems Tracing Infrastructure”, Google Technical Report dapper-2010-1.
- G. Tene, “How NOT to Measure Latency” (talk, 2015) — coordinated omission and HdrHistogram.
- J. Dean and L. A. Barroso, “The Tail at Scale”, CACM 56(2), 2013.
- R. Jain, The Art of Computer Systems Performance Analysis, Wiley, 1991 — experimental design, confidence intervals, warm-up.
- B. Beyer et al. (eds.), Site Reliability Engineering, O’Reilly, 2016 — chapters on monitoring, SLOs and load balancing (free online).
Preview of Lecture 13 — Failures I: what fails, how often, and why
Part III asked how to keep up with load. Part IV asks how to keep going when parts break, and they always do: disks, servers, networks, software and, most often, operators. Lecture 13 starts with numbers: MTBF, MTTR and availability, series and parallel compositions, the memoryless model of failure and when it is wrong, and what empirical studies found (Gray 1985, Oppenheimer 2003: operators and software dominate). It then looks at the remedies those studies suggest — fail-fast modules, process pairs, restart — and at what a long job running on flaky machines costs.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| feedback control loop | 反馈控制回路 |
| sensor / controller / actuator / plant | 传感器 / 控制器 / 执行器 / 被控对象 |
| control signal / setpoint (target) | 控制信号 / 设定值(目标) |
| gain | 增益 |
| delay (dead time) / lag | 延迟(纯滞后) / 滞后 |
| overshoot / oscillation / ringing | 超调 / 振荡 / 振铃 |
| stability | 稳定性 |
| flapping | 抖动(反复伸缩) |
| hysteresis / dead band | 迟滞 / 死区 |
| cooldown | 冷却期 |
| damping / smoothing | 阻尼 / 平滑 |
| proportional controller | 比例控制器 |
| target tracking | 目标跟踪(伸缩策略) |
| feed-forward / prediction | 前馈 / 预测 |
| headroom | 余量 |
| autoscaling / scale-out / scale-in | 自动伸缩 / 扩容 / 缩容 |
| boot time / warm pool | 启动时间 / 预热池 |
| service level objective (SLO) | 服务等级目标 |
| backlog / drain | 积压 / 排空 |
| leading / lagging indicator | 先行指标 / 滞后指标 |
| saturation | 饱和 |
| instrumentation / observability | 插桩(监测) / 可观测性 |
| metrics / logs / traces | 指标 / 日志 / 追踪 |
| warm-up period | 预热期 |
| run-to-run variance | 运行间方差 |
| confidence interval | 置信区间 |
| Student’s t distribution | 学生 t 分布 |
| bootstrap | 自助法 |
| coefficient of variation | 变异系数 |
| coordinated omission | 协同遗漏 |
| open-loop / closed-loop load generator | 开环 / 闭环负载生成器 |
| warm-up bias (initialization bias) | 预热偏差(初始化偏差) |
| distributed tracing | 分布式追踪 |
| trace / span / trace context | 追踪 / 跨度 / 追踪上下文 |
| parent span / child span | 父跨度 / 子跨度 |
| clock skew | 时钟偏差 |
| causality | 因果关系 |
| critical path | 关键路径 |
| head-based / tail-based sampling | 头部采样 / 尾部采样 |