February 26, 2011
Being the most popular CMS in the world, and a superb back end system, WordPress still has a lot to be ashamed of behind the scenes: messy code, inconsistent naming schemes, an obscure library system and awful database schemas.
A lot of this contributes to very poorly performing code – and not in the way that many of the “well designed” CMSs perform poorly (because they’ve been over-thought), but because scalability and caching has not been built in at all levels.
This article will take you through the steps of optimising an existing WordPress install to purr again, either after many years of service which have bought it to it’s knees, or a massive jump in content that’s exposed parts of your template that really slow things down.
1. Keep WordPress Up to Date
On the whole, whist adding features, the WordPress team is also is working on optimisations which you can take advantage of by moving to the latest version available. Typically we use the Subversion repositories so that it’s only a single command to bring everything in line with the latest release. You’ll also benefit from having a greater number of plugins available that can help optimise your CMS – your plugins can also be kept up to date via Subversion or the back-end system. See more on this in my post on WordPress and Subersion.
2. Use Caching Plugins
This isn’t the place to go into detail on all the WordPress caching plugins available – but many of them will get the performance you need. At Acumen we typically use W3 Total Cache due to the advanced caching options and cache database engines (it supports Disk, Memcache, APC, etc)
3. Use PHP Optimisers
Again, there are many explorations of speeding up PHP on the web. At Acumen we use APC due to its simplicity to install on Linux.
4. Tune your template
First, turn off any and all caching plugins, and use Firebug or Google Page Speed to inspect page load time. This is important because it reflects the loading time of content that may at any point become uncached (after it’s been edited, after a cache expiry, etc). If you’re finding that some of your pages are loading slowly, you’ll need to look at the exact code you’re using and see if a simpler alternative can be written. In extreme cases you might need to write your own SQL to work around WordPress’s lack of recursivity options in the available system queries, or even add your own caching to your template’s queries.
Note that browser-based analysers aren’t the only approach to analysing the performance of your template. If your server is struggling to serve your user’s requests, it’s likely the nominal load will be greater than 0 (we’re talking UNIX here, obviously). In this case, you can set a target to bring your server back into a 15-minute average of no more that 0.3.
If you’re really struggling to identify where code issues are coming from, you can consider the MySQL –log option, which will write a list of all queries it’s supporting.
5. Clean Stale WordPress Files
One great new feature of WordPress 2.6+ was that it keeps a revision of every page. You may want to remove existing revisions by deleting all `posts` with `post_type`=’revision’, and setting a template variable like the below:
That’s it for now- if you’ve any other suggestions for speeding up WordPress, leave them below and we’ll work them into this article!