Try
↑ ↓ move↵ openesc close
In this lesson · topic 3 of 7
  1. 1. Why the average lies
  2. 2. Histograms, merging and honest load tests
  3. 3. Average the hosts, widen the buckets, stop waiting
  4. 4. When an averaged p99 is half the real one
  5. 5. How many requests stand behind a p99
  6. 6. Turning latency into a good-events ratio
  7. 7. Fifty hosts, one stall, one bucket choice

Topic 3

Average the hosts, widen the buckets, stop waiting

8 min read

One stream, four views

The lab below generates the stream from the first topic and then shows it four ways. The histogram and the strip of numbers show the mean and the percentiles. The host table compares the average of the host p99s with the real merged one. The bucket table compares fine and fixed buckets. The last panel runs one worker under both kinds of load generator, with a periodic stall.

Predict before you press play

The hosts are unequal: the busiest has the most slow requests and the smaller ones are healthier. When you compare the average of the host p99s with the p99 of all requests merged, what do you expect?

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.

Full-page version with guided experiments: Latency percentiles lab.

Things to try

  1. Drop Host imbalance to 0 and watch the average of the host p99s settle on the merged p99. Put it back and watch them separate.
  2. Slide Slow requests from 0.5 percent up to 3 percent. The mean climbs smoothly. The p99 stays low and then jumps once the slow share passes one percent.
  3. Widen the buckets to 100 ms. Compare the fine and fixed columns for the median and for the p99.
  4. Raise the stall length. The waiting generator’s p99 hardly changes, while the schedule-keeping generator’s does.
  5. Raise the load on the tested worker from 0.2 to 0.8. Queueing makes the schedule-keeping measurement grow even without a stall.

The full-page lab adds five guided experiments, each applied with one click.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms