ealeng

Episode 02 of 55 · Estimates and load testing

Load tests that miss a whole second: coordinated omission

A load test reported a p99 of 1.1 ms for a service built to freeze for one second in every ten. The right answer, known before measuring, was 900 ms. How a planted fault gives you a known answer, why a tester that waits for each reply never sends the slow requests (coordinated omission), why the clock has to start when a request was due, and how k6 can hide the same freeze when it runs out of virtual users.

Lab 02 · Load Testing and Tail Latency17 min read
Video transcript8:46

0:00Cold open

0:01

My load test said everything was fast. Even the slowest one in a hundred requests took about one millisecond.

0:10

But I had built that service to freeze. For one full second, every ten seconds.

0:16

Real users would wait up to a second. My test never noticed. Why?

0:23Intro

0:25

Hands-on system design, part two.

0:28

Today: why a load test can miss a whole second, and how to catch it.

0:34Meet Lucía

0:35

I’m Lucía, a platform engineer. Last time, I measured how much one server could handle.

0:41

Here’s my test bench. A load test sends lots of fake requests at a service, and times every one.

0:49

A small Python web app answers them. Behind it sits a Postgres database.

0:56

This time, I made the app freeze on purpose. For the first second of every ten, it stops answering.

1:03

A request that arrives during a freeze waits until the freeze ends.

1:09

Why break it on purpose? So I know the right answer before I measure.

1:14

It’s like checking a kitchen scale with a one-kilo bag of sugar. If the scale says three hundred grams, the scale is wrong.

1:2401 · What you need

1:25

To run it yourself: Python with a few packages, Docker for the app and the database, and a script that loads a million rows.

1:35

The tests check the testing tools themselves. They run in about a second.

1:41

No cloud, and no API keys.

1:4502 · The freeze, in code

1:47

Here’s the whole freeze. It’s four lines in the app.

1:51

Read the clock, and find where we are in the ten-second cycle.

1:56

If we’re in the first second, sleep until that second is over.

2:02

Then do the normal lookup.

2:0603 · The right answer

2:07

So what should a correct test report? Let’s work it out, one step at a time.

2:13

The freeze covers one second in ten. Users arrive at random moments. So one user in ten lands in a freeze.

2:23

Zoom in on one freeze. Arrive just as it starts, and you wait a full second.

2:29

Arrive halfway, and you wait half a second. Arrive near the end, and you barely wait at all.

2:3704 · 100 users

2:39

Now picture a hundred users.

2:42

Ten of them land in a freeze. One in ten.

2:47

Of those ten, one lands in the first tenth of the freeze. So it waits nine tenths of a second, or more.

2:56

So one user in a hundred waits nine hundred milliseconds, or more.

3:02

That number has a name: the p99. Ninety-nine users in a hundred are faster than it.

3:10

Everyone else gets a normal answer, in about a millisecond. So a correct test should report a p99 of about nine hundred milliseconds.

3:2105 · Two ways to send load

3:23

Now, there are two ways a load test can send requests. Picture a help desk.

3:29

The first is called a closed loop. Four friends at the desk. Each one asks a question, waits for the answer, then asks the next.

3:38

When the desk freezes, all four are stuck. And while they wait, nobody asks anything new.

3:45

The second is called an open loop. Strangers walk up on their own schedule, busy desk or not.

3:53

When the desk freezes, strangers keep arriving, and every one of them waits.

4:00

Real users are strangers. They don’t wait for each other. So the open loop is the one that behaves like them.

4:0906 · The closed loop’s answer

4:10

First, the closed loop: four friends, for a full minute, against the freezing app.

4:16

The right p99 is about nine hundred milliseconds. What do you think the closed loop reported?

4:26

One point one milliseconds.

4:30

That’s about eight hundred times too low. As if the freeze never happened.

4:36

Its slowest single request did take a full second. But that one request disappears in the p99.

4:44

And look how fast it sent: over five thousand requests a second. The friends ask again as soon as an answer comes back.

4:53

So when answers are fast, they ask a lot. When the app is frozen, they ask almost nothing. They mostly tested the fast moments.

5:0407 · Why it missed

5:05

Here’s every request around one freeze, as I recorded it. The red box is the freeze. Higher means slower.

5:14

Inside the freeze, the closed loop sent just four requests. Four stuck friends.

5:21

