Jitter and the tail: measuring p99.9, finding the interference, and not lying to yourself with averages

The tail is the product. Report a percentile at a load and a payload, generate load at a fixed rate so you do not hide your own stalls, and hunt interference in a fixed order: scheduler, interrupts, memory, runtime, power, network.

Read the briefing
About 3 min to read 6 drills

What to remember

  1. You cannot claim p99.9 from a thousand samples. One in a thousand means a handful of observations. Tens of thousands minimum, and say how many you took.
  2. Coordinated omission makes a bad tail look good. A generator that waits for the reply stops sending during a stall, so the stall never appears in the histogram. Use fixed-rate load and latency correction.
  3. Never average a percentile. The mean of two hosts' p99 is not anyone's p99. Merge histograms, do not average summaries.
  4. Check interference in order: scheduler, IRQ, memory, runtime, power, network. That order matches how often each one is the answer. Most 'network' tails are local.
  5. A latency target with no load and no payload is unfalsifiable. 'p99.9 under 40 µs at 200k msg/s with 200-byte payloads' is a claim. '40 microseconds' is a sales figure.

The big picture

Tail latency work is measurement discipline plus a search order. The measurement has to be honest about how many samples it took and what it was doing while the system stalled; the search has to start with the interference sources that are actually common rather than the ones that are interesting.

The mental model

Every outlier is something else getting the CPU, the memory bus, the cache or the NIC at the wrong moment. Your job is to name that something. The percentile is how you notice, the trace is how you name it.

In depth

Measuring honestly

Report p50, p99, p99.9 and max — and the sample count, because a percentile is an estimate whose error depends on how far into the tail you went. Record histograms (HdrHistogram or equivalent) rather than summaries, so results can be merged across hosts and windows without the arithmetic sin of averaging percentiles.

Coordinated omission is the classic self-deception: a closed-loop generator that waits for each response before sending the next one stops issuing requests exactly while the system is stalled, so the stall is missing from the data. Fixed-rate (open-loop) generation, or explicit latency correction, is what keeps the number honest. Run the generator on a separate host, pin it too, and confirm it is not itself the bottleneck.

The search order
  1. Scheduler: preemption, migration and run-queue contention. perf sched latency, scheduler tracepoints, /proc/<pid>/status non-voluntary context switches.
  2. Interrupts and softirqs: /proc/interrupts deltas per core, /proc/softirqs, and whether they land on the isolated cores.
  3. Memory: page faults, THP compaction (compact_stall), reclaim (PSI), and NUMA misses.
  4. Runtime: GC pauses, allocator behaviour, JIT compilation, lock contention.
  5. Power and clocks: C-state exits, frequency transitions, SMIs (which are invisible to the OS and show up only as unexplained gaps).
  6. Network: only after the above, because most "network" tails are local — buffer drops, IRQ contention, or a busy consumer.
Tools for tails rather than means

cyclictest gives the kernel's own jitter floor, which is the ceiling on how good your application can be. perf record/report finds where CPU time goes; off-CPU analysis (bpftrace, BCC offcputime) finds where time is spent waiting, which is where most tail latency lives. perf stat and hardware counters show cache misses and TLB behaviour. funclatency/biolatency-style histograms answer "how bad, how often" instead of "what is the average". Tracing has a cost: prefer sampling and eBPF over ptrace-based tools on a live path, and never leave a tracer running on a production trading host without a time bound.

Stating a target

A latency SLO for a trading path is a percentile, at a rate, with a payload, on a named path — for example "p99.9 of gateway-in to order-out under 40 µs at 200,000 messages per second with 200-byte payloads, measured with hardware timestamps". That form is falsifiable, comparable across releases, and immune to the usual argument about whose measurement is right. The same discipline turns into a regression alarm: run it nightly, alert on percentile drift, and keep the environment fingerprint next to the number.

Myths and facts

Myth: The average is fine if the distribution is tight.

Fact: You do not know the distribution is tight until you look at the tail; the average is exactly the statistic that hides the outliers you care about.

Myth: More load samples always give a better percentile estimate.

Fact: Samples help, but a closed-loop generator with coordinated omission produces a confidently wrong tail no matter how long it runs.

Myth: Tail latency is usually the network.

Fact: It usually is not. Scheduler, interrupts and memory account for most of it on a tuned box; the network is the last place to look, not the first.

Myth: Tracing is free if it is eBPF.

Fact: It is cheap, not free, and per-event probes on a hot path can be measurable. Bound it and measure the measurement.

How pros do it

  • Record histograms, quote p50/p99/p99.9/max plus sample count, and never average percentiles.
  • Generate load at a fixed rate from a separate pinned host; correct for coordinated omission.
  • Search interference in order: scheduler, interrupts, memory, runtime, power, network.
  • Establish the kernel jitter floor with cyclictest so you know what is achievable before blaming the application.
  • Express targets as a percentile at a load and a payload on a named path, and run them nightly as a regression alarm.

