PHP Development

Debugging slow WordPress Theme demos with NewRelic

A few of our WordPress theme demos started to run slowly. Time to fire up newrelic to find out the problem.

It quickly stood out that WordPress SQL queries are chewing up most of the time:

newrelic-slow-database-transactions

What did I find in these demo database tables? 18000 WooCommerce “wc_session” entries.

heaps-of-wc_session-entries

All of these wc_session entries had “autoload” set to “no”. When WordPress starts it does a SQL query a bit like this:

SELECT * FROM wp_demo_options WHERE autoload = "yes"

But – there is no MySQL index on “autoload”! (Google for reasons).

no-autoload-index

So this SQL query was very expensive, since 99.99% of the option entries (wc_session) in this database table have autoload = “no”.

The quick fix for my live demos was to delete all %wc_session% entries and add an autoload index so it doesn’t slow down again in the future.

 

Leave a Reply

Your email address will not be published. Required fields are marked *