Everyone else was never asked. The users who would have walked up during the freeze aren’t in its results.

5:28

Now the open loop. Inside the freeze, it sent five hundred and twenty-three requests.

5:36

They form a staircase. Each step is a user who arrived a little later, and waited a little less.

5:43

This has a name: coordinated omission. The test gets stuck along with the app, so it never sends, and never times, the requests that would have been slow.

5:5508 · The open loop’s answer

5:57

And the open loop’s p99? About nine hundred and twenty-five milliseconds. Right.

6:04

Same app, same minute. The only difference is how the requests were sent.

6:1109 · Start the clock on time

6:13

One more trap. Many tools send on a schedule, like strangers, but with a small team of senders. A sender can still get stuck.

6:22

After the freeze, it sends the requests it missed, late.

6:27

Time a late request from when it left, and it looks fast.

6:32

Time it from when it was due, and you get the wait a user would have felt.

6:38

In code, it’s one choice: the finish time minus when it was due. Not minus when it left.

6:4610 · Check the tool: k6

6:48

My own test now finds the freeze. But should I trust a tool I wrote myself? So I checked with a second one: k6, a popular free load tester.

6:59

k6 also sends on a schedule. But every request needs one of its helpers, which it calls virtual users. Like the friends at the help desk.

7:10

With a thousand helpers, k6 found the freeze too: about nine hundred milliseconds.

7:17

Now, with only twenty helpers. What do you think it reported?

7:24

Two milliseconds. During the freeze, all twenty were stuck. A request came due, and nobody was free to send it.

7:32

So k6 skipped it. Two thousand eight hundred and seventy-four requests, never sent, never timed. Nearly all were due during a freeze.

7:43

Coordinated omission again. A schedule only helps if someone is free to follow it.

7:50

The good news: k6 counts what it skipped. If that count isn’t zero, don’t trust its timings.

7:58Back to Lucía

8:00

So, my load test missed a whole second. Here are three checks, so yours won’t.

8:06

Plant a known answer, so you can tell when the test is wrong.

8:11

Send on a schedule, and start the clock when each request was due.

8:16

Check your tool with a second one, and read what it skipped.

8:21

Next time: even correct numbers can fool you. Through a dashboard, a page with many calls, or plain noise.

8:30

For today: when a load test says everything is fast, ask what it didn’t send.Lucía: Start the clock when it was due.

8:36Summary

8:38

A known answer, a schedule with the clock started on time, and a second tool to check the first.

Key takeaways

  • ✓Plant a fault whose answer you know, and test the tester on it. A service frozen for the first 1 s of every 10 s keeps 1 user in 10 waiting, and 1 in 100 waiting 900 ms or more: p99 = 900 ms, p99.9 = 990 ms, 9% of requests over 100 ms.
  • ✓A closed-loop tester (4 workers, each sending when its last reply arrives) reported p99 = 1.1 ms, about 800× too low. Its max, 1,003 ms, was the only hint. It sent 0.01% of its requests during freezes that cover 10% of the time.
  • ✓Coordinated omission: the tester gets stuck along with the server, so the requests that would have been slow are never sent and never timed. In one freeze the closed loop started 4 requests; the open loop, which sends on schedule whatever is waiting, started 523.
  • ✓Start the clock when the request was due, not when it left. The same paced run reads p99 = 3.3 ms timed from when each request was sent and 919.5 ms timed from when it was due. The open loop read 925.5 ms.
  • ✓Check the tool with a second one. k6 with 1,000 virtual users found the freeze (914 ms). With 20, all of them were stuck in each freeze, so k6 skipped 2,874 requests that came due and reported p99 = 2.0 ms. Any dropped requests mean its latencies can't be trusted.
  • ✓Check the generator itself, too: its send lag (how late each request left) belongs next to its latencies. Sleeping until each send time left 0.93 ms late at the median, and that read as server latency.
  • ✓Past capacity, a latency number describes the test, not the server. Offered 7,000 a second, the service managed 6,293 and p99 jumped to 1.9 s, because the queue grows for as long as the test runs.

A load test sends many requests at a service at once and times every one. It's how you find out how fast a service is under traffic, and how much traffic it takes. This chapter tests the testers. The lab plants a fault whose answer is known before measuring: the service freezes for one second in every ten, so the right p99 is 900 ms. The load test from Chapter 1 reported 1.1 ms. Nothing was wrong with the server or the arithmetic. The tester got stuck along with the server and never sent the requests that would have been slow.

