Predict the output
What do the two lines print?
import statistics
latencies_ms = [20] * 95 + [900] * 5
cuts = statistics.quantiles(latencies_ms, n=100, method="inclusive")
print("mean", statistics.fmean(latencies_ms))
print("p50", cuts[49], "p99", cuts[98])Hint 1 of 1
95 × 20 + 5 × 900 = ?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A mean 64.0 then p50 20.0 p99 900.0
Correct. The mean sits between the two groups; the percentiles show both.
The mean, (95 × 20 + 5 × 900) / 100 = 64, describes no actual request. The median is 20 and the 99th percentile is 900, which together show the slow tail.
Why not the others?
- B
mean 20.0thenp50 20.0 p99 20.0. Five requests take 900 ms. - C
mean 460.0thenp50 460.0 p99 900.0. That would be the midpoint of two values, not the mean of 100. - D
mean 64.0thenp50 64.0 p99 64.0. Percentiles come from the sorted values.