{loadposition position_log_memviewer}While WordPress is great software because of its ease of use, it does have a history of using excessive server resources (such as memory and/or cpu time) at times. This is not always the fault of WordPress directly, but instead it could be the result of either:

  1. a "bad" plugin
  2. a custom theme

With so many lines of code in WordPress and custom user code written in plugins and custom themes, pinpointing directly where the excessive server resource usage is occurring is a difficult task.

InMotion Hosting has developed a WordPress plugin that can help identify where in your WordPress installation there is a problem. This plugin is called Memory Viewer.

 

 

How Does the Memory Viewer Plugin Work?

WordPress is built up of many different functions that perform specific tasks. These functions run at very specific times during WordPress' execution. For example, there are functions that run when WordPress begins to load your theme, and there are specific functions that run when WordPress is creating your site's footer. For plugin and theme developers, WordPress has created several different "hooks" in which you can run your custom code.

What the InMotion Hosting Memory Viewer Plugin does is jump in at certain hooks and logs specific data, including:

  • The current memory used by WordPress at that time
  • The maximum amount of memory used by PHP at that time
  • The number of MySQL queries that have run at that point
  • The amount of time MySQL has used up to that point

So in summary, the Memory Viewer Plugin takes snapshots of WordPress' activity at certain points in WordPress' execution.

 

 

How do I use the Memory Viewer Plugin?

  1. Download and install the plugin

    The first thing you'll want to do is download and install the WordPress Memory Viewer Plugin:
    WordPress Memory Viewer 1.5

  2. Install and activate the plugin

    After installing and activating the plugin, visit one of your WordPress pages. At the bottom of the page, you'll see a table of data, similar to the screenshot below:
    results-from-the-inmotion-hosting-memory-viewer-wordpress-plugin

    Please note that this data will only show when you are logged in as an administrator.

  3. Scan the data for any abnormalities

    At this point you can scan the data for any abnormalities. For example, if at one hook you're using 15MB of memory and then at the next you're using 50MB, you can get a good idea of where in WordPress' execution the big jump in memory took place. You can also click the "show queries" link to view the exact queries that were ran between the two hooks. More importantly, you can see how much time it took for each query to run.

While the plugin is named "Memory Viewer", it also tracks cpu time, which may be the culprit (and not memory usage). You can review the time between each of the hooks to help determine if there is a problem somewhere. For example, if the average time between hooks is about .005 seconds and you notice an abnormal time of .9 seconds as one of the entries, this can help pinpoint where in the script it is taking long to execute.

 

 

How much Memory and CPU time should WordPress be Using?

The numbers we mentioned above were just examples that we came up with. Due to variations in server setups and how different hosting companies track server resource usage, we unfortunately cannot answer specifically the question of how much memory and CPU time your WordPress installation should be using.

What we can do however is show you average data for a bare bones WordPress installation with only the Memory Viewer Plugin enabled. You can then compare your data against ours to determine how heavy your script is running.

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

 

 

Can I log data at other times in WordPress' Execution?

Yes! You can place the following code in your PHP code to take a snapshot of server usage at that time.

mvimh_log_data_at_hook("identifier");

The "identifier" is just any text to help you identify the data in the table. For example, in the screenshot below, we used the following functions:

mvimh_log_data_at_hook("line 10 of twentyeleven/content.php");

mvimh_log_data_at_hook("line 24 twentyeleven/sidebar.php");

calling-the-memory-viewer-plugin-during-custom-points-in-wordpress

Please be aware however that you cannot run these functions at any time you wish. They will only run after the Memory Viewer plugin as been initially loaded by WordPress.

 

 

How can I receive additional support / report bugs / suggest features?

If you have any questions about using the WordPress Memory Viewer plugin, feel free to ask a question or post a comment (on the bottom of this page), and we'll be more than happy to help!

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Support Center:
Email Address
Optional, but our team may contact you for more information.
Like this Article?

Comments

Post a comment
n/a Points
2014-04-02 9:33 pm

I am learning this pluggin. but I like what it does so far, Thank You

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Write New!
Do you want to publish a tutorial to our support center?

News / Announcements

SSL Certficate Warnings
Updated 2014-04-14 11:34 am EST
Hits: 2228
Heartbleed 0-day OpenSSL security bug
Updated 2014-04-14 04:43 pm EST
Hits: 5650

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!