Skip to content
Tech Intuition
Tech Intuition

Appearance

Theme

Signal · Dark with amber

Background

Slow stars and the odd comet

Connect

Performance engineering · Lesson 21 of 44

Performance engineering cheat sheet

One page for the day before a performance interview: the formulas with worked numbers, the figures worth knowing, method checklists for the common prompts, and twenty-four questions with short answers that point to the lessons.

GuideCore15 min readUpdated

  • 4 self-checks

Read first: Latency, throughput and queues, Load testing and benchmarking, Profiling and finding the bottleneck, Tail latency and overload, Network performance for system designers, Observability: metrics, logs and traces, SLOs, error budgets and alerting

By the end you will be able to
  • Recall the formulas for queues, scaling, statistics and networks, and do each with real numbers.
  • Quote the latency, packet and protocol figures that interviewers expect, and label them as rules of thumb.
  • Turn an SLO into minutes of error budget and a burn-rate alert, and estimate series and trace volume.
  • Run a method checklist for a slow service, a load test, regression detection, overload, alerting and a slow transfer.
  • Answer the twenty-four most common performance questions in a sentence or two, then go deeper.

This page is for revision, not for learning. Every formula below is derived and tested in a lesson of this section, and the last table says which one to open when an answer does not feel obvious. The habit that wins these interviews is the same each time: say the formula, put numbers in it, state the assumption, then say what you would do.

Formulas with worked numbers

Queues, capacity and scaling

NameFormulaUse it toWorked example
Little's LawL = λ × WSize pools, check a benchmark2,000 requests/s × 0.05 s = 100 in flight
Utilization lawU = X × D ÷ m, so a resource is full at X = m ÷ DFind each resource's ceiling2 ms of CPU on 8 cores: 4,000/s. A 0.45 ms global lock: 2,222/s, the bottleneck
M/M/1 response timeS ÷ (1 − ρ)Predict the hockey stickS = 10 ms at 80% busy: 50 ms mean
M/M/1 tailp99 is about 4.6 × the meanTurn a mean into a tail50 ms mean: about 230 ms p99
Kingmanwait ≈ ρ ÷ (1 − ρ) × (ca² + cs²) ÷ 2 × SSee why variability mattersConstant service times wait half as long as exponential ones
Utilization for a targetρ ≤ 1 − 1 ÷ k for a mean within k × SSet headroomk = 3: run at 67% or less
Headroom for failurenormal peak ≤ target × (N − 1) ÷ NSize zones75% after losing one of 3 zones: 50% on a normal day
Amdahlspeedup ≤ 1 ÷ (s + (1 − s) ÷ N)Bound a fix5% serial: never above 20×. A 45% frame: at most 1.8×
Universal Scalability LawC(N) = N ÷ (1 + α(N − 1) + βN(N − 1)), peak at √((1 − α) ÷ β)Explain flat or falling scalingα = 0.05, β = 0.001: 5.7× at 8 workers, a peak near 31 workers at 9×
Fan-out tail1 − (1 − p)^nSee why p99 matters1% slow, 100 calls: 63% of requests
Fleet sizeruns per day × minutes per run ÷ 1,440 ÷ target utilizationSize a pool3,880 runs × 10 min ÷ 1,440 ÷ 0.7 = 39 hosts
Retry amplificationattempts ^ layersCap retries3 attempts in 5 layers: 243 on the bottom one

Measurement and statistics

NameFormulaUse it toWorked example
Interactive response timeN = X × (R + Z)Check a closed-loop test50 users, no think time, 2 ms: expect 25,000/s
Runs neededn ≈ 16 × (σ ÷ δ)² per sidePlan a comparison2% target: 4 runs at 1% noise, 36 at 3%, 64 at 4%
Samples for a percentileten samples beyond p99.9 need 10,000 requestsTrust a tail numberA p99 from 200 requests rests on two samples
Multiple comparisonsfalse alarms ≈ benchmarks × significance levelDesign a gate100 benchmarks at 5%: about 5 per change
Bisect costlog2(commits) measurementsCost of finding a culprit63 commits: 6. 1,000 commits: about 10
Frame share to gain1 ÷ (1 − share)PrioritizeA 20% frame can buy 1.25× at most
CPU quota throttlingfrozen = period − quota ÷ busy threads, quota = limit × periodExplain container p99 steps2 CPUs, 8 busy threads, 100 ms period: frozen 75 ms
Key skewZipf with s = 1Model hot keys10,000 keys: the hottest 1% take 53% of requests
Error budget(1 − SLO) × windowTurn a target into minutes99.9% over 30 days: 43.2 minutes. 99.99%: 4.3
Budget used by a burn rateburn × window ÷ SLO windowSize a burn-rate alert14.4 over 1 hour: 2% of a 30-day budget. 6 over 6 hours: 5%
Availability in seriesa ^ nCap an SLO by its dependenciesThree at 99.9%: 99.7%. Ten: 99.0%
Series a metric can createthe product of the values of each labelEstimate a metrics bill25 × 4 × 5 × 6 × 50 labels: 150,000. As a histogram, 15 times more

