troubleshootIn previous posts, I discussed why webmasters should be concerned about their CPU usage on a shared host and what happens when you go over the amount of CPU usage that a shared host allows. In this post, I want to discuss ways to troubleshoot your WordPress blog or site when it’s using up extreme amounts of CPU resources.

In my experience, WordPress is unfortunately a resource hog. This comes from the fact that it makes quite a few queries to the host server to run each page each and every time a page is loaded. And as you add those cool new plug-ins, you add more and more queries on each page per page reload. And should you want to have a site that earns a good amount of traffic, you’ll be red flagged by your shared host in no time.

That’s not to discourage folks from installing their own WordPress on a shared host. That’s just to say there are things you can do to prevent your site from eating up all those resources. Here’s some I’ve learned through my own experiences:

Install a Cashe Plug-in

This is the first, easiest and most important step to take in cutting down on resources used by a WordPress blog. The current most popular plug-in that handles this is WP Super Cache. Here’s a description of what it does, from the creator’s site:

It generates html files that are served directly by Apache without processing comparatively heavy PHP scripts. By using this plugin you will speed up your WordPress blog significantly.

This plugin is a fork of the excellent WP-Cache 2 by Ricardo Galli Granada. WP-Cache 2 caches the pages of your WordPress blog and delivers them without accessing the database. Unfortunately it still means loading the PHP engine to serve the cached files.

By using this plug-in, your blog will be sending less queries to the server to run pages. It will serve up static pages to visitors and reduce the CPU usage significantly.

Install Bad Behavior

Sometimes a traffic spike isn’t real traffic at all. It’s those dreaded spam bots. Yes, there are plug-ins that come with the basic install of WordPress that deal with spam. But think, each page load that a bot makes is CPU use. Each time they try to post spam to your blog, more CPU use. So why let the spam bots come to your site at all?

You can use the Bad Behavior plug-in to completely block spam bots from reaching your blog at all. Instead, they will receive a static page and a message that turns them away from your blog, saving precious resources for the legitimate users! Very cool!

Check Your Queries

There is, indeed a way to check the number of queries your blog makes to the server upon each page load. Some of the templates come with it built in, usually at the bottom of the page. If your blog doesn’t report this to you and you’re coding inclined, you can add this bit of code to the footer of your blog page:

<?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds.

What it will output will look something like this: 29 queries. 0.226 seconds.

This basically means that my blog page required 29 queries to the server and took 0.226 seconds to load.

Why is important to know this? Because the one blog that I was running that got flagged for going over on CPU usage was loading 166 queries to the server on each page, every page, every hit the site got! WAY TOO MUCH!

Being able to monitor the number of queries my blog made to the server was the ONLY way I could eventually figure out which plug-in I had installed was the culprit. If you see that your site is eating an extreme amount of resources through queries per page load, there is something you can do, which leads me to my next step…

Uninstall Plug-Ins!

That’s right. All of them. Take every single plug-in off your site. Because if you have a cache plug-in installed and you have Bad Behavior keeping away bot activity, but your queries are high, then it’s bloated plug-ins that are killing your resources.

As a rule, though plug-ins are very cool, you should limit the amount of plug-ins and streamline your site to only use the ones you absolutely need. This is hard for me… because I love to experiment with new features on my blogs (I’m the annoying type of blogger that is constantly changing widget placement in my sidebar… I apologize!)

Not every plug-in will query your server on a page load. So your job is to now find out which plug-in causes the jump in resource usage when a user loads your page. You can do this by:

  1. Disable all plug-ins. All. Even the ones that don’t look suspicious. We need to start with a clean slate.
  2. Sort through your plug-ins and choose only the ones that you really really need to run your blog. Uninstall the plug-ins that are nothing but extra. Don’t just disable, actually uninstall them. Do leave a little wiggle room for the plug-ins you want — but be ready to uninstall them should they be the cause of CPU usage bloat.
  3. Now that you have no plug-ins, go to the front page of your blog and load it. Scroll down to the bottom and check the number of queries your blog makes to the server without plug-ins installed. Write this down or keep it in mind. We’re using this as a base number to test each plug-in.
  4. One at a time, enable your plug-ins. After each plug-in, go back to your main site and refresh the page, checking to see if there has been a change in the query number at the bottom. Note: You may need to reapply your Theme from the Appearance menu on your WordPress admin panel for the new plug-ins to take effect. Not sure if everyone has this issue or if it’s just me.
  5. Test all of your plug-ins until one of two things happen – you find which one is eating all your resources or you find a way to balance out the plug-ins that allow for you to use them in relative harmony

Let me stress that you should not rule out any plug-ins. When my blog got flagged for using up CPU resources, the above was the only method I found that helped me discover the plug-in that caused the issue (since I could not directly monitor my CPU usage on that host). When my queries jumped from 32 to 160-something, I knew I had found the issue. And it was not the sort of plug-in that I would have thought could have caused such a thing — really unexpected!

I hope that this post can be a help to someone dealing with the frustrations of a WordPress blog eating up CPU resources. It was such a rough experience for me that it prompted me to write this series!

More topics of interest:


Discussion (3) ¬

  1. Kai-shao

    Hi, that’s WP 2.7.x problem.

    Upgraded to WP 2.8, you’ll fix this CPU loading too high problem.

    Give Luv: Thumb up 0

  2. Aywren

    Yep, this was written before WP 2.8. While I have upgraded, I will still hold my breath to think all the CPU load will be fixed. I hope so, however. That would be really, really nice!

    Give Luv: Thumb up 0

  3. hosting

    this is great hosting list compare prize and more

    Give Luv: Thumb up 0

Comment ¬

You can add images to your comment by clicking here.

Optionally add an image (JPEG only)

NOTE - You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>