Oct
18
(2005)
One of the things I really love about WordPress is its always-fresh style of pulling pages directly from the database rather than generating hundreds or thousands of static pages. It makes publishing much quicker - you’re just adding a new row to the posts table - since there is no “Publishing Pages” stage, as in MovableType etc…
However, that is also the Achilles heal of WordPress - works fine as long as the load is miniscule, but if you get Slashdotted, or have a bunch of simultaneous views, the database can bog down pretty dramatically. Usually, that’s not a problem, but the threat is there.
There is a simple solution, however. The WP-Cache 2.0 plugin - it watches pages as they’re being requested, and caches the output to a static file on the fly. If a page has already been cached, it just returns that, rather than crunching through the database each time. Makes request handling much faster. Cached pages automatically timeout after 1 hour, and I think cached pages may automatically invalidate if the database is modified. Very slick. Cached pages have only a trivial amount of overhead over traditional static pages, so load handling should scale up much more smoothly than with strictly dynamic pages.
As an example - the main page for this blog takes 87 database queries to generate. I’m sure it would be possible to optimize that, but with the plugins that I like to use, it takes a fair number of queries to generate a full page. A cached version of the same page takes 0 queries, freeing up the database and CPU to more readily handle the fewer uncached dynamic pages that are requested. Already, I’ve noticed the generation time of the main page has dropped significantly, I’m assuming because of lower overall load. Previously, it could have taken close to 3 seconds to generate the page (slow, but tolerable). Now, it’s hovering around 500ms for a dynamic generation, and even that is skipped if it’s cached.
I’ve been running it here for a couple of days to see if there were any wrinkles of hiccoughs, and I haven’t been able to find any. If you look at the source for any page on this blog, scroll waaaay down to the bottom to see if the page was cached or not. That’s the only way to tell. Well, that, and it should be coming at you faster than before.
Comments
4 Responses to “WordPress and Caching”
Leave a Reply


Thanks, Dr. D! I’m giving the plugin a go over at CogDogBlog. Curious to see how the performance changes for my image heavy pages. Is theres a cache “penalty” for the first request? Hard to tell.
The first request is just a regular dynamic one, that happens to squirt the data into a text file on the way out the door. After that, it’s just a quick lookup to see if it’s cached (and valid), and just returns the file directly.
Thats pretty slick, I’ll give that a go when I move my blog over from b2evolution.
Daily Update — October 19, 2005
Today’s Daily Update focuses on "expansion" ranging from earnings reports and rising tuition costs to Google and Wikipedia. We also mention the growing Hurricane Wilma and the expanding repertoire of opinions of Supreme Court nominee Harriet…