Identify slow queries
Slow queries are SQL database queries made by application code that take an unusually long time to execute. An increase in slow queries will reduce the efficiency and resiliency of an application’s database. A site with frequent slow queries might appear to operate well under normal amounts of traffic, but can perform poorly if the amount of traffic increases even by small amounts.
Slow queries should be investigated and optimized wherever possible. Several resources are available for identifying slow database queries when they occur and identifying their source.
- The Insights & Metrics panel of the VIP Dashboard: The rate of change in the number of inefficient database queries made by an application can be reviewed in the “Slow Queries” section of the tab labeled “Database”. An unusually large volume of SQL queries made by an application that take an unusually long time to execute are indicated by a “Slow Query Rate” Anomaly Event Type in that section. The timestamp of an Anomaly Event Type can be correlated with the timestamp of a slow query listed in the Slow Query Logs panel (if it occurred recently enough to be one of the 100 of the most recent logged queries).
- Slow Query Logs in the VIP Dashboard or retrieved with VIP-CLI: A reference for up to 100 of the most recent queries made by an application that take an unusually long time to execute. Each slow query log provides a timestamp, the SQL statement that triggered the slow query, the request URL on which the slow query occurred, and more. Stack traces for the provided request URL can be reviewed by viewing the URL in a browser window with Query Monitor enabled.
- Runtime Logs in the VIP Dashboard or retrieved with VIP-CLI: Database queries that run for longer than 60 seconds are automatically terminated. This is a default platform setting that is subject to change, and is not customizable per application. A terminated query will appear in a Runtime Logs entry with the PHP message
MySQL server has gone away
. - New Relic: For environment’s that have New Relic enabled, slow queries can be identified and diagnosed in the New Relic dashboard.
Last updated: October 31, 2024