Course contents

15. Performance Engineering Lesson 8 of 8

Load Testing

Run load, stress, spike and soak tests in a simulation, find the knee by ramping traffic, read P99 instead of averages, and avoid coordinated omission.

15 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Load tests check expected peaks, stress tests find the ceiling and failure mode, spike tests check bursts and recovery, soak tests find slow degradation.
  • Latency stays flat, then bends sharply: the knee, not the maximum, is usable capacity.
  • Report percentiles from merged distributions at a known request rate; averages and averaged percentiles hide the tail.
  • Closed-loop generators back off when the system stalls (coordinated omission); use open-loop arrival rates.
  • A load test is an experiment: a question, a realistic workload and environment, and honest measurement.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

Load testing is generating controlled, synthetic traffic against a system and measuring how it behaves: latency distribution, throughput, errors and resource use. The umbrella term covers several test types, each answering a different question:

Test Shape of traffic Question
Smoke Very light Does the test setup work at all?
Load Expected and peak traffic, often ramped in plateaus Do we meet our latency and error targets at peak?
Stress Beyond expected peak, until it breaks Where is the ceiling, and how does it fail?
Spike Sudden jump to extreme load, then back Do we survive a burst, and do we recover?
Soak (endurance) Realistic load for hours or days Do we degrade over time (leaks, growth, fragmentation)?

Why it exists

Capacity estimates on paper miss things: a lock nobody knew about, a connection pool that is too small, a GC setting, a slow query that only appears with production-sized data. Load tests turn “should be fine” into measured numbers before users find the limits for you, and they give you a baseline to catch performance regressions between releases.

How it works

Workload model. Decide how the generator issues requests. In an open model requests arrive at a set rate (for example Poisson arrivals at 200 per second) regardless of how fast the system answers, like independent users on the internet. In a closed model a fixed number of virtual users each send a request, wait for the answer (and maybe think), then send the next; the arrival rate falls when the system slows down. Most public-facing services are better described by the open model. Many tools default to closed-loop virtual users; most also offer arrival-rate executors.

Coordinated omission. When a closed-loop generator waits on a stalled system, it stops sending, so the requests that would have arrived during the stall (and suffered most) are never issued and never measured. The recorded percentiles look far better than what users experience. Remedies: an open-model executor, or measuring each request’s latency from its intended send time (as wrk2 and HdrHistogram’s correction do).

Ramping and the knee. Increase load in plateaus long enough to reach steady state and record throughput and latency percentiles per plateau. Throughput grows with load until saturation; latency stays roughly flat and then bends upward as utilisation gets high, because queueing delay grows non-linearly (in the simplest queueing model, proportional to 1 ÷ (1 − ρ)). The point where it bends is the knee. Usable capacity is below the knee, not at the maximum.

Reading results. Use percentiles (P50, P95, P99, P99.9) from the full distribution, always with the request rate they were measured at. Percentiles cannot be averaged across servers or time slices; merge histograms instead. Look at error types (fast 503s and timeouts mean different things) and at resource metrics on every tier, so you know what saturated.

When to use it

  • Before launches, large marketing events and expected seasonal peaks.
  • In CI or nightly runs on a smaller scale, to catch performance regressions per release.
  • After architecture changes (new database, new cache, new region), to re-establish capacity numbers.
  • To validate autoscaling, rate limits, load shedding and timeouts under realistic pressure.

When not to

  • As a substitute for production observability: synthetic traffic never matches real behaviour perfectly.
  • Against shared or third-party systems without permission (payment providers, partner APIs): stub them or use their sandboxes.
  • When the environment differs so much from production (size, data volume, network) that the numbers cannot be transferred; at least state the differences.

Trade-offs

Choice You gain You pay
Production-sized staging Transferable numbers Cost of a second full environment
Testing in production (shadow or synthetic traffic) Real infrastructure and data Risk to users; needs careful isolation and kill switches
Open-model generator Honest latency under stalls Can overwhelm the system quickly; needs a cap
Long soak tests Finds leaks and slow degradation Hours of environment time per run
Stubbed dependencies Repeatable, isolates your service Misses the dependencies’ real limits

Alternatives

  • Capacity models: Little’s law and queueing estimates give first numbers before any test.
  • Canary releases with careful monitoring catch regressions with a slice of real traffic.
  • Traffic replay / shadowing: copy real production requests to a test system for a realistic mix.
  • Chaos and game days test failure behaviour rather than capacity; combine with load for realism.