Questions people ask

What is a good first check for an outlier storm?

Scheduler and interrupts: non-voluntary context switches on the hot thread and which processes have run on the isolated cores, then the per-core deltas in /proc/interrupts. Those two explain most tails on a tuned box. Say the median first — if it has not moved, the path is fine and the problem is local interference.

Can I use averages for dashboards?

For capacity trends, yes; for any latency claim, no. The average is exactly the statistic that hides the outliers you care about, and a latency dashboard without percentiles will hide the incident. Quote p50, p99, p99.9 and max, with the sample count.

How many samples for p99.9?

Tens of thousands as a floor for a usable estimate, hundreds of thousands if you want it stable release to release. One in a thousand means a thousand samples give you one point in the tail. State the count with the number, and record histograms so results merge instead of being averaged.

Is off-CPU analysis worth the setup?

Yes, once the CPU work is tuned, because most of what is left in the tail is waiting rather than computing. bpftrace or BCC offcputime shows where the time is spent blocked. The caveat is cost: sample rather than trace every event, and bound it on a live trading host.

How do I catch SMIs?

You cannot see them from the OS; you see unexplained gaps that no tracepoint covers. turbostat reports SMI counts per interval, and the fix is usually BIOS settings or vendor firmware rather than anything in Linux.

Further reading

Drills · 6

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

Your load test reports p99 of 900 µs, yet you can watch the service freeze for about 200 ms every minute. The generator sends the next request only after it gets the previous reply. Why does the number look fine?

  1. Coordinated omission: while the service is stalled the generator sends nothing, so the stall contributes one sample instead of the thousands it displaced. Switch to fixed-rate generation or apply latency correction. Closed-loop generation stops measuring exactly during the event you care about.
  2. The generator needs more threads. More closed-loop threads mask it slightly differently; the model is the problem.
  3. p99 excludes outliers by definition. A percentile includes everything below it; it does not discard outliers.
  4. The freeze is shorter than reported and p99 is correct. Under honest fixed-rate load every request that arrives during a 200 ms freeze records that wait; a closed loop records one.
In short

This is coordinated omission: the generator stops sending during the freeze, so the freeze barely shows up; use a fixed-rate generator instead.

Why

With a fixed-rate generator, a 200 ms stall at 10,000 requests/second means about 2,000 requests each waiting up to 200 ms — which is what the histogram should show. This is the single most common reason a benchmark and production disagree.

The common mistake

Blaming the generator's thread count or adding load. More closed-loop threads still stop sending during the stall; the model is wrong, not the volume.

Read the docs

2 Answer out loud

A tuned host's p99.9 just got worse and the median has not moved. Walk me through your search, in order, and tell me what evidence moves you from one suspect to the next. Four to six sentences.

In short

A strong answer checks the scheduler first, then interrupts, memory, runtime and power, with the network last, and names the counter for each.

What a strong answer does
  • order: Scheduler, then interrupts, then memory, then runtime, then power, then network — with the reason that order matches base rates.
  • evidence: Names the specific counter that implicates or clears each suspect: non-voluntary context switches, /proc/interrupts deltas, compact_stall, GC logs, turbostat, then NIC drops.
  • discipline: One change per measurement, percentile comparison against the recorded baseline, environment fingerprint captured.
Why

The ordering and the per-suspect counter are what distinguish a method from a tool list.

The common mistake

Starting with the network. On a tuned box most 'network' tails are local — a co-resident process, an IRQ on the wrong core, a compaction stall — and an interviewer hears network-first as inexperience.

3 Pick the strongest answer

Two hosts serve the same feed. One reports p99 of 300 µs, the other 700 µs. What is the fleet's p99?

  1. The fleet p99 is 500 µs, the average of the two. Only true by coincidence; it is not derivable from the two summaries.
  2. The fleet p99 is 700 µs, because the worse host sets the tail. Only if the slower host carries nearly all the traffic; with volumes unknown the merged p99 can sit anywhere between the two.
  3. The fleet p99 is 1 ms, because the values add. Percentiles are not additive either.
  4. Only that it lies somewhere between 300 and 700 µs: exactly where depends on both hosts' request volumes and shapes, because percentiles do not average. Merge histograms instead. Averaging percentiles is not a valid operation; a merged percentile sits between the parts, and only the underlying distributions say where.
In short

The fleet p99 is somewhere between 300 and 700 µs; you cannot average percentiles, so merge the histograms.

Why

This is why histogram-based metrics exist: Prometheus histograms and HdrHistogram merge correctly because they carry buckets, not summaries. Client-side computed quantiles (Prometheus summaries) cannot be aggregated at all.

The common mistake