The examples come from the first half of Lab 02 (Load Testing and Tail Latency) of the system design labs: 01_closed_vs_open.py (three testers against the freeze), Exercise 3 of 02_hdr_histogram.py (correcting a test after the fact), 03_vs_k6.py (checking our tester against k6) and 04_latency_vs_load.py (load past capacity, and warm-up). The rest of 02_hdr_histogram.py, and the numbers that are measured right but still mislead (averaged percentiles, fan-out, noise between runs), are in Chapter 3. The setup is Chapter 1's: one laptop (an Apple M4 Max), a Python web app (FastAPI, one worker) and Postgres 18 with a million rows in Docker, and the load generator on the same machine. Other work kept the laptop busy throughout (its load average, the number of processes wanting a core, ran 4–12), so read the shapes, not the last digit.

A fault with a known answer

The lab added one endpoint, GET /stall/k/{id}. It's the usual lookup, but frozen for the first second of every ten seconds of wall-clock time. The whole freeze is four lines in the app:

phase = time.time() % STALL_EVERY_S        # where are we in the 10 s cycle?
if phase < STALL_S:                        # in the first second:
    await asyncio.sleep(STALL_S - phase)   #   wait until it's over
return await get_key(key_id)               # then the normal lookup

Why break it on purpose? So the right answer is known before measuring, the way you check a kitchen scale with a 1 kg bag of sugar. A request that arrives during a freeze waits for the rest of it. Arrive as the freeze starts and you wait a full second; arrive halfway and you wait half a second.

Picture 100 users arriving at random moments. A freeze covers a tenth of the time, so 10 of them land in one. Of those 10, one lands in the first tenth of the freeze, so it waits 0.9 s or more. One user in 100 waits 900 ms or more: that's the p99 (as in Chapter 1, the latency 99 in 100 requests beat). Everyone else gets the normal answer in about a millisecond. The same reasoning gives the rest:

P(latency > x) = (1 s − x) ÷ 10       for x up to 1 s

p99   = 900 ms     (1% of requests wait longer)
p99.9 = 990 ms     (0.1%)
share slower than 100 ms = 9%

Drag the threshold to see which of the 100 wait longer than it.

Try it · 100 users, one freezeModelled: evenly spaced arrivals, not a recorded run

One 10 s cycle · 100 users, one every 100 ms

← freeze, first 1 s0s1s2s3s4s5s6s7s8s9s10s

The frozen second, zoomed in · bar = the wait until it ends

← arrive before 100 ms: wait > 900 ms950 ms850 ms750 ms650 ms550 ms450 ms350 ms250 ms150 ms50 ms0s0.25s0.5s0.75s1s
Of these 100 users, slower than x
1 of 100
Model: (1 s − x) ÷ 10
1.0%

One user in 100 waits more than 900 ms: that's the p99.

This model leaves out the normal millisecond, and the backlog the app works through after each freeze. A correct test should land close to it, a little above.

Two ways to send load

Picture a help desk.

  • Closed loop. Four friends at the desk. Each asks a question, waits for the answer, then asks the next. When the desk freezes, all four are stuck, and while they wait nobody asks anything new. A closed-loop tester has a fixed number of workers, and each sends its next request as soon as the last reply arrives. Chapter 1's measurements were all closed loop.
  • Open loop. Strangers walk up on their own schedule, busy desk or not. When the desk freezes, strangers keep arriving, and every one of them waits. An open-loop tester sends requests on a schedule (here, at random moments averaging 500 a second) whatever is still waiting.
  • Paced closed loop. In between: a small team of workers, each with a schedule (one request every 8 ms here). A worker still can't send while it waits for a reply, so after a freeze it sends its missed requests late, then catches up. Many load tools work this way.

Real users are strangers: they don't wait for each other. So an open-loop test models users; a closed-loop test models a fixed pool of clients, like a batch job with four threads. That isn't wrong when the clients really are a fixed pool. It's wrong when you're asking what users feel.

What each tester reported

Each tester ran for 60 s against the freezing endpoint (6 freezes), with the first 2 s dropped as warm-up. The closed loop used 4 workers; the paced and open testers aimed for 500 requests a second.