Failure modes

  • Testing the cache: one URL with one ID always hits the cache; production misses would hit the database.
  • The generator is the bottleneck: a saturated load machine caps the rate and adds its own latency. Watch its CPU and network, or distribute it.
  • Coordinated omission: closed-loop tools hide stalls, making percentiles look healthy.
  • No steady state: ramping too fast or measuring during warm-up (cold caches, JIT compilation, autoscaling still reacting).
  • Unrealistic data: tiny tables fit in memory; production tables do not.
  • Averages: reporting mean latency, or averaging per-server percentiles, hides the tail that users feel.

In production

Teams commonly use tools such as k6, Gatling, JMeter, Locust or wrk2, with results stored as histograms. Define the question and pass/fail criteria first (for example: P99 < 300 ms and < 0.1% errors at 1.5× forecast peak). Run from outside the system under test, preferably from several machines. Monitor every tier during the run (CPU, memory, connection pools, queue depths, GC) so the test identifies the bottleneck, not just the symptom. Keep runs reproducible: same data, same script versions, recorded environment.

Common misconceptions

  • “It handled the max RPS, so we are fine at that load.” At the maximum you are past the knee; latency is already poor.
  • “Average latency is good enough.” The tail decides user experience, especially when one page makes many calls.
  • “More virtual users means more load.” In a closed model, a slower system automatically receives less load.
  • “A one-hour test proves stability.” Leaks and growth may take a day to surface.

Interview angle

Expect to be asked how you would verify a design’s capacity claims. Describe the test types and when each applies, ramping to find the knee, judging on P99 at a stated rate against an SLO, and an open-model generator to avoid coordinated omission. Mentioning realistic data and a non-bottlenecked generator shows experience.

Model assumptions

Simplified model, not a benchmark. The load generator sends open-loop (Poisson) traffic through a round-robin load balancer to two app servers, each with 4 workers, a 25 ms mean service time with a long tail (lognormal, cv 0.8) and a queue of 40 requests before it answers 503; together they handle about 320 requests per second. Plateaus last a few seconds of simulated time, so steady state is approximate. The soak test’s leak is modelled by lowering App 1’s speed every 3 seconds (hours compressed into seconds). The open-loop stall slows both servers 20× for 600 ms. The closed-loop virtual user is a scripted illustration: the engine’s clients are always open-loop. Numbers are illustrative.