Saying 500 µs. The mean of two p99s is nobody's p99; only the merged histograms can say where the fleet's tail sits.

Read the docs

4 Read the output

The tail is fifty times worse since 14:00 and the median has not moved. What is hitting it, and what do you do?

# p99.9 order latency: 38 µs normal, 1.9 ms since 14:00. p50 unchanged at 9 µs.
$ grep -E 'nonvoluntary|voluntary' /proc/24117/status
voluntary_ctxt_switches:        118
nonvoluntary_ctxt_switches:     41822
$ grep -m1 . /proc/pressure/cpu
some avg10=0.42 avg60=0.38 avg300=0.31 total=88213411
$ awk 'NR==1{for(i=1;i<=NF;i++)if($i=="CPU10")c=i+1;next} $c>0{print $1,$c}' /proc/interrupts
LOC: 188034
RES: 2917
$ ps -eo psr,pid,comm --sort=psr | awk '$1==10'
 10  24117 strategy
 10  99231 node_exporter
  1. Something else is running on the isolated core: node_exporter shares CPU 10 with the strategy thread, and 41,822 non-voluntary context switches say the strategy is being preempted. Move the agent to the housekeeping cores (cpuset or systemd CPUAffinity) and re-measure. Non-voluntary switches plus a co-resident process on the same CPU is preemption, not a network or memory problem.
  2. p50 unchanged means the measurement is broken. An unchanged median with a blown tail is the classic signature of intermittent interference.
  3. Only the timer and reschedule interrupts land on CPU10, so the core is quiet and the application must be at fault. Interrupts are only one interference source; a co-scheduled process is another.
  4. CPU pressure of 0.42 shows the host is saturated; add cores. 0.42% stall time is nothing; the problem is local to one core.
In short

A monitoring agent is running on the isolated core 10 and preempting the strategy; move it to the housekeeping cores.

Why

Unchanged p50 with a 50× tail is interference, and the first two places to look are the scheduler and interrupts. Here psr (the CPU a process last ran on) puts a monitoring agent on the isolated core — a routine rollout defeating the isolation.

Read the docs

5 Scenario: what do you do next?

A vendor claims their gateway adds "under 10 microseconds". Your own measurement of the same path shows p99 at 140 µs. Both sides are convinced. You have a meeting in two hours.

Step 1. What do you establish first?

  1. Accept the vendor number since they know their product. Their number is probably true of a narrower path than yours.
  2. Re-run your test with more load to prove the vendor wrong. You do not yet know you are measuring the same thing.
  3. Escalate commercially. Premature, and it damages a relationship you will need for the fix.
  4. What each number actually measures: which two points, which percentile, at what message rate and payload size, with software or hardware timestamps, and over how many samples. Disagreements about latency are almost always disagreements about definitions, and this list resolves most of them before anyone argues.

Step 2. Their figure is a median, wire-to-wire inside the appliance, at 10k messages/second. Yours is p99, application-to-application, at 180k/s including the socket path. What now?

  1. Average the two numbers as a working figure. Meaningless; they measure different things.
  2. Assume the difference is your own stack and start tuning. Plausible, but measure before you tune — that is the whole discipline.
  3. Reconcile by decomposing your path with hardware timestamps at each hop, so you can show which segment the 140 µs sits in — then discuss the segment that is theirs with a comparable percentile and rate. Both numbers can be right; the useful conversation is about the segment and the statistic.
  4. Ask them to publish p99.9 at your rate and treat that as the SLA. A reasonable ask eventually, but you still cannot attribute your 140 µs without decomposition.

Step 3. Systemic fix so this does not recur?

  1. Insist all vendors quote p99.9. Better, but without endpoints, rate and payload it is still unfalsifiable.
  2. Build your own gateway. An enormous response to a definitional disagreement.
  3. A written latency definition per path — endpoints, percentile, rate, payload, timestamp source — used in vendor evaluations, internal SLOs and the nightly regression, with hardware-stamped capture as the shared source of truth. Makes future claims comparable and turns disputes into a lookup.
In short

First agree what each number measures: the two endpoints, the percentile, the rate, the payload and the timestamp source.

Why

This is the most common real argument in latency-sensitive infrastructure. The answer interviewers want is that a latency number is a five-part claim, and that decomposition with hardware timestamps is what converts opinion into attribution.

Read the docs

6 Quick recall

Your load generator waits for each reply before sending the next request, so it stops sending during a stall. What is that measurement problem called?

In short

The name is coordinated omission.

Accepted

coordinated omission · coordinated-omission · co

Why

Coordinated omission: closed-loop generators stop issuing requests while the system is stalled, so the stall is missing from the histogram.

Next lesson Kernel tuning for latency: isolcpus, affinity, NUMA, huge pages, and what actually moves the number
Drill · Jitter and the tail
0:00

Loading…