MySQL – Slow query – wp_options table. Website unable to handle traffic

amazon ec2amazon-rdsdatabaseMySQL

After spending several days researching, I have placed a website on a c1.medium instance, Amazon Linux, and the MySQL database on a db.m1.instance. The RDS is running MySQL version 5.6.13. I have allocated 100 GB for the DB instance and have set the provided IOPS at 1,000. The website is photo based, permits user uploads and at peak hours has 400+ visitors.

Once I enabled the slow query logging I found the issue appears to be with the wp_options table, which when looking into phpmyadmin I found contains information on the WordPress plug-ins and theme. Ex:

SET timestamp=1390186963;

SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';

Time: 140120 3:04:17

User@Host: xxxx Id: 744

Query_time: 49.248039 Lock_time: 0.000180 Rows_sent: 485 Rows_examined: 538

After experimenting with a few of the DB parameters I set the query_cache_type to 1 and the query_cache_size to 64MB. I was hoping that enabling the caching would stop the database from repeatedly calling the wp_options table, but that unfortunately doesn’t appear to be the case. Any suggestions? What would be the next steps to take to figure out the cause of this issue? When looking at the CloudWatch metrics the hardware appears to be sufficient, but maybe not?

Below are screenshots of the CloudWatch metrics for both instances.

EC2

RDS

Best Answer

Query_time: 49.248039 Lock_time: 0.000180 Rows_sent: 485 Rows_examined: 538

This, from your slow query log, implies that it took 49 seconds to execute this query. Try running

CREATE INDEX wp_options_autoload ON wp_options (autoload);

And then try loading your pages again.

Though with only 538 rows in the table, that's an extremely long time for that query to run.

Related Topic