How do we know which Wordpress plugins causes High CPU Usage?

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by vekou, Dec 7, 2010.

  1. vekou

    vekou Member

    Messages:
    196
    Likes Received:
    1
    Trophy Points:
    18
    Recently, I have been suspended 3x for High Resource Usage. I know what I'm supposed to do, disable the plugins and enable them one by one to see which plugin is the culprit. I've been experimenting this for months now, and still I get suspended. The problem is, even if I enable all of my plugins (I don't use too much plugins by the way), I don't get High Resource Usage and everything works normally. Then after about a few days to about a week, my website will be suspended. I installed a plugin that will monitor my Wordpress memory usage, and it is constant at about 7%. I wouldn't be suspended for using around 18MB of memory from the 64MB allocated.

    My questions are:
    • Aside from this troubleshooting method, what other methods can we use to know if we are reaching the resource usage limit?
    • I know that memory is not the only resource that is counted in the limit, i think it also includes the time a script is run, etc. What other resources are included in the limit and what those limits are?
    • I've noticed that everytime I get suspended, after unsuspending myself, I notice a few spams awaiting for moderation that weren't caught by Akismet. If Akismet is down and spam comments keep flooding in, will this hit the High Resource Limit since the script will probably keep on trying to contact the Akismet server?
    • Am I making sense?
     
  2. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    I can't answer your questions definitively, but I can tentatively.

    Sadly, I know of no methods that are easy or have a high likelihood of succeeding.

    From PHP, you could get current processor stats (including CPU usage) using procfs, but PHP on the free hosts is restricted in what can be accessed via the filesystem. This would also require altering the plugins to add scaffolding at various points in them to log CPU usage. Adding scaffolding to log memory usage is still a possibility, but not an easy one.

    A PHP profiler (such as Xdebug) can be used to gather information on how long various functions execute in a script. With that information, you could see how much time is spent in the functions each plugin defines. Since none is installed on the X10 hosts (and never will be; profilers aren't for production servers), you'd need to set up your own server to use one.

    Since what you really need is a way of getting information at the moment WP reaches the resource usage limits, I doubt the above will be very helpful. The surest way is to start with no (or very few) plug-ins enabled, then enable one every other week. You could enable (then disable) more than one at each step, going for a binary search approach, but that will cause quite a few suspensions.

    The number of processes running under your account, the total time your processes run in a given period and the total percent of CPU usage are also monitored.

    In mid 2009, the limits were:
    • 25% CPU
    • 5% memory (eg 400 MB)
    • 240 seconds of CPU time per hour
    • 20 concurrent processes executing

    If anyone (hi, admins) knows if these are the current values, it would be useful information to add to the HRU wiki page.

    It looks as though Akismet retries every 20 minutes. The retry function itself (take a look at akismet_cron_recheck) doesn't do too much. If there are a huge number of comments, it will have an impact, but shouldn't otherwise. You could add a LIMIT clause to akismet_cron_recheck's $comment_errors query to put a cap on the number of outstanding comments to process at any one go. For example:

    Code:
    		SELECT comment_id
    		FROM {$wpdb->prefix}commentmeta
    		WHERE meta_key = 'akismet_error'
    		LIMIT 20
    
    You could make the limit configurable via a plugin option.
    PHP:
        $comment_errors $wpdb->get_col$wpdb->prepare("
            SELECT comment_id
            FROM 
    {$wpdb->prefix}commentmeta
            WHERE meta_key = 'akismet_error'
            LIMIT %d
        "
    get_option('akismet_retry_comment_limit')) );
    You'd also need to update akismet_conf in the plugin's admin.php to both handle changes to the new option and to display a form input for the option. To add the option itself, your best bet is probably a call to register_setting in akismet_admin_init in admin.php. I don't write WP plugins, so there might be a necessary alteration I'm leaving out.

    Yes. More than many posters.

    Some other thoughts on resolving this:

    Resource spikes (especially ones that only happen every few days to a week) might be caused by spider crawls. Add a robots.txt to limit what spiders access.

    Caching plugins can help, but only if properly configured for your site.
     
    • Like Like x 1
  3. vekou

    vekou Member

    Messages:
    196
    Likes Received:
    1
    Trophy Points:
    18
    thank you very much information. I've tried disabling all the plugins, then enabling one per day. I never experienced any suspensions during that time aside from the "Page temporarily unavailable" screen which is kinda frequent during peak hours. I'm trying to figure out what triggered my suspensions if it was CPU hogging or cpu processing time or hitting the memory limit. For the meantime, I've installed a caching plugin so i can save memory and cpu when my site is not creating cache. yes I know that it can trigger a suspension, but at least it can save me from sudden spikes from spiders and unwanted crawlers.
     
  4. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    Since it sometimes took a week before being suspended, waiting one day between re-enabling plugins isn't enough time. You'll need to wait a fortnight between enabling plug-ins.
     
  5. vekou

    vekou Member

    Messages:
    196
    Likes Received:
    1
    Trophy Points:
    18
    okay thanks, but i'll probably disable plugins selectively, the one who are likely to cause spikes.
     

Share This Page