Network and packets

NameFormulaUse it toWorked example
Propagation5 µs per km each way in fiberFind the latency floorNew York to London, 5,570 km: about 56 ms round trip
Round trips to first byteTCP + TLS 1.2: 4. TCP + TLS 1.3: 3. QUIC: 2. QUIC 0-RTT: 1. Reused connection: 1Cost of a new connectionAt 80 ms: 320, 240, 160, 80 and 80 ms
Bandwidth-delay productbandwidth × RTTFind the window needed1 Gbps × 80 ms = 10 MB
Window-limited ratewindow ÷ RTTExplain a stuck transfer64 KB at 80 ms: 6.6 Mbps. 4 MiB: 420 Mbps
Slow startrounds n with 10 × (2^n − 1) ≥ segmentsTime a short transfer100 KB: 3 round trips. 1 MB: 7. 10 MB: 10
Loss-limited rate(MSS ÷ RTT) × (C ÷ √p), C about 1.2Explain a long, lossy path1,460 B, 80 ms, 0.01% loss: about 18 Mbps
Queue delaybuffer × 8 ÷ link rateSpot bufferbloat1 MB at 10 Mbps: 800 ms
Packet ratebits per second ÷ ((frame + 20) × 8)Start a data plane budget10 Gbps of 64-byte frames: 14.88 M packets/s. 1,518-byte: 0.81 M
Cycle budgetHz × cores ÷ packets per secondBudget per packetOne 3 GHz core at 10 Gbps of 64-byte frames: about 200 cycles. 16 cores, 100 Gbps, 362-byte mix: about 1,470
Payload sharepayload ÷ (payload + 78)Judge small-message overhead1,460 B: 95%. 100 B: 56%

Numbers worth knowing

These are rules of thumb and vary by hardware and version. Say "about", and say they are rules of thumb.

ItemFigure
Light in fiberAbout 200,000 km per second
CPU cache read1 to 10 ns
Main memory read (a cache miss)About 100 ns, or about 300 cycles at 3 GHz
Random read from a fast SSD50 to 100 µs
Round trip inside a datacenterAbout 0.5 ms
Spinning-disk seek5 to 10 ms
Round trip between continents100 to 150 ms
Ethernet frame on the wireFrame size + 20 bytes. MTU 1,500, MSS 1,460
TCP initial window10 segments, about 14.6 KB. The window field alone is 65,535 bytes without scaling
Delayed ACK on LinuxAbout 40 ms minimum (200 ms maximum). The Nagle stall is about 40 ms
Linux connection limitsAbout 28,000 ephemeral ports, TIME_WAIT of 60 s, often 1,024 open files
Container CPU period100 ms by default
CoDel defaults (Linux)Target 5 ms, interval 100 ms
Profiler sampling99 Hz, not 100
Hedged requestAfter about the p95: about 5% extra requests
Error budget of 99.9%43.2 minutes in 30 days. 99.99%: 4.3 minutes. 99.999%: 26 seconds
Burn-rate alert policyPage at 14.4 over 1 hour (and 5 minutes) and 6 over 6 hours (and 30 minutes). Ticket at 1 over 3 days (and 6 hours)
SRE client throttleReject with probability max(0, (requests − K × accepts) ÷ (requests + 1)), K = 2
gRPC retry throttlingA token bucket: a failure costs 1, a success returns a fraction, no retries at or below half

Method checklists

When the service is slow

  1. Make the symptom precise: endpoint, percentile, start time, what changed.
  2. Inside the service or not? Compare client-side and server-side latency.
  3. Run USE (utilization, saturation, errors) on every resource, pools and locks included.
  4. Choose the profiler: CPU, off-CPU, allocation or trace.
  5. Bound the gain with Amdahl, predict, change one thing, measure again, add a guard.

See profiling and finding the bottleneck.

When you design a load test

  1. Write the question and the pass condition first.
  2. Open loop where clients are independent; measure from the intended send time.
  3. Realistic mix, connections, key skew, data size and dependency latency.
  4. Check the generator, warm up, run long enough, and report capacity at an SLO.
  5. Compare builds with per-run values, interleaving, an interval and a minimum effect.

See load testing and benchmarking.

When you detect regressions in CI

  1. Tier the tests; select by changed paths; batch and bisect.
  2. Measure each benchmark's noise; gate only on stable ones and quiet metrics.
  3. Detect sustained shifts with change points, not a threshold on one run.
  4. Bisect the batch, confirm with a direct A/B, send the owner a ticket with evidence.
  5. Track precision, and watch for slow creep against fixed anchors.

See the performance testing platform.

When the service is overloaded

  1. Stop the loop first: shed load, cut retries and hedging, drop optional work.
  2. Bound queues, propagate deadlines, drop expired requests.
  3. Shed by priority and cost, early and cheaply; protect established work.
  4. Retry in one layer with a budget; throttle on the client; let limits adapt.
  5. Recover gradually, warm caches, and test the recovery.

See tail latency and overload.

  1. Round-trip time and loss: ping, mtr.
  2. One stream against several: iperf3.
  3. Compare the window with the bandwidth-delay product: ss -ti.
  4. Capture for retransmissions, zero windows and handshake timing.
  5. Check hosts (interrupts, drops, offloads) and middleboxes (per-flow limits, MTU).

See network performance.

When you design alerts for a service

  1. Write the SLIs from the user's side, and the SLO as minutes of budget.
  2. Page on burn rate over a long and a short window; ticket on a slow burn; never page on a cause.
  3. Check low traffic: how many failures does the budget allow, and does one of them trip a rule?
  4. Give every page an owner and a runbook, and test the rules with replayed history and injected faults.
  5. Alert on silence, and keep a heartbeat on the paging path.

See SLOs, error budgets and alerting.

When you design a high-throughput data plane

  1. Packet rate at the worst frame size, then cycles per packet, then the cost of a cache miss.
  2. Hash flows to cores symmetrically; keep per-core tables; avoid locks on the fast path.
  3. First packets on a slow path with admission control; every later packet on a fast path.
  4. Size and age the session table (timer wheel); decide what happens when it is full.
  5. Choose the stack (kernel, XDP, polling), count TLS cost separately, choose a failure policy, benchmark inline with features on.

See the traffic inspection gateway.

Twenty-four questions with short answers

QuestionShort answerOpen
Latency or throughput?Latency is time per request; throughput is completed work per second. Batching trades the first for the secondFundamentals
Why p99 and not the average?Averages hide the tail, and fan-out makes the tail typical. Keep mergeable histogramsFundamentals
What does Little's Law give you?In flight = rate × latency: it sizes pools and checks benchmarksFundamentals
Why does latency explode near saturation?Waiting grows as ρ ÷ (1 − ρ): going from 90% to 95% doubles it, and variability makes it worseFundamentals
Why does adding cores stop helping?Contention (a serial part) and coherency (shared writes): the Universal Scalability Law peaks and then fallsFundamentals
CPU is at 55% and p99 climbs. Why?Another resource is the bottleneck (a lock, a pool, a disk), or per-core skew, bursts or throttling. Compute each ceilingFundamentals
What is coordinated omission?A closed-loop generator stops sending during a stall, so the worst moments are never measured. Measure from the intended send timeLoad testing
Open or closed workload?Open where clients arrive independently of your speed; closed for fixed poolsLoad testing
How do you compare two builds?Per-run values, interleaved runs, a bootstrap interval, a minimum effect and enough runsLoad testing
How do you find a bottleneck?Outside in: where is the time, which resource is full (USE), profile it, predict, change one thing, re-measureProfiling
CPU is low and latency is high. Now what?The requests are waiting: off-CPU view, thread dumps, pool and lock metricsProfiling
Container p99 spikes at 40% CPU. Why?CFS quota throttling: busy threads use the quota early and freeze for the rest of the periodProfiling
How do you cut tail latency?Reduce variability, then hedge after about the p95 (about 5% extra load), use probation and partial resultsTail and overload
What happens past capacity?Queues grow, servers do zombie work, retries multiply load, and a metastable failure can outlast its triggerTail and overload
How do you protect a service from overload?Bounded queues, deadlines, early shedding by priority, adaptive LIFO or CoDel, retry budgets, client throttling, adaptive limitsTail and overload
A fast link gives a slow transfer. Why?The window is below the bandwidth-delay product, or loss caps it (Mathis). Check scaling, buffers and middleboxesNetwork
Why do short requests feel slow?Round trips: handshakes and slow start dominate. Reuse connections and terminate near usersNetwork
Small messages stall for 40 ms. Why?Nagle meeting delayed ACK. One write per message, and TCP_NODELAYNetwork
How do you alert on an SLO?Burn rate over two windows: page at 14.4 over 1 hour (and 5 minutes) and 6 over 6 hours (and 30 minutes), ticket at 1 over 3 days. A raw error-rate threshold is noisy and blindSLOs and alerting
How much failure does 99.9% allow?43.2 minutes in 30 days. A full outage burns at 1,000 times the sustainable rate, so it empties the budget in 43 minutesSLOs and alerting
The metrics bill tripled. Why?A label with many values (ids, raw URLs) or per-pod churn: series are the product of the label values, and a histogram multiplies them againObservability
How do you sample traces?Head sampling is cheap and blind. Tail sampling keeps errors and slow requests but buffers whole traces and routes by trace id. Compute metrics before samplingObservability
Design a performance CI platformTiers, selection and batching; noise control; change-point detection; bisect; triage with evidencePlatform
Design a packet inspection gatewayCycle budget; per-core share-nothing; symmetric hash; fast and slow paths; timer-wheel session table; bypass; inline benchmarkGateway

