logo
podcast Podcast
get help Get Unstuck

How do you know if something is slow in production?

The tools we used for finding slow code in development are not suitable for production. So how can we find slow code there?

Joel Clermont
Joel Clermont
2023-08-23

Since it's not recommended to run Telescope in production, how can you identify slow requests there?

The first thing I'd set up is a slow query log. That link is to the MySQL docs, but there's a similar concept in PostgreSQL as well. With this option enabled, you can set a threshold where any query that takes longer will be logged. I'd recommend starting with 3 seconds and ratcheting it down 250ms at a time from there. You can then periodically review the logs to identify queries that might be missing an index, or in need of some other optimizations. These logs will show the date/time, SQL statement, and how long it ran, but it won't have any context of your Laravel application.

To get more rich context of the entire request that led to the slow query, I recommend Sentry. In addition to exception tracking, it also has a Performance module which exposes slow requests (whether database related or not) and even surfaces N+1 issues that slip through to production. It's not free, but I find it well worth the cost.

I'd love to hear if you have any other things you do to watch performance in your production environment.

Here to help,

Joel

P.S. Ever wonder if your Laravel app could be more secure? Download our free book for 7 steps to review.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.