The lesson as textEvery step of the simulation, written out.
  1. 1. Start with a baseline

    A load generator sends synthetic traffic to a production-sized staging copy: a load balancer and two app servers, about 320 requests per second of capacity together. First a light run at 50 requests per second: a smoke test that the setup works, and a baseline to compare every later run against.

    Look at three numbers: P50 (the typical request), P99 (the slowest 1%) and the error rate. Even at light load P99 is well above P50, because some requests are simply slower to serve.

    Scene: A load generator sends 50 requests per second to a load balancer and two app servers. Nothing fails; P99 is several times P50.

    Key idea: Every load test needs a baseline and a question. Record P50, P99 and errors, not just “it held up”.

  2. 2. Load test: ramp up and find the knee

    A load test checks behaviour at expected and peak traffic. Ramp in plateaus, holding each one long enough to settle: 100 → 200 → 260 → 300 → 360 requests per second.

    Watch P99. From 100 to 260 it barely moves. At 300 it roughly doubles. At 360, past capacity, throughput stops growing at about 320 while P99 keeps climbing and errors appear. That bend is the knee: past it, each extra request per second costs a lot of latency. Find it, then plan to run well below it, not at the theoretical maximum.

    Scene: Traffic steps up from 100 to 360 requests per second. P99 stays flat up to 260, roughly doubles at 300, and at 360 throughput stops growing near 320 while P99 climbs further and errors begin.

    Key idea: Latency grows slowly, then sharply. The knee, not the maximum, is your usable capacity.

  3. 3. Read the P99, not the average

    Hold the test at 280 requests per second. The average latency looks acceptable. The P99 is well over twice the average: one request in a hundred waits at least that long, and a page that makes ten such calls hits one of them about one time in ten.

    Report percentiles from the full distribution (histograms), never averages of percentiles across servers or time slices: percentiles do not average. And state the load they were measured at, because a P99 without a request rate means nothing.

    Scene: At a steady 280 requests per second, the average latency is moderate but P99 is more than twice as high.

    Key idea: Averages hide the tail. Judge a load test on P99 (and P99.9) at a stated request rate.

  4. 4. Stress test: push past the limit

    A stress test goes beyond expected load to learn how the system breaks. At 420 requests per second throughput flattens near 320: that is the real capacity. The servers’ queues fill and the excess is rejected with 503.

    That is a good way to fail: fast, explicit errors, latency bounded by the queue limit, and the system still serves what it can. Bad ways look different: timeouts piling up, memory growing until a crash, or throughput falling under overload. A stress test tells you which one you have.

    Scene: At 420 requests per second throughput stays near 320, both servers are saturated with full queues, and the excess is rejected.

    Key idea: Stress tests find the ceiling and the failure mode. Fail fast and visibly, not slowly and silently.

  5. 5. Spike test: a sudden burst

    A spike test jumps from normal to extreme load at once, like a push notification or a sale starting. One second in, traffic leaps from 150 to 500 requests per second for two seconds, then drops back.

    During the spike, queues fill within moments and requests are rejected; autoscaling would be far too slow to help. The question a spike test answers is what happens after: here the queues drain within about a second and the system is healthy again. A system with unbounded queues or retry storms might not recover at all.

    Scene: Traffic jumps from 150 to 500 requests per second for two seconds. Requests are rejected during the spike; after it the queues drain and errors stop.

    Key idea: Spike tests check survival and recovery from bursts that no autoscaler can follow.

  6. 6. Soak test: hold it for hours

    A soak (endurance) test holds a realistic load for hours to find problems that need time: memory leaks, growing caches, connection or file-descriptor leaks, log files filling disks, slow GC.

    Here App 1 has a leak: it gets a little slower as time goes on (modelled by lowering its speed every 3 seconds; hours compressed into seconds). At a steady 220 requests per second, the first minutes look perfect. Then P99 creeps up as App 1 slows, and round robin keeps sending it half the traffic. A one-hour load test would have passed.

    Scene: Steady 220 requests per second. App 1 slows down step by step; after several seconds its queue grows and P99 rises well above where it started.

    Key idea: Some failures only show up with time. Soak tests catch leaks and slow degradation that short tests pass.

  7. 7. Closed-loop generators hide stalls

    Many load tools run virtual users in a closed loop: send a request, wait for the answer, send the next. Watch one virtual user: requests flow every ~75 ms, then one request hits a 600 ms stall. The user waits, and sends nothing during the stall.

    The tool records one slow request. But real users arrive whether or not your server is stalled: in those 600 ms about eight more requests would have arrived and waited. They were never sent, so they are never measured. This is coordinated omission: the generator slows down together with the system and hides the worst latency. (Scripted illustration.)

    Scene: Scripted: one virtual user sends a request, waits for the answer, then sends the next. One request stalls for 600 ms and no new requests are sent during the stall, so only one slow request is recorded.

    Key idea: A closed-loop generator backs off when the system stalls, so the requests that would have suffered are never measured.

  8. 8. Open-loop load measures what users feel

    An open-loop generator sends requests on a fixed schedule (here random arrivals at 200 per second), independent of responses, like real independent users. Both servers now stall for 600 ms, 1.5 seconds in.

    The offered load does not drop during the stall: requests keep arriving, pile up in the queues and wait, and once the queues are full some are rejected. P99 shows the stall clearly: several times its normal value. Use an open-model (arrival-rate) executor, or correct for coordinated omission by measuring latency from each request’s intended start time.

    Scene: Open-loop traffic at 200 requests per second keeps arriving while both servers stall for 600 ms. Queues build up and P99 rises sharply; after the stall the queues drain.

    Key idea: Use open-loop (arrival-rate) load, or measure from intended send times, so stalls show up in the percentiles.

  9. 9. A load test that tells the truth

    Pick the test for the question: load (does peak traffic meet the SLO?), stress (where and how does it break?), spike (does it survive and recover from a burst?), soak (does it degrade over hours?). Ramp in plateaus to find the knee, judge on P99 at a stated rate, and generate open-loop load.

    Make it realistic: production-sized environment, a realistic mix of endpoints and data (not one cached URL), warm-up excluded from results, a load generator that is not itself the bottleneck, and dependencies that behave like production’s or are clearly stubbed.

    Scene: The load generator sends a steady 220 requests per second to both healthy servers; nothing fails.

    Key idea: A load test is an experiment: a question, a realistic workload, open-loop arrivals and percentile results at a known rate.