How to answer, in one breath

Restate the goal with a percentile and a load. Model it with one formula and real numbers. Name the resources that could be the limit and the one you expect. Say how you would measure it, what you predict, and what you would change first. Close with what happens at twice the load, and how you would keep the gain.

Summary

Five families cover most performance questions. Queueing and capacity (Little's Law, utilization, the hockey stick, USL and Amdahl) tell you what to expect before you measure. Measurement and statistics (open loops, intervals, run counts, change points) tell you what to believe. Profiling and overload control tell you what to do. Network and packet arithmetic (round trips, the bandwidth-delay product, loss, packet and cycle budgets) tell you what the wire and the CPU allow. Reliability arithmetic (error budgets in minutes, burn-rate alerts, series and span volume) tells you what to promise and how to watch it. Practice the worked examples until the numbers come without a calculator.

Check yourself

Try answering out loud before you reveal each answer.

QuestionA service has a 99.9% SLO over 30 days. How much of the budget does a burn rate of 14.4 use in an hour, and how long until the whole budget is gone at that rate?Reveal answer

14.4 × 1 hour ÷ 720 hours = 2% of the budget. The whole budget lasts 30 ÷ 14.4 = 2.1 days, which is why a burn rate of 14.4 pages. A burn rate of 1 would last the full 30 days and only files a ticket.

QuestionA service handles 1,000 requests per second at 120 ms mean latency. How many requests are in flight, and what is the p99 for a single-server queue (M/M/1) at 80% utilization with a 10 ms service time?Reveal answer

In flight: 1,000 × 0.12 = 120. For the queue, the mean response is 10 ÷ (1 − 0.8) = 50 ms, and the p99 is about 4.6 times that, roughly 230 ms.

QuestionOn a 10 Gbps link with 64-byte frames, how many packets a second is line rate, and how many cycles per packet does one 3 GHz core have?Reveal answer

Each frame takes 84 bytes on the wire, so 10,000,000,000 ÷ (84 × 8) = 14.88 million packets a second. One core has 3,000,000,000 ÷ 14,880,952, about 200 cycles per packet, less than a memory miss.

QuestionA 1 Gbps path has a 40 ms round trip. How much data must be in flight to fill it, and what rate does a 64 KB window give?Reveal answer

The bandwidth-delay product is 125,000,000 bytes per second × 0.04 s = 5 MB. A 64 KB window gives 65,535 ÷ 0.04 s = 1.64 MB/s, about 13 Mbps.

Lesson 21 of 44

Nice. Lock it in, then keep going.

Up next · Lesson 22Case study: design a URL shortenerA senior-level walkthrough: requirements, estimates, API and data model, the high-level design, low-level ID generation in C#, the redirect path, scale, abuse and the follow-ups interviewers use to push.

Send a message

It goes straight to my inbox. I usually reply within a few days.