performance

A Mean Is Not a Latency, But Little's Law Needs One Anyway

Every latency guide gives you the same rule: report percentiles, never a mean. The rule is correct. The average sits above the typical request and well below the tail, so it describes neither the request most users get nor the one that blows the deadline. Put a mean on a latency dashboard and you have published a number that is true about the arithmetic and false about the experience.

Here is the catch. Two of the cheapest and most useful predictions in performance work take a mean as their only numeric input. Little’s Law uses one to tell you how much work is in flight. Amdahl’s Law uses one to tell you how far adding cores will get you. Both run on a napkin, before you build anything, and neither has a percentile anywhere in it. Ban the mean outright and you lose them.

So the mean is the wrong number to report and the right number to model with. That is not a contradiction, it is a filing problem, and it has a clean fix: give the mean exactly one place to live, a labelled block separate from the latency report, and keep it out of everywhere else. Report with percentiles, model with means, and never let the two touch.

The examples below come from a parcel sortation line, a materials-handling system a conveyor runs through a warehouse. A scanner reads each parcel, a handler decides where it goes, and a diverter pushes it to the right chute before it rolls past. The deadline is physical: belt speed times the distance from scanner to diverter. Miss it and the parcel takes the wrong exit. The same shape, a stream of arrivals through a stage with a service time, is where both laws earn their keep.

A mean is a bad latency

Start with why the average is the wrong thing to report. Here is the residence time W for parcels passing through the handler, the time from a parcel’s arrival to the handler marking it done, measured on a C++ implementation:

A horizontal spectrum of W, residence time, with four markers left to right: p50 at 0.78 ms labelled the typical parcel; W-bar the mean at 1.05 ms labelled the model input and drawn in the amber accent; p99 at 4.35 ms; and p99.9 at 8.5 ms labelled the tail. An arrow beneath points toward slower. A slate emphasis box reads that the mean is useless as a latency because it is neither the typical parcel nor the tail, yet essential as L equals lambda times W-bar, the only value that ties queue length to rate.
Figure 1: The mean residence time, 1.05 ms, sits above the typical parcel (p50, 0.78 ms) and far below the tail (p99, 4.35 ms). As a latency it describes no real parcel. It has exactly one job, and Figure 2 shows it.

The mean is 1.05 ms. The p50 is 0.78 ms and the p99 is 4.35 ms. Report the mean and a reader concludes parcels take about a millisecond, which overstates the common case by a third and hides the tail by a factor of four. The mean is not a summary of the distribution. It is a single arithmetic fact about it, and a misleading one to hand someone who wants to know how slow things get.

That is the case for keeping it out of every latency report. Reports should carry p50, p99, and p99.9, and no average. If you stop there, though, you have thrown out two predictions you want.

A mean is the one thing the laws need

Little’s Law states that for a stable system the number of items inside it equals the arrival rate times the time each item spends inside:

L = lambda x W

Point it at the belt and it predicts the work in flight before you run anything. The conveyor carries a parcel from scanner to diverter in 480 ms, and at 1,000 parcels per second that is 1000 x 0.48 = 480 parcels on the belt at once, from two parameters and no measurement. Point it at the handler instead and W is the mean residence time. There is no percentile form of this law. W is a time-average by definition, because only the average ties the long-run queue length to the arrival rate. The p50 will not do it; the p99 will not do it. The law needs the mean or it needs nothing.

Expressed in code, the law is a single line, and the parameter name carries the warning about which value belongs there:

// cpp/include/lowlat/ch02/model.hpp
[[nodiscard]] constexpr double littles_L(double lambda_per_s, double w_seconds) noexcept {
  return lambda_per_s * w_seconds;
}

// Amdahl's Law: with serial fraction s, the speedup on n workers.
[[nodiscard]] constexpr double amdahl_speedup(double serial_fraction, unsigned workers) noexcept {
  return 1.0 / (serial_fraction + (1.0 - serial_fraction) / static_cast<double>(workers));
}

Amdahl’s Law has the same dependency. If a fraction s of a one-worker run cannot be parallelised, then N workers give a speedup of 1 / (s + (1 - s) / N), and no number of workers passes 1/s. That s is also a time fraction, another average: the share of wall time spent in the serial section, over the whole run. You measure it rather than guess it, by timing every serial section at one worker and dividing the summed serial time by the summed wall time. Here the serial section is a lock around a shared sort-plan update:

// cpp/src/amdahl.cpp
// Serial fraction s = time inside the lock / wall time, at N = 1. Ratio of sums
// over the calibration runs.
std::int64_t lock_total = 0, wall_total = 0;
for (int i = 0; i < o.calibration_runs; ++i) {
  const Run r = run_batch<true>(plan, o, 1);
  lock_total += r.in_lock_ns;
  wall_total += r.wall_ns;
}
const double s = static_cast<double>(lock_total) / static_cast<double>(wall_total);

Both laws eat a time-average and predict structure. Neither one has a percentile anywhere in it. Forbid means from the codebase and you have also forbidden the two cheapest predictions in performance engineering.

Quarantine, don’t ban

The resolution is not to relax the rule on reports. It is to give the mean a room of its own. After each run the program writes its percentile report as usual, and beside it writes a separate model block that is the only structure allowed to hold an average. Every field name states what it is:

