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!
I do not claim to be an expert on this subject. If you have more insight or suggestions please post a comment here.
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.
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.
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:
Now, when you post to Digg or another high traffic website you can include these mirror URLs as the one of the first comments.
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.
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.