Tester Requests Per second p50 p90 p99 p99.9 Max > 100 ms
The known answer 0 0 900 990 1,000 9.0%
Closed loop, 4 workers 313,535 5,406 0.6 0.8 1.1 2.5 1,003 0.0%
Paced, timed from when sent 29,000 500 1.4 1.9 3.3 24.8 1,006 0.1%
Paced, timed from when due 29,000 500 1.5 120.4 919.5 995.8 1,006 10.2%
Open loop, timed from when due 29,148 503 1.0 93.9 925.5 1,006.4 1,043 9.9%

All times in ms. The closed loop reported a p99 of 1.1 ms for a service that keeps 1 user in 10 waiting up to a second: about 800× too low, as if the freeze never happened. Its own max, 1,003 ms, is the only hint. Note its rate, too: over 5,000 a second, a number nobody chose. In a closed loop the request rate is a result, not a setting: when replies are fast, the workers ask a lot, and when the server is frozen, they ask almost nothing. They mostly tested the fast moments.

The open loop landed on the known answer: 925.5 ms. The extra 25 ms over the model is a few milliseconds of chance (10.5% of this run's requests landed in freezes, not exactly 10%) plus the queue: about 500 requests come out of each freeze at once, and the app, one Python worker, answers them one after another.

Try it · The known answer, and what each tester saidLab 02 · 01_closed_vs_open.py · 60 s each

Which number

99 in 100 were faster: the slowest 1 in 100. The known answer is 900 ms.

Linear axis, 0 to about 1 second: a 1 ms bar is a sliver. The known answer leaves out the normal ~1 ms a request takes. Red: under a fifth of the known answer. Click a tester for its details.

Requests timed
313,535
Requests a second
5,406
Sent during a freeze
0.01%
p99 vs 900 ms
813× too low

Four workers, each sending its next request when the last reply comes back. Nobody chose 5,406 a second: fast replies set it. During each freeze all four were stuck, so it sent almost nothing (0.01% of its requests) and timed only the fast moments.

Why it missed: coordinated omission

The lab counted how many requests each tester sent while a freeze was on:

Tester Sent during a freeze Due during a freeze
Closed loop 0.01% no schedule
Paced 0.03% 10.3%
Open loop 10.5% 10.5%

Users arriving at random would put 10% of their requests in a freeze. The closed and paced testers each had 4 requests stuck in each freeze, one per worker, and then sent nothing else until it ended. The open loop kept sending: in the freeze shown below it started 523 requests (497–532 across the six freezes), and they form a staircase, each request arriving a little later and waiting a little less.

This has a name: coordinated omission. The tester gets stuck along with the service, so it never sends, and never times, the requests that would have been slow. The freeze "coordinates" with the tester to leave itself out of the sample. The paced tester had 10.3% of its requests due during freezes and sent almost none of them on time: coordinated omission in one number.

Try it · Every request around one freezeLab 02 · 01_closed_vs_open.py · raw records, one freeze
freeze1 ms10 ms100 ms1 s4 stuck, ~1 s each−1 s0 s+1 s+2 s

Across: when each request started (when it was sent), from 1 s before the freeze to 2.5 s after it began. Up: its latency, on a log scale. Darker cells hold more requests; red ones are slower than 100 ms.

Requests shown
15,313
Started in the freeze
4
Slower than 100 ms
4

In the freeze, the closed loop started 4 requests, one per worker, each stuck until the freeze ended. Then nothing. The users who would have walked up during that second are not in its results.

One freeze (the second after the run began), from the same runs as the table above. The closed loop shows far more requests because it sent over 5,000 a second; the others sent 500. Across all six freezes, the open loop started 497–532 requests in each.

Start the clock when the request was due

Look at the two paced rows again. Same run, same requests, same server: 3.3 ms timed from when each request was sent, 919.5 ms timed from when it was due. After a freeze, a stuck worker sends its missed requests late. Timed from when it left, a late request looks fast. Timed from when it was due, you get the wait a user would have felt, because that user would have clicked on time.

In the lab's load generator, every request records three times: when the schedule said to send it (due, called intended in the code), when it was actually sent, and when the reply was done. Latency is one line:

latency = done - intended     # not done - sent

An open-loop generator times everything from the schedule, so it charges its own lateness to the request too. That's correct for the same reason: the user it stands for would have sent on time. It's also why the generator's own lateness has to be watched (below).

Fixing a test afterwards. HdrHistogram, a widely used library for recording latencies, has a correction for paced tests: for each slow request, add the requests the client should have sent while it was stuck (a 1 s wait with an 8 ms schedule adds 124: 992 ms, 984 ms, … down to 8 ms). On the paced run's naive numbers, it brought p99 from 3.3 to 899 ms and p99.9 from 25 to 995 ms, close to the open loop's 926 and 1,007. It didn't fix p90 (3.7 ms against the open loop's 94), and it needs to know the client's intended interval, which a plain closed loop doesn't have. Recording the due time in the first place is simpler and needs no guessing.

Check the tool with a second one

The lab's generator now finds the freeze, but it's a tool the lab wrote itself. So the lab checked it against k6, a popular free load tester, with both tools inside the Docker network so they take the same path to the app.

On a normal endpoint they agree. The plain lookup at 1,000 requests a second for 30 s:

Tester Requests p50 ms (95% interval) p99 ms (95% interval)
Ours, in Docker 27,964 0.43 (0.43–0.43) 2.11 (2.02–2.22)
k6, in Docker 29,999 0.55 2.15
Ours, on the Mac 27,919 0.62 (0.62–0.63) 2.67 (2.49–3.00)

k6's p99 of 2.15 ms sits inside our interval. At p50 ours reads 0.12 ms lower, most likely because our generator is always awake to read a reply while k6 has to be woken up, so don't compare sub-millisecond medians across tools. Run from the Mac, through Docker's port forwarder, everything reads about 0.2 ms higher. (k6 gives no intervals, and its request count includes the first 2 s, which ours drops.)

On the freezing endpoint, k6 can hide the freeze too. k6 also sends on a schedule, but every request in flight needs one of its virtual users (VUs), its workers. If none is free when a request comes due, k6 skips it and counts it as a dropped iteration. At 500 requests a second, 60 s:

Tester Requests timed Dropped p90 ms p99 ms p99.9 ms
Ours 28,959 0 57.5 902.3 1,001
k6, 1,000 VUs 30,001 0 32.8 914.1 1,003
k6, 20 VUs 27,127 2,874 0.8 2.0 995

With 1,000 VUs, k6 found the freeze: 914 ms, inside our run's interval (887–915 ms). With 20, all of them were stuck in each freeze; a request came due and nobody was free to send it. k6 skipped 2,874 requests, nearly all of them due during a freeze (6 freezes × about a second × 500 a second ≈ 2,900): the ones that would have been slow. The p99 looked good again. A schedule only helps if someone is free to follow it. The good news is that k6 counts what it skipped: if dropped_iterations isn't zero, don't trust its latencies. How many VUs is enough? At least the rate times the worst latency you want to see, by Little's law from Chapter 1: 500 a second × 1 s = 500.

Check the generator's own lateness. The first version of the lab's generator disagreed with k6 by several times at p50. Python's event loop wakes from a sleep up to a millisecond late, so the generator sent late, and an open-loop generator rightly counts that as latency. It read as server latency. The fix was to wait in a tight loop (spin) for the last 2 ms before each send. The lab kept both versions:

Our generator Send lag p50 Send lag p99 Latency p50 Latency p99 Client CPU (cores)
Sleep until due 0.93 3.20 1.63 4.45 0.22
Spin for the last 2 ms 0.01 1.07 0.45 1.88 1.12
k6, for comparison 0.55 2.15

Send lag is sent time minus due time. Sleeping cost 0.93 ms of it at the median, and the median latency more than tripled (1.63 ms against 0.45). Spinning fixed it at five times the CPU. Report the send lag next to the latencies; if it grows, the generator is falling behind, and its numbers measure itself.

Try it · Check the tool with a second oneLab 02 · 03_vs_k6.py · both tools inside Docker

The freezing endpoint at 500 requests a second for 60 s. Known answer: p99 = 900 ms. k6 needs a free virtual user for every request in flight; a 1 s freeze at 500 a second holds about 500 of them.

Requests timed
27,127
Dropped (never sent)
2,874
p99
2 ms
p99.9
995 ms

Don't trust it. During each freeze all 20 virtual users were stuck, so when a request came due nobody was free to send it, and k6 skipped it: 2,874 requests, nearly all due during a freeze, the ones that would have been slow. The p99 looks fine again. The 20 stuck requests per freeze still show up, in the max and p99.9.