// cpp/src/littles.cpp
// --- the model block: the only place a mean appears ---------------------
const double lambda   = static_cast<double>(o.rate_hz);
const double w_mean_s = static_cast<double>(handler.w_sum_ns() / received) / 1e9;
const double l_sampled   = static_cast<double>(sampled.sum_in_system) / sampled.samples;
const double l_predicted = lowlat::ch02::littles_L(lambda, w_mean_s);
const double rel_err     = (l_sampled - l_predicted) / l_predicted;
const nlohmann::json model = {
    {"law", "Little: L = lambda * W"},
    {"lambda_per_s", lambda},
    {"L_sampled_time_average", l_sampled},
    {"W_mean_seconds_modelling_input", w_mean_s},
    {"predicted_L", l_predicted},
    {"relative_error", rel_err},
};

Read the field names. It is not w_mean_ms, it is W_mean_seconds_modelling_input. The label is part of the value. A reader later grepping the reports for a latency to quote cannot pick this one up by accident, because the name tells them it is a model input, not a result. The latency report and the model block sit next to each other and never get confused, because the data structure itself refuses to confuse them.

A diagram of one latency report for a run of 10,000 parcels at 1000 per second. Inside a report frame sit two boxes. The left box, reported latency, holds percentiles only: p50 0.78 ms, p99 4.35 ms, p99.9 8.5 ms, and the note no mean here. The right box, drawn in the amber accent and labelled the only mean, is the model block holding W-bar 1.05 ms and lambda 1000 per second, a labelled modelling input. An amber arrow carries W-bar out of the model block into a slate box for Little's Law, L equals lambda times W-bar, which feeds a result box reading predicted L 1.05, sampled L 1.05, error plus 0.5 percent. A caption across the top reads that a mean is never a latency and appears once, labelled, as a model input.
Figure 2: One run produces two things. The latency report carries percentiles and no mean. The model block is the only structure that holds an average, and it feeds Little's Law, not the SLO.

Make the block part of the shared reporting tool, not a convention each program is trusted to follow. The report writer takes an optional model argument and writes it beside the percentiles, so a C++ program hands it JSON, a Python one a dict, a Java one a map, and the key is omitted when a run has no model to attach. The quarantine then holds by construction, in any language that uses the tool.

The model predicts, the measurement checks

Keeping the mean in its own block buys more than tidiness. It lets a run check the model against reality in the same pass. The program samples the live queue length L from a separate thread while the per-parcel clock records W, so L and W arrive by independent mechanisms. If L = lambda x W-bar holds, both are confirmed at once. Sampled L matched the prediction within 0.3 to 0.5 percent in C++ and within 1.3 to 4.3 percent in Java.

The sharpest demonstration that the discipline works comes from where the model fails. Amdahl’s Law knows about the lock, because the lock is what s measures. It knows nothing about Python’s Global Interpreter Lock, because the GIL is not in the formula. Run the same parallel batch on Python threads and watch the prediction break:

Workers (N=4) Predicted Measured
C++ ~3.1x 2.83 to 2.85x
Java ~3.1x 2.74 to 2.75x
Python processes ~3.0x 2.92 to 2.97x
Python threads ~3.1x 0.47 to 0.50x

CPU-bound Python threads under the GIL do not merely fail to speed up. They run more than twice as slow at four workers as at one, because every lock and barrier hand-off also pays a GIL hand-off, and the interpreter still runs one thread at a time. Processes, one interpreter each, track the prediction closely. The threads row is a negative control: the model misses it wildly, and that miss is the signal. A clean, labelled model is one you can hold a measurement against and learn exactly which mechanism you left out. A mean smuggled into a latency report could never tell you that, because you would never have known which number was a claim and which was an input.

The takeaway

The rule is small and it survives contact with real code:

  • A mean is a poor summary of a latency distribution. It is neither the typical request nor the tail. Report percentiles.
  • A mean is the required input to Little’s Law and Amdahl’s Law. There is no percentile substitute; the laws tie averages to structure.
  • Resolve the tension by quarantine, not prohibition. Latencies stay percentiles in the report; means live in a labelled model block whose field names mark them as inputs.
  • A clean model pays off when it is wrong. The Python-threads miss is only legible because the mean was never allowed to pose as a result.

Source project

The numbers, figures, and code in this post are drawn from Chapter 2, “Modelling with Little’s Law and Amdahl’s Law”, of Low-Latency Engineering in C++, Python & Java, a chaptered, measured guide to latency engineering with runnable C++20/23, Python 3.14, and Java 25 examples built on the parcel sortation line used above. The full chapter adds the sampler that measures L, the barrier-phased workload behind the Amdahl numbers, and a free-running-lock variant that beats the Amdahl curve.

The code shown is excerpted from the r02.x release: model.hpp, littles.cpp, and amdahl.cpp. The repository has the Java and Python counterparts and the verify.sh that asserts every number quoted here.

More posts drawn from the catalog are indexed on the Pattern Catalyst hub.

Figures were measured on a bare-metal 8-core/16-thread Intel laptop CPU, Fedora 44, governor powersave, untuned. A measurement is only comparable against its own machine profile.