How I Survived a 2300% Traffic Increase With Drupal

Yesterday, my Orphaned Works article hit the front page of Reddit, a popular social news site. Traffic instantly increased by a factor of more than 20. At peak, the site was serving over 30 requests a second, enough to take down most poorly configured Drupal sites. In this article, I'll show you how I survived, and what steps you can take to make sure your site is ready for the Reddit Effect.

Traffic graph

These first 2 tips will give you the quickest bang-for-your-buck, and based on my research, more than half of new Drupal sites fail to take advantage of them!

1. Lower Your File Count with CSS Aggregation

Drupal has a tendency for CSS file overload. If you're running 40 modules, chances are, 20 of them have their own CSS file. That means every visitor to your site has to download 20 additional files before your page will even display.

This is a huge bottleneck that can add tens of seconds to your page load time, and kill your server, in the event of a traffic spike.

Luckily, there's a simple solution: CSS Aggregation. Starting in version 5, Drupal has the ability to merge all your CSS files into a single download. Instead of dozens of file requests, your visitors now get everything in one quick burst.

To enable CSS aggregation in Drupal, just go to Site Configuration > Performance.

Enable CSS Aggregation

Drupal 6 also offers JavaScript Optimization, which does the same thing for JS files. Drupal 5 users can add this functionality with the JavaScript Aggregator module.

2. Speed Up Drupal with Page Caching

Page Caching is the other important setting found on the Performance page.

Enable page caching

Enabling page caching will speed up Drupal significantly for anonymous users by dramatically reducing the number of database queries required to render the page.

Most sites will want to use the "normal" setting here, it provides the best mix of performance and stability.

3. Disable Bandwidth-Intensive Blocks

If you're running a random image block in your sidebar, or any other bandwidth-heavy, disk-churning widget, it's a good idea to disable it temporarily. Remember, every new image is another file your user has to download.

Pages per visit

Since most social-media visitors never browse deeper than the page they land on, you can usually get away with leaving the blocks enabled on the rest of your site.

To disable a block on only specific pages, go to Site Building > Blocks and click Configure on the block you're concerned with.

Disable blocks

Remember to enter only the Drupal alias, and not the whole URL.

4. Improve Page Load Times By Optimizing Your Images

If your theme or article uses PNG images, be sure to run them through a PNG optimizer. The best and most effective PNG optimizer to date is PNGOUT, a free command-line utility.

PNGOUT generates file sizes 5-10% smaller than other PNG optimizers, including OptiPNG, PNGCrush, and AdvPNG.

If you don't like using the command line, check out PNG Gauntlet, a free front-end for PNGOUT.

I also used Photoshop to increase the JPEG compression on my header image, reducing file size by 30KB. Image quality took a small hit, but overall, I doubt most people noticed.

These small optimizations can add up to hundreds of megabytes saved when you consider how many times the files will be downloaded.

5. Get a reliable web host

Ultimately, your ability to survive landing on the front page of Digg, Reddit, or Slashdot depends on your hosting company.

Believe it or not, this site survived the Reddit Effect on a $7/month shared hosting account from AN Hosting. They've been excellent when it comes to keeping the site online, both with the recent Reddit traffic spike, and when I was featured on LinuxToday.com a little while back.

Not all hosts are so generous. The last thing you want is a cheap host pulling the plug on your big day, so make sure you're hosting with someone you can trust.

For more tips on improving your site's performance, be sure to read How Database Configuration Can Slow Down Drupal.

post to del.icio.usSubscribe

Posted by John on 2008-07-07