Is Your WordPress Site Slow? Problem May Lie With MySQL, Here is How to Fix it
By on February 20th, 2012

When I initially started out with using VPS, I had tons of problems with Apache but quickly switched to Nginx which has proven to be more than a boon, because it meant that I could do more with less. However, having used WordPress I have come to know that the system is not necessarily scalable in itself when it comes to self-hosted websites.

In the past, I have written about the architecture that powers Techie Buzz and several guides like Scaling WordPress Using MySQL Replication and HyperDB and setting up memcache with WordPress among others.

However, over time, I have learned quite a few things about managing WordPress for a website with heavy traffic and also sorted out several issues which had become a bottleneck for us.

One of the biggest issues I have faced over time with WordPress is the database. More often than not WordPress websites work slower than expected because of the MySQL database and heavy load on it. However, many a times a simple change in MySQL could speed up the website considerably.

The default engine (not forced by WordPress) while installing WordPress is MyISAM for most hosting companies. The problem with MyISAM is that it locks the entire table when it inserts or updates rows. This in turn locks other queries which are accessing the same table slowing down the entire website in the process.

For example, when you are updating a post, you will be updating the wp_posts table and during this update all other select, insert, update and delete queries will be queued till the insert/update query completes. This in itself should not be a big problem when you have a site with less traffic. However, it does make a big impact when you have a large website with multiple queries being run every minute or so.

So what is the solution for this? Well, the best I could implement was switching the tables with the frequent queries to InnoDB. InnoDB is a storage engine in MySQL which might become the default one in future MySQL versions. With an InnoDB table the queries don’t lock the entire table, but just lock a single row it is inserting/updating. This leaves the other queries to complete without having to wait in a queue.

Making this small change has definitely made life easier for us. Along with our other caching mechanisms we now have almost 0 load on our database, which is definitely a great thing.

While this has definitely been helpful for us, I would suggest that you spend some time reading up the differences between MyISAM and InnoDB and their advantages and disadvantages before you make the move. Once you are convinced that you are ready to migrate, head over to my earlier guide on how to safely and easily migrate tables from MyISAM to InnoDB Engine.

Tags: , , ,
Author: Keith Dsouza Google Profile for Keith Dsouza
I am the editor-in-chief and owner of Techie Buzz. I love coding and have contributed to several open source projects in the past. You can know more about me and my projects by visiting my Personal Website. I am also a social networking enthusiast and can be found active on twitter, you can follow Keith on twitter @keithdsouza. You can click on my name to visit my Google+ profile.

Keith Dsouza has written and can be contacted at keith@techie-buzz.com.
  • http://www.technobuzz.net/ Rajesh

    These are some of the best and useful tips. THanks :)

  • Vikash

    Well, Does it matter if you are on a Pro shared hosting?

 
Copyright 2006-2012 Techie Buzz. All Rights Reserved. Our content may not be reproduced on other websites. Content Delivery by MaxCDN