Chris Farrell Membership
eUKHost
1and1-co-uk Web Hosting
This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies. Find out more.

Reduce WordPress CPU Usage – Step #3 – Reduce Database Queries

 Posted by  Add comments
 

Reduce WordPress CPU Usage – Step #3 – Reduce Database Queries

This article is part of the, ‘Reduce WordPress CPU Usage’ series.

Plugins can enhance your blogs in so many ways. They can:

  • enable readers to sign up for your RSS feed,
  • automatically eliminate comment spam,
  • optimise your blog pings,
  • streamline your SEO efforts,
  • automating backups.

A high CPU usage can be caused by the number of calls that WordPress has to make to the database. WordPress retrieves almost all of the data it needs for pages, posts and plugins from the database.

  • Installing a caching mechanism such as the WP-SuperCache plugin will help but the calls will still be needed to produce the cached files.

How much Memory and CPU time should WordPress be Using?

Due to variations in server setups and how different hosting companies track server resource usage, I cannot answer specifically the question of how much memory and CPU time your WordPress installation should be using.

What I can do is give you average data for a bare bones WordPress installation with the default theme.

  • Average Total Time to generate the entire page: 0.1254 seconds
  • Average Total Time used by MySQL: 0.0017 seconds (1.35% of total time)
  • Average Maximum amount of memory used at any point: 17.56MB
  • Total number of MySQL Queries Ran: 14

Too Many Plugins Slow Down Your WordPress Blog

So how can you reduce the number of database queries apart from implementing a caching regime?

  • Reduce the number of plugins which store data in the database and/or make excessive calls to the database.

Remove Unnecessary Plugins

The first step is to simply remove any plugins which are unnecessary. This simple housekeeping can work wonders.

Disable Diagnostic Plugins

The second step is to disable plugins with are purely utilitarian or diagnostic until they are actually needed. Not all plugins need to be active all the time. For example I use, Broken Link Checker and Search Regex, neither of which need to be permanently active (two excellent programs by the way).

Reduce the Impact of Plugins

The third step is to reduce a plugins impact on the site by tuning of unnecessary function such as logging. If you think you have a problem with the plugin you can always turn logging back on again.

  • The Akismet configuration has the feature, ‘show the number of comments you’ve approved beside each comment author’. Turn this off.
  • If your spam plugin has an option to show the number of spam comments it has caught in the past. Turn this off.

Keep up-to Date

Keep your plugins up to date. The only caution here is that some plugins may not be updated to work with your WP version. Check the authors’ website, the best and most stable plugins are usually updated fairly quickly after WP is updated.

Hardcode Information

Hardcode As Much Information As Possible Instead of Grabbing It From the Database. Items Such As The URL Of Your Blog.

Diagnose the Problem

Check to see if your theme and all the plugins you use are taking up too much server time by adding one line to the footer.php file of your theme, See, ‘Display Page Load Time + Number of Queries’.

If you see more than 100 queries consistently your server is being worked hard and your pages may load slowly. Query numbers in the range 20 to 50 seem to be the norm with WordPress sites.

To manually find the offending plugin just deactivate each plugin, one at a time and refresh the page. You should see the number of queries (server requests) drop. Once you’ve found the problem, you have the choice of either keeping the plugin or deleting the plugin and finding a better alternative.

  • Note: Check that caching is not active when diagnosing the problem.

To automatically find the offending plugin try using yet another couple of plugins:

Memory Viewer [http://wordpress.org/extend/plugins/memory-viewer/].

  • Memory Viewer is a WordPress plugin that allows you to view WordPress’ memory utilization at several hooks during WordPress’ execution. It also shows a summary of MySQL Queries that have run as well as CPU time. It is very simple. All you need to do is: 1. Enable the plugin 2. Visit your WordPress site (YOU MUST be logged in as an administrator) 3. Scroll to the bottom of your page to see the data.
  • I don’t recommended its use on a live blog.
  • Note: Don’t forget to turn this plugin off when you’ve finished your diagnosis.

Debug Objects [http://wordpress.org/extend/plugins/debug-objects/]

  • The Plugin Debug Objects provides a large amount of information: query, cache, constants, hooks, functions and many more. Values and content can be displayed at the front-end and backend of the blog, to analyze errors and to better understand and develop WordPress. The plugin does not filter values and should only be used for information and optimization.
  • I don’t recommended its use on a live blog.
  • Note: Don’t forget to turn this plugin off when you’ve finished your diagnosis.

If you have any tips you can give on this subject just add your comments below…


KingSolutions.org.uk is hosted on JustHost

 Leave a Reply

(required)

(required)

87 queries in 0.884 seconds (Child).