Latency percentiles lab
A stream of requests with a small slow share. Read the mean, median, p95, p99 and p99.9, average percentiles across hosts, bucket them coarsely, and measure them with a load generator that waits.
mean 26.8 msmedian 19.3 msp99 362 ms10,000 requests
| Measure | Latency |
|---|---|
| mean | 26.8 ms |
| p50 | 19.3 ms |
| p95 | 33.0 ms |
| p99 | 362 ms |
| p99.9 | 682 ms |
Requests per latency range (48 log-spaced ranges from 4 ms to 8 s): 5.5 ms to 6.4 ms: 2; 6.4 ms to 7.5 ms: 6; 7.5 ms to 8.8 ms: 33; 8.8 ms to 10.3 ms: 143; 10.3 ms to 12.1 ms: 400; 12.1 ms to 14.2 ms: 935; 14.2 ms to 16.6 ms: 1577; 16.6 ms to 19.5 ms: 2021; 19.5 ms to 22.8 ms: 1960; 22.8 ms to 26.7 ms: 1481; 26.7 ms to 31.3 ms: 808; 31.3 ms to 36.7 ms: 329; 36.7 ms to 43.0 ms: 102; 43.0 ms to 50.4 ms: 27; 50.4 ms to 59.0 ms: 3; 130 ms to 153 ms: 2; 153 ms to 179 ms: 3; 179 ms to 210 ms: 5; 210 ms to 246 ms: 9; 246 ms to 288 ms: 18; 288 ms to 337 ms: 28; 337 ms to 395 ms: 23; 395 ms to 463 ms: 28; 463 ms to 542 ms: 23; 542 ms to 635 ms: 16; 635 ms to 744 ms: 12; 744 ms to 872 ms: 4; 872 ms to 1.02 s: 2.
- mean
- 26.8 ms
- p50
- 19.3 ms
- p95
- 33.0 ms
- p99
- 362 ms
- p99.9
- 682 ms
Many hosts, one number
| Host | Traffic | Slow path | p99 | |
|---|---|---|---|---|
| 1 | 58% | 2.7% | 416 ms | |
| 2 | 26% | 1.3% | 269 ms | |
| 3 | 11% | 0.6% | 37.1 ms | |
| 4 | 5% | 0.3% | 35.0 ms | |
| Average of the host p99s | 189 ms | |||
| p99 of all requests merged | 362 ms |
- average of host p99s
- 189 ms
- true merged p99
- 362 ms
- average is off by
- 48% low
The average treats a host with a sliver of the traffic as equal to the busiest one. The merged p99 counts every request once.
Fixed buckets, 10 ms wide
| Percentile | Fine buckets | Fixed buckets | Error |
|---|---|---|---|
| p50 | 19.3 ms | 19.2 ms | -1% |
| p95 | 33.0 ms | 35.2 ms | +7% |
| p99 | 362 ms | 363 ms | +0% |
| p99.9 | 682 ms | 680 ms | -0% |
The fine value comes from a histogram with buckets 2 percent wide. The bucketed value is what a metrics system with fixed, equal-width buckets would report, interpolating inside the bucket.
One worker, two ways to measure it
Waits for each reply
Sends the next request once the last one has been answered. Time is counted from the send.
- p50
- 19.3 ms
- p99
- 392 ms
- p99.9
- 815 ms
Keeps its schedule
Intends one request every 55 ms. Time is counted from the intended send, so queueing counts.
- p50
- 21.3 ms
- p99
- 815 ms
- p99.9
- 1.01 s
Same 2,000 requests, same service times. The waiting generator reports a p99 that is 2.1 times lower than the schedule-keeping one.
What to try
Each one sets up a starting point. Then make the change it describes.
The mean hides the tail
Keep two percent slow requests and make the hosts identical. Read the mean, the median and p99 in the strip of numbers under the histogram.
Look for. The mean sits a little above the median, because the slow requests pull it up. p99 is many times higher than both, and the histogram shows the second hump the mean smooths over.
Cross the one percent line
Set slow requests to 0.5 percent, then slowly raise it to 3 percent. Watch p99 and the mean as you go.
Look for. The mean rises smoothly. p99 stays near the fast path until the slow share passes one percent, then jumps into the slow path. Rare slowness is invisible to p99 and visible to p99.9.
Average the hosts
Keep the default imbalance and compare the average of the host p99s with the p99 of all requests merged. Then drag Host imbalance to zero.
Look for. With unequal hosts the average is far from the merged p99, because it counts a host with a sliver of the traffic as much as the busiest one. With identical hosts the two agree.
Coarse buckets
Set the bucket width to 100 ms and compare the fine and fixed columns.
Look for. Most requests fall into the first bucket, so the median is read from an interpolation inside it and comes out far too high. The tail is wide enough to survive coarse buckets better.
A generator that waits
Set the stall to 1500 ms and the load to 0.5, and compare the two ways of measuring the one worker.
Look for. The generator that waits for each reply sends nothing while the worker is stalled, so it records the stall once. The one that keeps its schedule records every request that should have gone out, and its p99 is much higher.
New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.
Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms