Optimizing WordPress for High Volume Traffic

Last week my keyboard prank post was promoted to the front page of Digg and within minutes my WordPress blog was down for the count. Being slightly embarrassed I tried get my site back online and along the way found several things you can do to prevent this from happening to you!

NOTE:

I do not claim to be an expert on this subject. If you have more insight or suggestions please post a comment here.

MySql

Most times it’s the MySql database that’s the problem. All your blog entries are stored, managed and retrieved from a MySql database, and, by default MySql doesn’t allow more than 100 connections at a given time. So if you’re getting pounded by the entire world, most of your viewers will see an error page

Luckily there is an easy solution (if you manage your own server): just increase the number of connections MySql supports. Open your MySql configuration file, in my case it was at /etc/my.cnf, and set ‘max_connections’ to any number you want; I set it to 250. Now don’t forget to restart MySql after this change.

WP-Cache

MySql is only part of the issue — why abuse your database server if you don’t have to? WP-Cache is a WordPress plugin that caches your posts to static HTML files to save your database and server cycles.

This saves your MySql server by keeping the number of connections to a minimum. Also since WordPress is written in PHP, which is an interpreted language that must be parsed each time a page is requested, caching the pages as HTML saves your web server cycles and speeds up the load time for your viewers.
By default the cache is used for an hour until it’s expired and refreshed with new content. Since I wanted to view the recent comments quicker than that I changed the expiration time to 4 minutes (or 240 seconds). To change this click Options > WP-Cache and change the expire time value and then click ‘Change Expiration’. Be sure to read the WP-Cache instructions on how to install and configure it.

Mirroring

These steps are all fine and good, but what if your server can’t handle the traffic or you don’t have the administrative rights to make the necessary optimizations? At this point you’ll want to mirror blog post before it gets submitted to Digg or Slashdot. The reason I stress this is if you wait until your site is down, it’s too late.

Mirroring your content only takes a single click with the Coral Content Distribution Network. Coral works like a P2P network and as soon as your link is submitted on their website, it’s mirrored around the world across 260+ servers. To start, go to their website and enter your URL in the form (under Using Coral) and click ‘Go’. This will open a new window and show you your mirrored page (this may take a minute).

It’s important to note that Coral does have a bandwidth limit on the URLs it mirrors, so it might be a good idea to create a couple more mirrors through Coral. You should be able to do this by adding a unique parameter to your URL; I did it this way:

  1. http://mozmonkey.com.nyud.net:8090/2006/april_fools_hack/
  2. http://mozmonkey.com.nyud.net:8090/2006/april_fools_hack/?mirror2
  3. http://mozmonkey.com.nyud.net:8090/2006/april_fools_hack/?mirror3

Now, when you post to Digg or another high traffic website you can include these mirror URLs as the one of the first comments.

Apache

If you’re running your site through Apache you probably wont need to tweak it much — the only thing I did was set MaxClients to the max (256). For more information about Apache optimizations checkout the Apache Performance Notes. This article has some simple changes you can make to help squeeze the most out of Apache.

Advanced Options

If you want to know more advanced optimizations checkout High Performance WordPress. This article goes into great detail about how WordPress works and many more things you can do to optimize it.

Comments

  1. […] Jeremy Gillick (software engineer and cool prankster) says: Last week my keyboard prank post was promoted to the front page of Digg and within minutes my WordPress blog was down for the count. Being slightly embarrassed I tried get my site back online and along the way found several things you can do to prevent this from happening to you! […]

  2. it’s painful to get to know the limitations of your applications and servers. there are some other things you can do to help WordPress move faster. One is to utilize a php accelerator. it’s a little involved for the novice, but really helps. another thing you can do is to make sure mysql is caching. that will help too. good post.

  3. I also use wordpress and this information is very useful. I don’t add my site on any social bookmark yet but maybe in the future.. who knows…

  4. By default the cache is used for an hour until it’s expired and refreshed with new content. I was not aware of this. We are now optimizing our site accordingly. Thanks!

  5. First of all congratulation for such a great site. I learned a lot reading article here today. I will make sure i visit this site once a day so i can learn more.

  6. We have posted answers to your comments in a new post this morning. We are also getting in touch with some of you to get suggestions and further feedback.

  7. By default the cache is used for an hour until it’s expired and refreshed with new content. I was not aware of this. We are now optimizing our site accordingly. Thanks!

  8. So I’ve finally gotten my act together and updated the design of shelktone.com I’m now on WordPress and I believe there are no more broken links. Exciting!

    Let me know what you think of the new design and if you have any suggestions. Thanks!

  9. This is a good subject to talk about. Sometimes I fav stuff like this on Redit. This article probably won’t do well with that crowd. I’ll take a look around your site though and submit something else.