Lessons learned about speeding up WordPress and an apache webserver in general

Nov 8th, 2011 | By | Category: Internet, Linux / Freebsd, Technology

Alright so I’ve been struggling with this for quite some time.  I run 60-70 wordpress blogs that make up a large network of travel websites providing information on news, restaurants, hotels, events and job postings for every major city in north america.  Chances are if you’ve searched one of those things for a particular city you’ve hit one of my sites(or at least that’s the idea).  Now the problem is that there are a LOT of hotels, restaurants, news articles and job postings in north america, 100’s of thousands of them.  This means that my blogs have 100’s of thousands of posts on them and this number grows every day as they are updated to reflect new jobs, news and everything else going on in your city.

The big problem arises now because I have 60 blogs all with 10’s of thousands of posts being accessed by 100’s and 1000’s of people every day, clearly this isn’t somethign wordpress was built for but I have a flavoured history of bending software to my will.  My CPU usage was constantly at 100% and it’s only recently that I’ve gotten around to fixing this, or so the germans would have me believe 🙂  Here’s what you need to do

  1. Make sure eAccelerator is installed on your server
  2. Tweak your apache settings.. Right now this is what I have my httpd.conf set to:
  3. MaxKeepAliveRequests 20
    KeepAliveTimeout 2
    Timeout 45
    MaxClients 20
    MinSpareServers 2
    MaxSpareServers 7
    StartServers  4
  4. Make sure that you have wp-super-cache installed.. I researched the crap out of caching plugins and this one consistently came out on top
    • Now here’s the kicker..  I had a script that installs and sets up new websites for me and much to my chagrin after 6 months I just noticed that none of my blogs were caching properly.. the reason was because wordpress didn’t have write access to wp-content/cache/supercache.  Make SURE the wp-content/cache directory and ALL subdirs are writable by apache
  5. Increase your expiry time substantially.  The default is 3600 seconds(1/2 hour) but why do I want all of my sites rebuilding their cached pages every 30 minutes when I only update the sites every 4 hours?  So change the expiry time to something more in line with the frequency of your updates so you’re server isn’t constantly rebuilding pages all the time
  6. Preload, preload preload: This one was huge for me because of the number of posts I have.  Go into the preload section and turn on preload mode.  After you’ve updated the settings click on preload cache now.  This will systematically go through and precache your entire website..  The beauty about preload mode is that the precached posts done here never expire or are ever recached.  The preloading processes is fairly slow so you can do a few sites at a time without worrying that it’s going to melt your server into the ground
  7. WP-Minify: This wonderful little plugin takes your CSS and JS files and compresses the hell out of them, as much as it can without breaking them so that instead of your people having to load 10 50k CSS files it crunches it down to 1 50k  CSS file or something ridiculous like that.  Definitely some tweaking to look at with that
  8. Remove all unnecessary plugins: The less that loads the less your load. Figure out what you absolutely don’t need and scrap it
  9. Disable all Apache logging:  In total I have a few hundred websites on the server and recently I’ve turned off all domain specific apache logging.  If I need to trouble shoot a domain I’ll just re-enable it and the repeat the problem to see what’s going on but disabling this has also reduced my cpu consumption by leaps and bounds.
  10. Nginx: Whatever you do don’t have all of your traffic flowing solely through apache, get something like nginx on there.
I’ve never seen high CPU usage from mysql with any of my blogs so I’ve given up trying to optimize that..I’ve gone through the process of trying to optimize mysql but never noticed a difference so I just leave that as stock.  Hopefully that helps you out, my server isn’t the flashiest or the beefiest of girls but she’s a well oiled and highly tuned machine.  With these tweaks I should be able to get a few more years out of the ole girl yet 🙂
Tags: , , , , , ,

Leave a Comment