Try
↑ ↓ move↵ openesc close

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

Latency of every request so far
51020501002005001 s2 s5 smean 26.8 msp50 19.3 msp95 33.0 msp99 362 msp99.9 682 mslatency in ms, log scale. Bar height is the square root of the count.
mean
26.8 ms
p50
19.3 ms
p95
33.0 ms
p99
362 ms
p99.9
682 ms

Many hosts, one number

Each host reports its own p99. The two rows below compare ways of combining them.
HostTrafficSlow pathp99
158%2.7%416 ms
226%1.3%269 ms
311%0.6%37.1 ms
45%0.3%35.0 ms
Average of the host p99s189 ms
p99 of all requests merged362 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 read from fine buckets and from fixed buckets
PercentileFine bucketsFixed bucketsError
p5019.3 ms19.2 ms-1%
p9533.0 ms35.2 ms+7%
p99362 ms363 ms+0%
p99.9682 ms680 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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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