TesterDroppedp90 msp99 ms
Our generator057.5902.3
k6, 1,000 virtual users032.8914.1
k6, 20 virtual users2,8740.802

Past capacity, the number describes the test

The last check is on the load itself. The lab swept the plain lookup with the open loop, one 15-second run at each rate:

Offered a second Achieved a second p50 ms p99 ms Send lag p99 ms Client CPU (cores)
1,000 1,001 0.43 1.97 1.06 1.1
4,000 4,021 0.42 1.75 0.33 2.9
5,000 4,995 0.55 5.44 0.25 4.6
6,000 6,008 0.81 84.9 0.93 5.2
7,000 6,293 207 1,933 0.47 5.6
10,000 5,149 7,625 11,838 6.96 6.7

Latency stays flat to 4,000 a second, bends between 5,000 and 6,000 (p99 from 5 to 85 ms: the knee, where requests start to queue), then hits a wall. Past about 6,300 a second, requests arrive faster than they finish, the queue grows for the whole test, and latency depends on how long you ran. Above capacity, a latency number describes the test, not the server. Report the capacity and the latencies below it. (About 6,300 is close to Chapter 1's closed-loop flat top of about 6,800, measured a different way. Chapter 4 predicts the knee instead of finding it.)

Two warnings in the same table. Achieved throughput falls past capacity (6,293 → 5,149), but the generator was using up to 6.7 cores next to the app and its send lag rose to 7 ms, so part of that fall is probably the generator competing for the CPU, not the server. Check before claiming either.

Warm-up lives in the tail. Restarted fresh and measured in half-second windows at 3,000 a second, the app's first window had p99 87 ms against a steady 1.7 ms, while p50 barely moved (0.57 against 0.46 ms). Write down a rule for "settled". A strict rule (every later window's p50 within 20% of the steady median) said 19 s, thrown off by hiccups at 2.5, 3.5 and 18.5 s that are part of normal running. A run rule (4 windows in a row within 20%) said 0.5 s. The 2 s the lab drops from every run is comfortably past it.

Caveats

  • One busy laptop. Tester, app and database share one machine through Docker Desktop's VM, and other work kept the load average at 4–12. The numbers are this laptop's.
  • The freeze is planted, and simple. Every request in a freeze waits for exactly the rest of it. Real stalls (garbage-collection pauses, failovers, a lock held too long) are messier, which is why a known answer is worth planting before you measure the real thing.
  • The model is close, not exact. It leaves out the normal ~1 ms and the backlog after each freeze, so a correct test reads a little above 900 ms (919.5 and 925.5 here). p90 sits right at the edge of the frozen tenth, so it swings with a few requests either way: 120 ms for the paced run timed from when due, 94 ms for the open loop.
  • Real traffic isn't purely open. Users wait for a page before clicking again. Model the arrivals, not the clients, and use a closed loop when the clients really are a fixed pool.
  • The k6 runs and the first table are separate runs. Our generator read 902 ms in the k6 comparison (inside Docker) and 925.5 ms in the first table (from the Mac); both are within a few percent of 900.
  • The correction needs the interval. HdrHistogram's after-the-fact fix only works when you know how often the client meant to send, and it doesn't recover p90.

The checklist

  1. Plant a known answer (a freeze, a delay) and check that the load test finds it before you trust it on the real thing.
  2. Send on a schedule (open loop) when you're asking what users feel. A closed loop's request rate is a result, not a setting.
  3. Start the clock when each request was due, not when it left.
  4. Look at the max and at what was sent during a slow period. A p99 far below the max, with nothing in between, is the shape of coordinated omission.
  5. Check the tool with a second one on the same path, and read what it skipped: any dropped_iterations means the latencies are incomplete. Give it at least rate × worst latency virtual users.
  6. Report the generator's send lag and CPU next to its latencies, at every load level.
  7. Stay below capacity when you report latency, and write down your warm-up rule.

Practice: a load test with a known answer

Write the lab's model and three testers in plain Python: the known p99 of the freezing service, a closed loop, a paced loop and an open loop against a simulated freeze, latency timed from when sent or when due, HdrHistogram's correction, and the k6 checks. The tests use the lab's numbers: p99 = 900 ms and 9% over 100 ms, the closed loop's 4 stuck requests per freeze and a ~1 ms p99, 500 virtual users for a 1 s freeze at 500 a second, and k6's 2,874 drops.

