Skip to content
Web Performance

Finding Slow Pages with a Single SQL Query

Theo Marsh
1 min read
887
Cover photo for “Finding Slow Pages with a Single SQL Query”

Averages hide slow pages. Percentiles find them, and one query over the request log is enough to start.

We try to write for one specific reader. When a paragraph confuses that imaginary person, it usually confuses everyone else too.

slow-pages.sql
SELECT path,
       COUNT(*) AS hits,
       PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY duration_ms) AS p95_ms
FROM request_log
WHERE logged_at > NOW() - INTERVAL '7 days'
GROUP BY path
HAVING COUNT(*) > 100
ORDER BY p95_ms DESC
LIMIT 20;

Small improvements compound. A page that loads a little faster, a heading that reads a little clearer, and a form with one fewer field all add up.

Every studio accumulates habits it never chose. Once a year we list them and ask whether each one still earns its place.

Reading work aloud is the cheapest editing tool there is. Your ear catches rhythm problems that your eye skips over, especially in long sentences.

2
Continue reading

Related posts

All posts
Conversation

Comments · 2

Posting as guest · Sign in
  1. Priya Raman ·

    I tried this on a client project last month and it saved us at least two review rounds.

  2. Nils Berg ·

    The quote at the end made my day. Sharing this with the whole team.