Judging an app by its average response time is a common and costly mistake in performance monitoring. A user remembers the slow request, and the slow request is exactly what an average smooths away. p95 puts a number on that part of the experience: the slowest 5% of requests, which a real fraction of your users hit every day.
Why average is misleading
Consider two routes with the same average latency of 149ms:
| Route | Avg | p95 | p99 | Max |
|---|---|---|---|---|
| /api/orders | 149ms | 180ms | 210ms | 280ms |
| /api/checkout | 149ms | 50ms | 6,500ms | 12,000ms |
Same average. Wildly different user experience. /api/orders is uniformly slow-ish; /api/checkout is fast for most people but catastrophic for a long tail. The percentiles show a difference the average can't.
How to compute p95 in Laravel
The exact (nearest-rank) definition: sort all N durations ascending and pick the value at position ceil(N × 0.95), counting from 1. With 1,000 requests, p95 is the 950th value.
Exact p95 in PostgreSQL
SELECT
route,
COUNT(*) AS requests,
AVG(duration_ms) AS avg_ms,
percentile_disc(0.5) WITHIN GROUP (ORDER BY duration_ms) AS p50,
percentile_disc(0.95) WITHIN GROUP (ORDER BY duration_ms) AS p95,
percentile_disc(0.99) WITHIN GROUP (ORDER BY duration_ms) AS p99
FROM request_logs
WHERE created_at > NOW() - INTERVAL '1 hour'
GROUP BY route
ORDER BY p95 DESC
LIMIT 20; percentile_disc returns an actual recorded duration, the nearest-rank value defined above. percentile_cont interpolates between the two neighbouring values instead. MySQL has neither function, and its OFFSET only accepts a literal or a placeholder, not an expression. Run a COUNT(*) first, compute ceil(count × 0.95) - 1 in PHP, then bind it: ORDER BY duration_ms LIMIT 1 OFFSET ?.
How APMs compute p95 at scale
Storing every request's duration forever is expensive. Many APMs use streaming percentile algorithms (t-digest or HDR histograms) that estimate p95 from a small fixed memory footprint with bounded error.
NightOwl stores every request's duration in your PostgreSQL. For short time windows it computes an exact nearest-rank percentile from those raw rows (percentile_disc, or ORDER BY duration OFFSET ceil(n × 0.95) - 1 LIMIT 1). For wide windows a full scan of the raw rows timed out on busy apps, so it reads histogram rollups and estimates the percentile with DDSketch, which keeps the estimate within 1% of the true value.
Alerting on p95
Good p95 alerts have three properties:
- Per-route, not global. Global p95 hides per-endpoint regressions. Alert on specific high-value routes (/checkout, /login, /api/orders).
- Comparative, not absolute. "p95 exceeded 500ms" is a weak signal if the baseline was 450ms. "p95 is 30% above last week's median" catches regressions.
- Sustained, not instant. Alert when p95 exceeds threshold for 5+ consecutive minutes. Single-minute spikes are usually noise.
NightOwl doesn't alert on p95 today. Its alerts fire on individual records: a performance issue opens when a single request (or job, query or other record) meets the duration threshold you set for it, and later slow records add to the same issue instead of alerting again.
What p95 doesn't tell you
P95 is a single number. It can't tell you why the slow tail is slow. Pair it with:
- Per-request trace view: see which query or external call ate the budget (the slow endpoints guide walks through this)
- User dimension: is the slow tail concentrated in specific user segments?
- Time dimension: is the tail uniform or spiky at certain hours?
- p99 and max: does p99 correlate with p95 or does it blow up independently? See p95 vs p99 latency.