Subscribe via

Make Your WordPress 10X faster During Traffic Storms

This tutorial will augment the technique of automatically enabling WP-Cache during heavy load with the ability to switch to a low-bandwidth WordPress theme at the same time.

Few reasons to do this

1. WP-Cache messes with your site statistics, so you do not want to leave it on when your site is not being hammered.
2. You don’t want to use a bandwidth efficient theme all the time because it’s not pretty-lookin’.
3. During traffic storms (e.g. Digg Effect), every 1/100 second optimization tweak counts.
4. If you host your site on a shared host, you will most likely have a bandwidth quota. Switching to a leaner theme conserves your bandwidth (duh!)
5. If you host your site on a home connection, your upload is not up to par with most hosting services, so you need to use that small pipe efficiently.
6. Each “IMG” tag, even if it’s a 1×1 pixel gif, requires an HTTP request to your web server. If you have 10 images on your page, and 10 users are loading your page, that’s 100 simultaneous calls to your server already. Leaner themes usually means less/no images, giving Apache some break.
7. If you’re server is non-uber, you don’t deserve to administer it.

How to do this

I’m building on top of my post about Automatically Enabling WP-Cache during heavy load, so you should go read that first if you haven’t done so already.

  1. I prepared a “lite” theme, but copying my current theme to a separate folder and named it omninoggin_lite. In the lite theme, I removed all the images and all the visual plugins (including the sidebar).
  2. I need a way to easily switch my WordPress theme between my normal and lean themes. I know the easiest way to switch themes is to go to wp-admin > presentation > themes, but here is a way to do it from a script (remember to substitute “YOUR-WP-ADMIN-PASSWORD” with your own password).
    export PATH=$PATH:/usr/local/bin:/usr/bin
    curl -b cookies.txt -c cookies.txt -d "log=admin&pwd=YOUR-WP-ADMIN-PASSWORD" > /dev/null
    curl -b cookies.txt -c cookies.txt -d "log=admin&pwd=YOUR-WP-ADMIN-PASSWORD" > themes.php
    LITE_URL=`grep -o ""themes.php.*=omninoggin_lite&.*"" themes.php | head -1 | sed s/"//g | sed s/#038;//g`
    FULL_URL=`grep -o ""themes.php.*=omninoggin&.*"" themes.php | head -1 | sed s/"//g | sed s/#038;//g`
    echo $LITE_URL
    echo $FULL_URL
    rm themes.php
    if [ "$1" = "lite" -o "$1" = "full" ] ; then
      [ "$1" = "lite" ] && wget --load-cookies cookies.txt "$LITE_URL" -O /dev/null
      [ "$1" = "full" ] && wget --load-cookies cookies.txt "$FULL_URL" -O /dev/null
      echo usage: wptheme '<lite|full>'
      exit 1
    rm cookies.txt

    Now I can easily switch between themes by executing:

    sh wptheme lite
    sh wptheme full
  3. Building on top of the Auto WP-Cache post, I have to make sure that the ‘autowpcache’ python script will switch my WordPress to my “lite” theme when the server load is too high. To do this, I renamed ‘autowpcache’ to ‘autooptimize’ since it will be enabling both WP-Cache and switching my theme to a leaner theme. I then made the following modifications:
    commands.getoutput("sh /usr/local/www/apache22/data/wp-content/plugins/wp-cache-on-demand/wptheme lite")
    time.sleep(end + 5)
    commands.getoutput("sh /usr/local/www/apache22/data/wp-content/plugins/wp-cache-on-demand/wpcache on")
    print "Load time for Apache status page went overboard"
    # ...
    commands.getoutput("sh /usr/local/www/apache22/data/wp-content/plugins/wp-cache-on-demand/wptheme full")
    commands.getoutput("sh /usr/local/www/apache22/data/wp-content/plugins/wp-cache-on-demand/wpcache off")
    commands.getoutput("logger -p user.notice WP-Cache has been turned off")
  4. Enjoy being L33T.


I clocked my page generation time and page load time. Keep in mind that page generation time is how long it takes the server to generate the HTML file from PHP code. Page load time is the period of time between the client request and client response (end of HTML file received). For things like WP-Cache, there is only one page generation time as no PHP code is being executed on subsequent runs. So without further adieu:

Unoptimized Normal:
0.330 gen time
0.645 load time

Lean Theme:
0.155 gen time
0.249 load time

WP-Cache Enabled:
0.375 gen time (first only)
0.088 load time

Lean Theme & WP-Cache:
0.231 gen time (first only)
0.068 load time

Notice that if both Lean Theme and WP-Cache is enabled, then there is a whopping 10x speedup from the normal unoptimized load time! Also keep in mind that since all the images are stripped, HTTP requests are reduced and bandwidth is conserved. This ultimately lets your server handle 10+x more visitors than what you would be able to handle with your normal settings. Phew, that was tiring. Enjoy!

5 Responses to “Make Your WordPress 10X faster During Traffic Storms”

[go to last comment]
  1. Ty Bone

    *Update* I’m thinking about turning this along with automatically turning on WP-Cache/WP-Super-Cache on demand into a WordPress plugin. I’m still trying to figure out how to implement it, but I’m pretty sure the plugin is going to ROCK!

  2. Sid Savara – Personal Development

    Any updates on this one? This is a pretty cool idea. I think wrapping it up in a plugin with a “default lite” theme would probably be sufficient – and maybe at the top a little message telling users hey, this is a optimized theme, heavy load! Come back to see the regular site =)

  3. Ty Bone

    I haven’t updated this project yet (so many projects going on!). I’ve written this before or at the beginning of my WordPress plugins development. I was waiting for the right time (when I learn more about WP Plugins) to wrap this up into a nice little plugin for the masses. I guess the time has come. Nice that you reminded me!

  4. Make Popularity Contest Work with WP-Super-Cache | OMNINOGGIN

    […] I wrote “Make Your WordPress 10X faster During Traffic Storms“, which is a post about automatically turning WP-[Super]-Cache on/off and automatically […]

  5. Ty Bone

    *Update* I have cleaned up this article by wrapping authentication into a script (step 2). Please let me know if you like it!

[go to first comment]

Leave a Reply