14.1 · The performance vocabulary
Most performance arguments are vocabulary arguments. Pin down the words before the numbers.
| Term | Definition | Unit |
|---|---|---|
| Latency | Time for one request to traverse a path, end-to-end | ms |
| Response time | Latency observed at the client = service time + queue time + network | ms |
| Service time ($S$) | Time the server actually works on a request | ms |
| Queue time ($W_q$) | Time the request waits before being served | ms |
| Throughput ($X$ or $\lambda$) | Completed requests per second | req/s |
| Concurrency ($L$ or $N$) | Requests in flight at one instant | requests |
| Utilisation ($U$) | Fraction of time a resource is busy, $U = \lambda S$ | 0–1 |
| Saturation | Extra work queued because the resource is full | queue depth |
| Goodput | Throughput of useful work (excluding retries, errors) | req/s |
| Headroom | 1 − utilisation at peak, the safety margin | % |
14.2 · Queueing theory essentials
Every queue you cannot avoid is one you must size. The two laws every architect must internalise:
Little's Law (John D. C. Little, MIT, 1961) holds for any stable system in steady state:
$L = \lambda W$
where $L$ is mean concurrency, $\lambda$ is arrival rate, and $W$ is mean time in system. It lets you derive any of the three from the other two — useful for thread-pool sizing, queue sizing, and connection pools.
The Utilisation Law: $U = \lambda S$ (arrival × service time). For an M/M/1 queue (Poisson arrivals, exponential service, one server), the mean response time is:
$R = \dfrac{S}{1 - U}$
The denominator $(1 - U)$ produces the infamous hockey-stick. At $U = 0.5$, $R = 2S$. At $U = 0.8$, $R = 5S$. At $U = 0.95$, $R = 20S$. This is why production targets sit at 60–70 % utilisation, not 95 %.
Response time vs utilisation (M/M/1)
Variants worth knowing: M/M/c (c servers — pooled), M/G/1 (general service distribution — the Pollaczek–Khinchine formula adds variance: $W_q = \dfrac{\rho^2(1+C_v^2)}{2\lambda(1-\rho)}$), and G/G/1 (Kingman's approximation). Variance hurts as much as average load.
14.3 · The Universal Scalability Law
Neil J. Gunther (Performance Dynamics Co., 1993, refined 2007) extended Amdahl with a coherence term to model the real ceiling of horizontally-scaled systems:
$C(N) = \dfrac{N}{1 + \alpha(N-1) + \beta N(N-1)}$
where $N$ is the number of parallel units, $\alpha$ is the contention coefficient (serial fraction — locks, single-writer paths), and $\beta$ is the coherence coefficient (cost of inter-node synchronisation — cache lines, distributed consensus). The $\beta N(N-1)$ term is quadratic: at some $N^*$ throughput actually decreases. This is "retrograde scalability" — adding nodes makes the system slower.
| Pattern | $\alpha$ | $\beta$ | Outcome |
|---|---|---|---|
| Embarrassingly parallel | ≈ 0 | ≈ 0 | Linear |
| Shared-nothing web tier | low | ≈ 0 | Near-linear, slow saturation |
| Read-replica DB | medium | low | Sub-linear, knee around 8–16 nodes |
| Distributed lock / consensus | medium | high | Retrograde beyond 5–7 nodes |
14.4 · Amdahl's Law
Gene Amdahl (IBM, 1967) gave the speedup ceiling from parallelising a fraction $p$ of the work across $N$ processors: $\text{Speedup}(N) = \dfrac{1}{(1 - p) + p/N}$. As $N \to \infty$, speedup is bounded by $1/(1-p)$. If 10 % is inherently serial, no amount of hardware exceeds 10×. The architectural lesson: find and shrink the serial fraction before buying iron.
14.5 · Latency budgets
A latency budget decomposes a target SLO into spendable slices per hop. Build one early; it forces conversations with every owner on the path. Sample for a 200 ms p95 page render:
| Hop | Budget | Notes |
|---|---|---|
| DNS lookup | 10 ms | Cacheable; pin TTL |
| TCP + TLS handshake | 30 ms | Use TLS 1.3 0-RTT, session resumption |
| Edge / CDN routing | 15 ms | POP nearest user (Cloudflare, Fastly, CloudFront) |
| Backbone network (CDN → origin) | 25 ms | Same region; private peering |
| API gateway / WAF | 10 ms | Allow no synchronous external calls here |
| Application logic | 40 ms | Sum of synchronous work |
| Cache lookup | 5 ms | Redis / Memcached, same AZ |
| Database (read) | 25 ms | Indexed, ≤ 3 round-trips |
| Serialisation + payload | 10 ms | Prefer Brotli/gzip, HTTP/2 or 3 |
| Browser render (FCP) | 30 ms | Critical CSS inlined, lazy non-critical |
| Total | 200 ms | Cross-check with synthetic + RUM |
14.6 · Performance NFRs done right
Cross-reference Ch 05. A performance NFR worthy of an architecture has all five clauses: metric · percentile · workload · window · compliance.
// Bad checkout must be fast // Good SLI : checkout-api end-to-end response time SLO : p95 ≤ 600 ms and p99 ≤ 1200 ms Workload : 4 000 RPS sustained, 8 000 RPS peak for 10 min Window : 28-day rolling Compliance: 99.0 % of 1-min buckets must meet both thresholds
Percentile cheat-sheet: p50 (typical user), p95 (worst tail you advertise), p99 (the loudest 1 % — usually your top customers), p99.9 (queue spikes, GC pauses), p99.99 (chaos territory). Each extra nine roughly doubles cost.
14.7 · Capacity planning workflow
peak RPS, mix, growth
service demand per request
12–24 months
30–40% headroom
- Workload model — request types, mix, distribution (Poisson? bursty?), seasonality, growth rate.
- Resource model — CPU-ms, memory MB, IOPS, network bytes per request by type. Derive from profiling.
- Forecast — multiply by demand forecast; add a confidence interval. Re-do quarterly.
- Safety margin — keep peak utilisation ≤ 70 % per §14.2; absorb variance and failure of one AZ.
- Provision — reserved/committed for baseline, on-demand or spot for burst, scale-to-zero off-peak.
14.8 · Sizing approaches
| Approach | When | Accuracy |
|---|---|---|
| Back-of-envelope (Jeff Dean numbers) | Greenfield, no system to measure | ± order of magnitude |
| Vendor calculators (AWS Pricing Calculator, Azure TCO, GCP Estimator) | Cost framing of a sized design | ± 30 % on cost |
| Reference benchmarks (TPC-C/H/DS, YCSB) | Comparing engines | Apples-to-apples for the workload tested |
| Load testing | Pre-launch, post-change | ± 10 % if model is faithful |
| Observed production headroom | Running systems | Best — use rolling 28-day p95 of utilisation |
14.9 · Load testing strategies
Closed-loop (think-time per virtual user, requests gated by responses) models users. Open-loop (Poisson arrivals independent of response time) models traffic. Closed-loop hides queue build-up because slow responses self-throttle the test; open-loop reveals it. Public APIs and event-driven systems should be tested open-loop (Gil Tene's "coordinated omission" critique).
| Test type | Goal | Duration |
|---|---|---|
| Smoke | Pipeline + harness sanity | 2–5 min |
| Load | Confirm SLO at expected peak | 30–60 min |
| Stress | Find the breaking point | Until failure |
| Soak / endurance | Memory leaks, queue drift, log-disk fill | 8–72 h |
| Spike | Burst from baseline to N× in seconds | 10–30 min |
| Breakpoint / capacity | Where the knee is | Ramp continuously |
Tooling: k6 (Grafana Labs, 2017) Gatling (2012) Apache JMeter (1998) Locust (Python) Vegeta (Go, open-loop) Tsung wrk2 (Gil Tene) NBomber (.NET).
14.10 · APM & profiling
Two complementary lenses for production:
- RED method (Tom Wilkie, Weaveworks, 2016) — Rate, Errors, Duration. Per-service request view.
- USE method (Brendan Gregg, Netflix, 2012) — Utilisation, Saturation, Errors. Per-resource view.
- Four Golden Signals (Google SRE Book, 2016) — Latency, Traffic, Errors, Saturation. RED + saturation.
APM vendors: Datadog, New Relic, Dynatrace, AppDynamics (Cisco), Honeycomb, Lightstep (ServiceNow), Elastic APM. Continuous profiling (always-on, sample-based CPU/heap/lock profiles): Pyroscope (Grafana), Parca (Polar Signals), Google Cloud Profiler, AWS CodeGuru Profiler. The flame graph (Brendan Gregg, 2011) is the canonical visualisation.
14.11 · Caching hierarchies
Each layer trades freshness for latency. Pick the highest layer that meets the freshness need; cache invalidation is the second-hardest problem in CS (Phil Karlton).
| Eviction | Best for | Worst for |
|---|---|---|
| LRU (Least Recently Used) | Working-set workloads | Scan-heavy traffic poisons it |
| LFU (Least Frequently Used) | Power-law popularity | Slow to adapt to shifts |
| TTL (time-based) | Freshness SLAs, regulatory | Thundering herd at expiry |
| ARC / W-TinyLFU | Mixed (Caffeine's default) | Slightly more memory overhead |
14.12 · Common performance anti-patterns
- N+1 queries — one query for the list, N for each child. Fix with joins, batch loaders (Facebook DataLoader), or projections.
- Premature optimisation (Knuth, 1974) — micro-tuning before profiling. Measure first.
- Synchronous I/O on the hot path — blocking external calls inside a request. Move to async, queue, or pre-compute.
- Chatty interfaces — fine-grained APIs forcing many round-trips. Coarsen, batch, or use BFF (Ch 08).
- Unbounded fan-out — one request spawns hundreds (scatter-gather). Bound concurrency, hedge tail requests.
- Retry storms — synchronous retries amplify load during incidents. Use jittered exponential backoff + circuit breaker (Ch 13).
- Hot keys — single partition or single cache key absorbs all traffic. Salt, shard, or replicate.
- Coordinated omission — load tool stops counting when the system slows. Use open-loop tools (wrk2, Vegeta).
- Log-on-hot-path — synchronous structured logging at debug level under load. Sample or async-buffer.