WordPress memory

How to monitor and reduce WordPress memory usage by plugins

WordPress memory

One of the best things about WordPress is that it’s so easy to extend your site’s functionality with the many (mostly) free plugins available on the plugin repository. But loading your site with too many plugins can cause your site to consume too many resources on your server, slowing your site down. So how do you find out what resources your plugins are consuming to help you reduce WordPress memory usage and speed up your site?

Reduce WordPress memory usage by plugins

In a WordPress page request, the point at which plugins are loaded depends on how they’ve been coded. WordPress runs through a series of typical actions on every request. You can see these actions here, including the order in which they are run. A plugin developer decided where in this their plugin is needed, depending on the functionality the plugin offers, and ‘hooks’ into one of these actions, overiding or extending the default WordPress functionality with their custom code. More general information on the basics of plugin writing is available at the WordPress Codex.

So, as an example you’ve got a site that has 10 (or more!) plugins. These are firing at different times during a page request, hooking into different actions, all over the place. So how do you go about monitoring which plugins are most intensive?

As standard, there isn’t an easy way to monitor what WordPress memory usage is as it loads all of the plugins you’ve got installed on your site. But there are three plugins that in tandem, can really help you to find out what’s causing your site to slow down. Let’s look at them.

1) P3 (Plugin Performance Profiler)

Created by the in-house team at GoDaddy, the P3 (Plugin Performance Profiler) plugin allows you to run a scan over your site to determine what resources your plugins are using, and when, during a standard page request. This allows you to see the worst offenders and reduce WordPress memory usage by removing them or finding alternatives.

Once you’ve installed the plugin running a scan is easy and quick, even on a large site. Once the scan is complete you’ll see a comprehensive results report such as this;

P3 (Plugin Performance Profiler) Report
P3 (Plugin Performance Profiler) Report

The Runtime by Plugin report shows you a simple pie breakdown of which plugins are causing the most load on your site during a page request. Very useful, and a very quick way for you to identify and reduce WordPress memory usage by removing plugins that you don’t need.

Even more useful is the Detailed Timeline, which shows when the plugins are being loaded during the page request, so you can see if any particular one is causing a problem at a particular point.

Detailed Timeline of plugin load
Detailed Timeline of plugin load

Using the P3 (Plugin Performance Profiler) is a great start, but how do we get more information about what’s causing our site to slow down?

2) Memory Viewer

As the developer of the Memory Viewer plugin says;

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 ran as well as CPU time.

Once installed, administrative users will see a new panel at the bottom of every page;

Memory Monitor output
Memory Monitor output

The report shows the memory usage at every major action hook, along with statistics on time and MySQL usage. You can also choose to show the queries that are happening at each hook, and output allows gives you an idea as to what code is responsible, which allows you to pinpoint exactly which ones are causing excessive load.

Generally a good indicator is when you see the ‘Current Memory Usage’ column leap up significantly from one action to the next. Any large jumps are worthy of investigation, as there could be plugins running that are the cause, or custom scripts in your theme that need optimisation. By removing or optimising these blockages, you can reduce WordPress memory usage significantly and then retest to see the effect of your changes on page load speed.

3) Debug Bar

Finally, the Debug Bar plugin offers similar functionality to Memory Monitor, but installs a panel into the WordPress admin bar. It is also extendable via other plugins to track and monitor other data such as the errors and warnings that PHP may record when you have the WordPress debug, WP_DEBUG, switched on.

Personally I prefere the ease and simplicity of Memory Monitor, but there’s no doubt that Debug Bar is extremely powerful.

Debug Bar output
Debug Bar output

So that’s three different, easy ways to monitor your WordPress site and find out which plugins and scripts you need to consider removing or tweaking to reduce WordPress memory usage and speed up your site.

I’d be really interested to hear what other WordPress developers use to monitor and optimise their sites.

Published by

Stu Miller

Web consultant and specialist, WordPress developer and PHP developer based in Leeds, UK. 15 years experience in architecting web sites and applications. Co-founder and Technical Director of SmartInsights.com, formerly the same of First 10 Digital

14 thoughts on “How to monitor and reduce WordPress memory usage by plugins”

  1. Hey, thanks for this. I used the GoDaddy plugin on one of my sites and… BOOM removed 4 plugins that I apparently thought were holding up something important. Good stuff as I subscribe to the less is way more theology.

  2. Stu, after experiencing upwards of 5 second page loads on a highly-cached site, I came across this post and installed the 3 performance plugins to see what was up. I was shocked when P3 indicated that, out of my 22 plugins, ONE of them was consuming 49% of all the resources on my site. It’s Timely’s All-In-One Event Calendar. It’s really a nice-looking event calendar, but it’s difficult to get support, they’ve removed their wordpress plugin page, and now I see that perhaps their coding is not terribly efficient. This was eye-opening for me.

  3. P3 didn’t seem to work for me. I get errors: “Warning: fopen() [function fopen]: Unable to access…”, “failed to open stream…”, “No such file or directory in…”, “Turned off performance scanning”, “Error reading scan”.
    Reinstalling the plugin didn’t work. Once I removed the “Memory Viewer” plugin, it worked fine. Has anyone encountered this too? Can the two plugins run at the same time?

  4. Nice article.. but.. as I see, on my page Jetpacks and SEO Ultimate are the heaviest memory eaters – i like the functionality of Jetpack (Comments also work with Twitter, FB, G+ etc, Infinite Scrolling, article-based Statistics) and don’t want to miss it, and SEO Ultimate is really powerful. What I want to say with this is that I’d like to use alternatives if there were any.

  5. hi stu. I’m about to use P3 plugin to monitor my running plugins, so I searched the review and finally I found your post. Thanks for this, and thanks for convincing me. Nice

  6. Hi Stu, thanks for sharing – the P3 scanner is extremely useful. Turns out WordPress SEO is a bit of a killer on a project that’s just gone live on a tiny AWS server. Thanks to GoDaddy – who’d have thunk it?!

  7. Hi Stu,
    I knew P3 (Plugin Performance Profiler) before. I have one website installed on Godaddy and recently experienced an issue with Fatal error: Allowed memory size. I tried Memory viewer and it works great and it is simple to use. I might give it a try with the last one, Debug bar which it seems from your pictures more detailed indeed. All the Best. Donald

Leave a Reply