Is Your Blog a CPU Hog?

Poor Tricia; her host told her her blogs are using too many server resources. The problem is what with running a lot of popular blogs and installing load of plugins, her blog just chows down CPU!

Tricia sent out an ABP about this at the PPP forums, so I went and visited Tricia’s Musings. After loading the page, I used the “view source” button on my browser, scrolled to the bottom and found the last few lines in the html. I read this:

</body>
</html></center>
<!-- Dynamic Page Served (once) in 3.866 seconds -->

3.886 seconds? That’s a lot. I just checked BigBucksBlogger; it took 0.73 seconds to serve the page without Cacheing. It took 1.07s with Caching. (More on caching later.)

Tricia is using WP-Cache, but almost 4 seconds is a major amount of time to serve one page. (Mind you, this number isn’t exactly the cpu. But it is proportional to cpu, so big numbers are bad.)

Anyway, Tricia is using lots of resources; it’s probably due to one very badly written plugin. Which? I have no idea.

Now I bet, you are asking me exactly what Tricia and Anabella asked: How can you tell how much time a page uses? And how can you tell if a plugin is a hog?

How to Tell How Much Time it Takes to Serve a Page

On WordPress blogs, you can print out the amount of time it takes to serve a full page by adding this to your after your footer is loaded.

<?php printf(__(‘%s seconds’), timer_stop(0, 2)); ?>

Where ever you place this bit of code, it will print the time lapsed since you first requested the page. By putting it in the footer, you can see the full time required.

Many templates include this command, but wrap it in comment tags. That hides it from visitors, who generally don’t care. But since I know most Templates show this, I knew that if I read Tricia’s source I would be likely to find the time required to serve the page.

Some templates don’t include the command; mine didn’t. But you can add the code easily. Just go to “presentation” open up the main index template and slap that php in! (Do the same for single posts if you want the time to appear in those too.)

I added it to my template and if you scroll down, you’ll see the time appears.

Note: don’t expect the time to to say 0.7 seconds. If you load my page several times, and I’m not caching, you’ll see the number varies a bit- in fact quite a bit. But you aren’t going to see 4 seconds as I saw at Tricia’s site! If I’m caching, you’ll probably see the same time listed every time you reload the page and you’ll see more than 0.7 seconds. That’s because when I cache, the page takes about 0.7 pages to “create” and a little more to cache it. But once it’s cached, it takes zero cpu to for the next hour. That’s because instead of creating a page, the cached page is served for that hour; that takes zero CPU. For heavily visited blogs, caching saves CPU.

How can I tell if a plugin is a CPU hog?

You can add the code to your footer, deactivate the plugin and turn the cache off. Reload your page two or three times and see how much time it takes to load. Now activate the plugin, reload two or three times. See how much time it takes with the plugin activated.

If the page load using the plugin is much larger than without, that plugin is a hog. Turn it off. Find something else!

Couldn’t you give me something easier and more efficient to use?

Yes. This could all be made easier if I wrote you a plugin that did this:

  • Recorded the time it took to generate the header.
  • Recorded the time it took to exit from “the_loop”. (That’s WordPress lingo for finishing delivering all the posts. Most templates deliver the sidebar after that.
  • Recorded the time it took to finish creating the footer
  • Displayed all that in a visible table at the end of the footer.

With this data, not only would you know how much time it took to run each plugin, but you’d also have data that would help you figure out if the cpu hogging plugin is something you use when loading content, creating the sidebar or generating the footer. This really helps because many, many of the CPU hogs are inefficiently written comments plugins. A few operate elsewhere. It’s easier to figure out which is which if you know where the cpu gluttony is taking place.

My Question to You

It would take me time to do this. How many people out there have problems with CPU resources? ‘Cuz if it’s a lot of you, I’ll be happy to write it (especially if after you use it, you blog about my mad plugin-writin’ skillz!)

So, how many of you want this? Only one? The it would be better if you just looked at the footer? Millions and zillions? I’ll write it tomorrow! Let me know.

8 Responses to “Is Your Blog a CPU Hog?”

  1. cmanlong says:

    I noticed you stopped by my blog. I just wanted to say thanks for the visit and I’m glad you enjoyed the article.

    later all and have a profitable productive bloggging day

  2. cmanlong says:

    oops too many g’s :)

    i’ll have to google bloggging now and see where I rank ;)

  3. Marisa says:

    I’ve had some problems recently with CPU hogs. I’d love this plugin. :0

  4. Tricia says:

    Good info here I’ll have to try this on all my sites.

    Now you are talking like we know that it’s Tricia’s Musings that is the source of all my hosting woes. That isn’t so. I have 10 domains on my hosting account. One runs a blog and a HUGE html based website, the other runs a CMS Joomla website, 6 are blogs that I’ve barely worked on, one has one blog, and the biggie- Feverishthoughts.com has a grand total of 7 blogs running on it - two of which are very busy blogs.

    I think the source of my CPU resource usage problems is more than likely one or all of the blogs on Feverishthoughts but another big suspect is the CMS website that I’m running.

    If it’s as simple as a bad plugin that’s put me in hosting hell I’d love to know, but my web host won’t even pinpoint which of my domains is the problem. It’s ridiculous.

  5. Tricia says:

    BTW the 6 new domains are for 5 current blogs on Feverishthoughts and one single new blog. so no … don’t get the idea I’m going blog nuts. The directory blogs need real homes is all.

  6. Tricia says:

    One more time … my web host put my account on non-production servers and everything loads much slowly since they did that because obviously the server is slow too.

    Could that affect the page load time you are seeing? I think so. I’ve found everything takes twice as long since they moved my sites.

  7. Aks says:

    Nice trick!! I had come to know about that when i was experimenting with WP and some plugins…

  8. Matthias Köbrich says:

    thanks for this tip. i´ll check this out on my blog although i don´t know how to fix it…

Leave a Reply