Try it · Practice in PythonRuns in your browser · ⌘/Ctrl + Enter to run
load_practice.py109 lines

Quiz

Try it · Check your understanding0 of 6 answered
  1. 1.A service freezes for the first second of every ten, and a request arriving during a freeze waits for the rest of it. What should a correct load test report as p99?

  2. 2.A closed-loop test with 4 workers reports p99 = 1.1 ms and max = 1,003 ms against that freezing service. What happened?

  3. 3.Which kind of load test behaves like real users arriving at a website?

  4. 4.A paced tester has a schedule, but a stuck worker sends its missed requests late, after the freeze. Timed from when each was sent, its p99 is 3.3 ms. What fixes the number?

  5. 5.k6 with 20 virtual users reports p99 = 2.0 ms on the freezing endpoint, and dropped_iterations = 2,874. What do you conclude?

  6. 6.An open-loop test offered 7,000 requests a second to a service that tops out near 6,300 and reports p99 = 1.9 s. What's wrong with quoting that p99?

Check your understanding

Try each question before opening its answer.

A service freezes for 1 s of every 10 s. Work out its p99, step by step.

Users arrive at random, so 1 in 10 lands in a freeze and waits for the rest of it. Of those, 1 in 10 lands in the freeze's first tenth and waits 0.9 s or more. That's 1 user in 100, so p99 ≈ 900 ms. The same reasoning gives p99.9 ≈ 990 ms and 9% of requests over 100 ms.

What's the difference between a closed-loop and an open-loop load test, and which one models users?

A closed loop has a fixed number of workers, each sending its next request when the last reply arrives, so the rate depends on the server's speed (5,406 a second here, chosen by nobody). An open loop sends on a schedule whatever is still waiting, so slow replies pile up as they would for real users. Open loop models users; closed loop models a fixed pool of clients.

Explain coordinated omission with the freeze as the example.

When the server froze, the closed loop's 4 workers were each stuck on one request, so the tester sent nothing else until the freeze ended: 0.01% of its requests went out during freezes that cover 10% of the time. The requests that would have been slow were never sent, so its p99 read 1.1 ms against a true 900 ms. In the same kind of freeze, the open loop started 523 requests.

A closed-loop test reports p99 = 1 ms and max = 1 s. What do you suspect, and how do you check?

A stall the test didn't see: a p99 a thousand times below the max with nothing in between is the shape of coordinated omission. Rerun it open loop, or check the send times: if the tester sent nothing for a second, it was stuck. Here, the open loop read 925.5 ms.

Why does timing from the due time fix a paced test, and why is it right to count the generator's own lateness?

A stuck worker sends its missed requests late; timed from when they left they look fast (p99 3.3 ms), timed from when they were due they show the real wait (919.5 ms). The user the request stands for would have sent on time, so any lateness, the server's or the generator's, is wait that user would feel. If the generator itself is late, fix the generator, not the number.

How can k6, which sends on a schedule, still miss the freeze? What tells you?

Each request in flight needs a free virtual user. With 20, all were stuck in each freeze, so k6 skipped the requests that came due (2,874 of them) and reported p99 = 2.0 ms. k6 counts them in dropped_iterations: anything above zero means the report left requests out. With 1,000 virtual users it read 914 ms. You need at least rate × the worst latency: 500 here.

Name three checks that a load generator is telling the truth.

A known answer it must find (the planted freeze: 925.5 ms against 900). A second tool on the same path (k6's p99, 2.15 ms, inside our 2.02–2.22 ms). The generator's own health at every load level: send lag and CPU. The first version sent 0.93 ms late at the median and reported it as server latency.

A colleague reports "p99 = 1.9 s at 7,000 requests a second". What's wrong with that sentence?

7,000 is past capacity (it achieved 6,293), so the queue grew for the whole test and the p99 depends on how long the test ran. It describes the test, not the server. Report the capacity, about 6,300 here, and the latency below it: p99 85 ms at 6,000, under 2 ms up to 4,000.

Next up: Chapter 3, tail latency traps: the load test is right now, and its numbers can still mislead. Averaging per-second p99s, a page that waits on 20 calls, and the noise between runs of the same code.

Learning something useful?

New labs, articles, and videos on evaluating and testing AI systems come out regularly. Follow along so you don't miss the next one.