Reading the numbers
p50 vs p95 vs p99, what each tells you.
k6 prints about twenty numbers at the end of a run. Four of them answer questions you have, and the rest are context. This lesson is the four, and the one number everybody quotes that should be ignored.
The summary, annotated
checks_succeeded...: 100.00% 60 out of 60 <- did it do the right thinghttp_req_failed....: 0.00% 0 out of 62 <- did it answer at allhttp_req_duration..: avg=1.66ms p(95)=3.42ms <- how long it tookp(99)=69.28msiteration_duration.: avg=2.05s <- includes your sleep()http_reqs..........: 62 1.98/s <- throughput
iteration_duration catches people out: it includes the think time in the journey, so it is about 2 seconds whatever your API does. It measures the script, not the system. The number that measures the system is http_req_duration.
Ignore the average
The average is the one number almost every report leads with, and it is the least informative thing in the summary. An average of 50ms is consistent with every request taking 50ms, and equally consistent with 95% taking 10ms and 5% taking a second.
Two systems, the same average
What each percentile is for
- p50, the median. The typical experience. Useful for "did my change make the common case faster", and useless for finding problems, because problems are not typical.
- p95. The usual SLO number. One request in twenty is worse than this. On a page that makes ten API calls, p95 per request means roughly half of page loads contain at least one slow call, which is why p95 matters more than it sounds.
- p99. Where the pathologies live: GC pauses, cache misses, lock contention, a connection being opened. It is also the noisiest, and it needs volume. At 60 requests, p99 is one request and tells you nothing. At 60,000 it is the most interesting line in the summary.
Never average percentiles, and never compare a p95 computed over a whole run against one computed over a steady state. Both are arithmetic that looks reasonable and produces a number that describes nothing. Report the percentile from the hold stage, and say which stage it came from.
Failed is not the same as wrong
http_req_failed counts responses that were not 2xx or 3xx. checks counts your own assertions. They answer different questions, and a gap between them is informative:
http_req_failed 0%, checks 100% the system is healthyhttp_req_failed 8%, checks 92% it is returning errorshttp_req_failed 0%, checks 60% it is answering 200 with the wrong body
The third line is the one worth having checks for. An endpoint that returns 200 with an empty list because a query timed out and the error was swallowed is invisible to http_req_failed and completely visible to a check that asserts the shape of the body.
Which is why the check has to be specific. The suite Grit shipped until v3.432.0 checked r.body && r.body.length > 0, which an error envelope passes. It reported a successful check on a 500 for months. The replacement asserts Array.isArray(r.json('data')).
Throughput, and why it is a result and not a target
http_reqs per second is a function of your virtual user count and your think time, not of how fast the system is. A hundred VUs with a 1 to 3 second sleep produce about 50 requests a second whatever your API does, until the API becomes slow enough to be the limiting factor. Throughput only becomes a measurement of the system at the point where latency starts rising, and that point is what the breakpoint test finds.
Try it
One. Run the average load test and record avg, p50, p95 and p99 for http_req_duration.
Two. Work out the ratio p99 divided by p50. Write it down.
Three. Add a deliberate stall to one handler,time.Sleep(500 * time.Millisecond) behind a 1 in 20 condition. Re-run and recompute the ratio.
Quick check
Spot a typo? Have an idea?
Help us improve this lesson. One click opens a GitHub issue with the lesson URL pre-filled, suggest clearer wording, report a bug, or request more depth. The course keeps improving thanks to learners like you.
Suggest an improvement on GitHub