Start free trial
Start free trial Log in

14-day free trial. No credit card.

Laravel p95 latency: measure it, alert on it, fix it

What p95 latency shows that an average hides, and how to compute it in Laravel with or without an APM.

  • Guide
  • 3 min read

What is p95 latency in Laravel and how do I measure it?

P95 latency means 95% of requests complete in this time or faster, and the slowest 5% take longer. It's the industry-standard way to describe response-time health without letting outliers dominate. Compute it by recording every request's duration, sorting ascending, and taking the value at the 95th-percentile index. Laravel's nightwatch package records per-request duration; NightOwl shows p95 per route on its Requests page, with a P50/P95/P99 duration chart over the selected window.

Updated

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/orders149ms180ms210ms280ms
/api/checkout149ms50ms6,500ms12,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

sql
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:

  1. Per-route, not global. Global p95 hides per-endpoint regressions. Alert on specific high-value routes (/checkout, /login, /api/orders).
  2. 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.
  3. 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.

Your p95 per route, without writing the SQL

NightOwl shows P95 for every route and a P50/P95/P99 duration chart over the window you pick. Filter a route to its requests at or above P95 or P99, then open one to see which query or external call made it slow.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

What is p95 latency?

P95 latency is the 95th percentile of response times: 95% of requests complete in this time or less, and the slowest 5% take longer. If a route has a p95 of 400ms over the last hour, that means 19 out of every 20 requests were at or below 400ms. P95 is the industry-standard way to describe 'the slow tail' without letting extreme outliers dominate.

Why use p95 instead of average latency?

Average hides the slow tail. A route that serves 98 requests in 50ms and two requests in 10 seconds has an average of 249ms, which looks acceptable. Its p95 is 50ms and its p99 is 10s, which correctly tells you 'most requests are fast but 2% are catastrophic.' Users experience the tail, not the average.

How do I calculate p95 latency in Laravel?

Collect every request's duration for a time window, sort them ascending, and pick the value at position ceil(0.95 × count), counting from 1. That's the exact (nearest-rank) p95. In SQL: ORDER BY duration ASC LIMIT 1 OFFSET ceil(count × 0.95) - 1, with the count taken first. Streaming approximations (t-digest, HDR histograms) let you compute p95 without storing every sample, which is what many APMs use at scale.

What's a good p95 latency for a Laravel endpoint?

Depends on the endpoint class. UI-blocking API endpoints: under 200ms p95 is good, 200-500ms is acceptable, above 500ms is a UX problem. Full page renders and write endpoints: under 500ms is good, 500ms-1s is acceptable. Background jobs and reports: seconds-to-minutes are fine if they're not blocking users. Set per-endpoint SLOs instead of a global threshold.

P95 vs p99 latency: which should I track?

Both, for different questions. P95 is the 'typical bad case'. It covers most user pain and is stable enough to trigger alerts on. P99 is the 'rare bad case': extremely slow outliers that might indicate specific user segments or data patterns hitting worst-case paths. Alert on p95 for day-to-day monitoring; investigate p99 when you're chasing long-tail bugs.

How do I monitor p95 latency trends in Laravel?

You need per-minute or per-hour buckets with p95 computed inside each bucket. Bucket size depends on traffic: high-traffic routes can use 1-minute buckets; low-traffic routes need 15-minute or hourly buckets to have enough samples. Plotting p95 over time shows regressions (a deploy made it worse) and trends (a route is slowly degrading as data grows).

Can I compute p95 from Laravel logs?

Yes, if your logs record per-request duration. Parse the log, sort by duration within a time window, pick the 95th-percentile value. Painful to do continuously, since you'd be re-parsing logs. Many APMs compute p95 at ingest time with streaming algorithms. If you want p95 without an APM, log to a database and query it. PostgreSQL has percentile_disc and percentile_cont. MySQL has neither, so count the rows first and fetch the value with ORDER BY duration LIMIT 1 OFFSET n, computing n in your application.

Why does p95 latency spike on deploy?

Usually one of: (1) opcache cold-start on first requests to new code, (2) autoload cache rebuilding, (3) warmed-cache misses if you deploy-clear caches, (4) connection pool re-establishment. Warm the app before routing traffic (health check + pre-warming script), and use php artisan optimize after deploy to prebuild caches.

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial

Related

See your p95 per route on your own app

Start the agent and each route's P95 and P99 fill in from your real traffic. No credit card needed.