Improving performance by 87% at b5media using a cache, optimization, and a screwdriver

Posted by Gary King on April 17, 2007
Categories: business, programming

Running a blog network with nearly 200 blogs is no easy task, and when you’ve got the same item being downloaded a few thousand times every second, it can put quite the strain on a server. That’s why the b5media blogroll (an example is shown to the right of this post) can pretty much kill a server if people love our blogs too much, and if the blogroll isn’t as optimized as it could have been. We needed to fix the blogroll so that we could use it without straining our servers nearly as much as it once did, so I jumped in and optimized it so that it would be nice and speedy.

The good thing was that whenever the blogroll was requested by a website, the same data would always be sent (in XML format - what else?). The reason that the blogroll may look different on several websites is because each website parses the XML file differently. This enabled us to cache the blogroll XML data that is returned, since it is not dynamic; it only changes if we add/modify/remove a channel or a blog.

Average load times

Before optimization

Before optimizing the blogroll, these were the average load times that it took to load the blogroll with the old code, when it ran 2500 times:

  • 5.9277107715607 seconds
  • 5.2258749008179 seconds
  • 6.9043378829956 seconds
  • 8.450049161911 seconds
  • 6.729789018631 seconds
  • 6.3227508068085 seconds
  • 5.4357509613037 seconds
  • 7.2524189949036 seconds
  • 7.7171530723572 seconds
  • 6.8039338588715 seconds

After optimization

After optimizing the blogroll, here are the average load times that it takes to load the blogroll with the new, optimized code, when it ran 2500 times:

  • 1.349152803421 seconds
  • 1.3284649848938 seconds
  • 1.1611139774323 seconds
  • 1.3144729137421 seconds
  • 1.2075929641724 seconds
  • 1.1899409294128 seconds
  • 1.3266270160675 seconds
  • 1.297404050827 seconds
  • 1.2125298976898 seconds
  • 1.1947700977325 seconds

Numbers speak louder than words (but actions come as a close second). Keep in mind that the times shown above represent the times that it takes for the blogroll to execute 2500 times (meaning, it takes roughly 1 second to load the blogroll 2500 times. That’s a lot of b5media-blogroll-lovin’!)

This is just yet another testament that caching and optimization can really do you some good, even if it may be a minor change that you’ve made to your code. I used to just write code without any considerations regarding caching and optimization of the code (this was quite a while ago). Eventually, I learned that by simply spending a few minutes to cache data, it can save all of your website’s visitors some time, and little by little, that time adds up.

Resources

Here are some great resources that you can use to cache some of your own data:

  • for caching PHP in general, use Turck MMCache
  • for caching on WordPress, download and install the WP-Cache plugin

Tutorials

(Oh, and there was no screwdriver involved. Doh!)

Popularity: 15% [?]

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Aaron Brazell Tuesday, April 17 2007 at 5:14 pm EDT #

    You did a smash up job, Gary. This was really great for us!

  2. Gary King Tuesday, April 17 2007 at 5:14 pm EDT #

    This is a comment

  3. Gary King Tuesday, April 17 2007 at 5:15 pm EDT #

    Aaron, you said that you got a 404 when commenting. Lies! Bah.

  4. David Wednesday, April 18 2007 at 12:45 am EDT #

    Cache where, on my computer? So the fact that I clear the Firefox data everytime makes this useless right? Ah, you know, it’s too bad b5media doesn’t have a low-quality randomness category for my blog.

  5. Gary King Wednesday, April 18 2007 at 12:54 am EDT #

    David,

    The blogroll’s cache is on our servers. So, the fact that you clear your Firefox data every time does NOT make this useless ;)

    Also, if we end up having several, low-quality randomness blogs, then we’ll consider creating that category. News categories are always an option! :)

  6. David Wednesday, April 18 2007 at 1:19 pm EDT #

    If the data is still be sent from your servers over to my computer, how does it make it load faster then? Or was it that the blog roll was being sent from elsewhere to your server, then to my computer?

  7. Gary King Wednesday, April 18 2007 at 1:49 pm EDT #

    David,

    The blogroll gets faster to your computer because then the website that you’re visiting spends less time loading the blogroll, since the blogroll itself has calculations required that will load the channels and blogs that it lists.

Comments



Close
E-mail It