Hosting how to tech news wordpress

WordPress High CPU Usage Fix : Reduce CPU Usage in Shared Hosting

wordpress high cpu usage fix
reduce CPU usage on WordPress

WordPress is the most renowned platform for professional blogging as well as server related problems. If you were using WordPress on shared hosting for a while, I’m sure that you might have came across CPU related errors. WordPress is so-called the most notorious CMS to handle the CPU resources.

Here we’re dealing with the tips to reduce CPU usage on WordPress blogs. This WordPress high CPU usage fix guide has been proven with my own experiments and I run high traffic blogs in shared hosting without any excess CPU issues. I assume that you are on shared server and learned the basics of WordPress and cPanel.

WordPress High CPU Usage Fix : 7 Unbeatable Ways

1. Remove Unnecessary Plugins

This might be first point you would ever see in WordPress CPU optimization. Plugins are the most resource eating materials when it comes to WordPress. Hosting companies usually suggest maximum 3 or 4 plugins but in the live case, it isn’t possible unless we run a story narration blog.

Since we are solely depending on plugins to automate certain processes, it’s really hard to find the plugins which should be avoided.

In this scenario, we must compromise on visual effects and should focus on blog optimisation. ie., concentrate on necessary show ups and avoid eye-catching sliders, related posts plugins etc.

In order to find the most resource consuming plugin, you can try P3 Profiler (Which is again a plugin :P). It accurately measures your server resource from head to toe from plugins side and show the results in in the form of easily understandable charts.

Try to avoid use of badly coded related post plugins. Related post plugins have many issues. Even good plugins in this category like ‘Yet Another Related Posts Plugin (YARPP)’ has many issues.

Many web hosts have banned its use in shared hosting plans. It resulted in high load of CPU and increased query time. Think before using them. I suggest you to use nRelate Related Posts plugin instead of YARPP.

Bonus Tip

Uninstall this plugin after finding which plugin lags your blog. However, you can re install this whenever you want to check the resource again.

2- Using Cache Plugins

W3 Total cache (W3TC) and WP Super Cache are the most effective cache plugins I’ve ever came across. Though some people suggest WPSC, I should recommend you to install W3TC as it’s loaded with advanced options like minification, database cache, page cache, cache purging, CDN optimization, CloudFlare integration etc.

After installing either of these plugin (Preferably, W3TC), configure every options from its dashboard. It can also be used to flush your temporary DNS cache which is very helpful wherein DNS propagation period.

3- Using CloudFlare

CloudFlare is a free blog optimization service which can also be considered as a basic CDN service. Don’t expect too much from their CDN as it accelerates your blog without any bucks. However, you can significantly improve your page loading speed and CPU load.

It works as an intermediate between the blog and the server. Whenever user requests a page, CloudFlare provides the page without letting the blog from accessing the server contact. It automatically catches your pages from the server side and stores in its own large data servers.

Let’s see an example. Suppose you are going to get some milk from a cow (Physically). How it would be if you get the milk from a milkmaid which has already been taken from the cow? Isn’t it easy? It literally reduces the load of “cow” (Server here) from frequent disturbance. It also provides faster access and you don’t have to walk longer.

In the same manner, CloudFlare grabs your pages from the server and stores in a place (Data centers) where it can be accessed quickly without pinging to the server. That’s all.

4 – By Optimizing Cron Jobs (wp-cron.php)

Cron Jobs are specially assigned programs to ping the server automatically when there arise a page request. By default, Cron Jobs ping servers in a certain interval of time which causes extra load on the server. Fortunately it isn’t a must do action at all. So you can regulate the time interval of pinging to higher limit.

It noticeably reduces your server resource from the back end. Let’s have a look on wp-cron pinging effect.

If you are getting 50 visitors to your site every hour, and each of them reads 2-3 pages, then wp-cron.php is being called:

50 x 2.5 = 125 times per hour
125 x 24 = 3,000 times per day
3,000 x 30 = 90,000 times per month!

[Source :http://www.boltwebhosting.com/wordpress-optimization/wp-cron-php-how-to-stop-it-from-running-frequently.html]

If you have added something on your PHP to load from external source and the external site is down then your page will also load slowly.

How to Optimize wp-cron.php?

First, you need to stop wp-cron.php from running on every page view. Do this by opening the file wp-config.php (found in the folder where WordPress is installed) and add the following line close to the top of the file:

define(‘DISABLE_WP_

CRON’, true);

What that does is tell the WordPress engine not to run the wp-cron.php script on every page view, essentially it disables it. Second, you need to create a way for the wp-cron.php file to run on a regular basis. Usually the best way to do this is a normal cron job. Create a cron job in cPanel that runs every hour and have the cronjob run this command:

wget -O /dev/null http://www.example.com/wp-cron.php?doing_wp_cron

Replace www.example.com with your blog

4 – Using Light Loading Themes

Simple, elegant themes can invisibly reduce your database call into a great amount. There are plenty of WordPress themes that boast infinite add on features like inbuilt slider, ad boxes, related posts tweak, subscription pop up etc.

Keep in mind that in accordance with the number of features you use, the chances of high server load are high. I personally suggest Genesis Framework as it’s running on thousands of authority blogs.

5. By Correctly Optimizing WP Database

Databases are something which is very important to every blog. It contains all your posts, comments, meta data etc in tabular form. It indeed a MySQL section.

A poorly optimized database table can annoyingly hamper your blog. It uses unnecessary space to store unwanted files which will certainly lags your blog.

WP-Optimize is a great free plugin to remove post revisions, spam comments, unapproved comments, tables etc. You can save a hell lot space by just running this cool plugin. Remember, a properly optimized database ensures maximum possible speed apart from the server side.

6. By Compressing/Merging Existing Images in your Posts

There’s a saying ” A picture can speak thousand words”. When it comes to blogging, images are most important factor to grab attention of the readers. On the other hand, it can also be used to gain entry search engine traffic by correctly rendering Alt tags.

But excessive insertion will not only slower your blog but also turns as a nuisance to your loyal readers. Whatever it may be, you may reduce maximum picture additions in your blog. Alternatively, you can host your all images in a sub domain which won’t affect your page speed, hence faster response from server.

Most of the hosting companies provide image optimization tools in cPanel. You can either depend any of these free tools or use any 3rd party apps. Also if you are posting long articles which possesses dozens of images, you can split the post to 2 or 3 pages with respect to the length of the article. This method can also be used in comment section if you are getting hundreds of comments in each posts.

7. By Updating Possible Functions.

Many plugins release newer versions in certain interval of time. Some themes also update as well. Here, if you don’t update these functions properly, it will automatically surpass update requests whenever you load your blog. So update every plugins and themes (including WordPress) as fast as possible.

In short, Always update everything. If there is an update available, you should always go for it. Updates contain security improvements and bug fixes.

Takeaway

Here I’ve mentioned the top 7 tips to reduce CPU usage on WordPress blogs. There are so many tiny tips which will help you to build a shared hosting blog apart from this. Just implement it and get rid off server errors. I expect your valuable comments and feedback for this article. Also, take a while to share this post as well. Happy blogging.:D

About the author

Sidharth Pk

Sidharth. Professional Blogger. Android dev. Audiophile. Find us on Google+
Find Me on Facebook Follow Me on Twitter

39 Comments

Click here to post a comment

    • Hi Aditya. WP Cron can dramatically reduce load up in servers if you do correct optimization. Do well and let me know if you caught any error.

    • Hi Arup, Thanks for being here. You’re right, nowadays, lots of blogs are being banned due to excessive server resource usage. Hope these tips will help them to build a risk free blog.

    • I’m glad you liked this post. When compared to WPSC, W3TC has many more features and configurations. You had better try the latter and check whether it reduces your CPU load. Thanks for commenting Jawad.

  • Hey, I was just wondering where your site was hosted at? It loads pretty quick. Could you provide some insights on it?

  • Hi Sid, thanks for this wonderful resource.

    1. I am using just 5 plugins.
    2. I use Total Cache with Max CDN
    3. I created Cloud Flare account, waiting to watch some results.
    4. How to optimize CRON jobs? I have absolutely no idea. Couldn’t figure it out from your explanation.
    5. Am using Elegant Themes
    6. Used plugin and optimized database.
    7. How do I transfer existing images to a sub-domain? Do I need to change the image link for every post published since 2011?
    8. All themes and plugins updated.

    After doing these, there were 100% CPU usage twice in the last 60 minutes; definitely better than 5-6 times but I need to do more.

    I see a lot of errors in log file, like –

    [30-Apr-2013 14:34:02] WordPress database error MySQL server has gone away for query SELECT * FROM wp_comments WHERE comment_approved = ‘1’ AND comment_post_ID = 4444 ORDER BY comment_date_gmt DESC made by require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/Basic/category.php’), get_template_part, locate_template, load_template, require(‘/themes/Basic/includes/defaultcat.php’), get_template_part, locate_template, load_template, require(‘/themes/Basic/includes/postinfo.php’), comments_popup_link, get_comments_number, apply_filters(‘get_comments_number’), call_user_func_array, et_comment_count, get_comments, WP_Comment_Query->query, W3_Db->query, W3_DbCache->query, W3_DbCallUnderlying->query, W3_Db->query, W3_DbProcessor->query, W3_Db->default_query

    [30-Apr-2013 14:34:02] WordPress database error MySQL server has gone away for query SELECT * FROM wp_posts WHERE ID = 4445 LIMIT 1 made by require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/Basic/category.php’), get_template_part, locate_template, load_template, require(‘/themes/Basic/includes/defaultcat.php’), get_thumbnail, wp_get_attachment_image_src, image_downsize, wp_attachment_is_image, get_post, WP_Post::get_instance, W3_Db->query, W3_DbCache->query, W3_DbCallUnderlying->query, W3_Db->query, W3_DbProcessor->query, W3_Db->default_query

    All this is beyond my understanding 🙁

    ~ Chitra

    • Hi Chitra. It’s kinda weird issue as far as I think.You didn’t answer me why you haven’t move to HostGator. You’re using just 5 plugins right? In this blog, I’m using almost 20 plugins and I’m not even using any CDN like MAX. And I’m sure you can expect better result from CloudFlare. It reduces the overall bandwidth to a great extent. And elegant themes are class ones and I’m not sure whether it causes any problem. And as an answer for your 4th and 7th queries, I will be posting the complete guides on Cron job optimization and subdomain image hosting. Stay in touch . 😀

  • Hi Sid,
    Thanks for sharing this useful information.
    I’m use shared web hosting and there are 3-4 blogs hosted there. When I do some tweaks with my files, the CPU usage goes 100% and all other blogs goes down.
    And from my experience, Hosting images on a sub-domain and using cloudflare helped me a lot.
    Your tips really helped me in reducing CPU usage. Thanks for the great share!

    • Yeah, hosting all images in a sub domain is the best way to reduce load in a WordPress blog. I will be posting a complete guide on this. And thanks for commenting and glad to hear your appreciation. Stay in touch.

  • excellent article sid,
    you have covered most of the tips.

    The cache plugin is an absolute must, i have seen strong vps and dedicated servers going out of service due to not having a cache plugin for their wordpress blogs.

    will check out the other options too, am on a VPS from hostgator, so far the cpu usage is not an issue,
    cheers!

    • Much delighted to hear that Bro. Glad. Cache plugins can reduce up to 60% load and hence it’s so important. As you are on VPS, you won’t be getting any problems. This article is mainly meant for shared hosting users. Thanks a lot for your time and stay in touch.

  • All these issues are known except CRON Job. Another factors you just missed from this wonderful tutorial is – losslessly compressed Images and programming errors in wp-themes like proper use to XHTML tags and CSS.

    One more issue which is not even answered by the pros are – how much cloudflare affect the performance of your site as i am not able to measure any significant changes after implementing this on my shared hosting(Hostgator). Waiting for your kind attention

    • Thanks for letting me know the point Rakesh. Poorly coded themes can definitely ruin the blog in all aspects, say security and page speed. Anyway, I will be adding it very soon. Also, when it comes to CloudFlare, it definitely helps to reduce bandwidth without any doubt. You can check it at the CF dashboard. But I don’t know whether it helps to improve page speed. But I think using CF along with cache plugin can make wonders, hence it’s even suggested by hosting companies.

  • This post was awesome! I will try the cron part, since the time I have started using Google pagespeed my blog has been somewhat fast but admin panel is almost slow as a crawl should I use cloudfare along with it or should I remove it to only use cloudfare ??

    • Slow loading admin panel is common as you’re in shared hosting but the blog will load faster than the dashboard. Here, cloudflare doesn’t have any role. It just store blog pages and nothing else. I think you’re on hostgator right?

  • great post sid…that cow and milk example was awesome. i am too worried about my page speed. recently i moved to hostgator dedicated server but still i want good page laoding time. i am using cloudflare and low res images. will try some of the tips you suggested..and please publish that post about “hosting images on sub domain or other places” ASAP..thanks..

    • Thanks for your compliment Prabhat. I will surely publish article on hosting images on subdomain as it’ll reduce the load time significantly. Keep visiting and thanks for your comment. 😀

  • CPU limit is the main restrictions when we consider shared hosting,i too had the same problem when traffic begins to rise in my blog,i faced suspension from my host due high CPU usage.Then tried to find the host that doesn’t have this creepy problem,every time vps hosting surfaced but I never took it due to its cost.
    I finally found a new category in hosting called litespeed type,these type of hosting doesn’t have any CPU usage limit but it was also costly,atlast I found a hosting company named veeble which offered litespeed at very low cost,now the intresting part is that they are from Kerala,from where you and me are from.

  • Hi

    Nice info on High CPU Usage I have only just noticed this problem in my Cpanel I Have recently put the WP Super Cache plug-in And altered my Crone Jobs this as slightly dropped my CPU usage was at %50 plus
    Now down to %40 plus so got it down by about %10

  • Excellent and very useful post! Well, only 3 or 4 plugins is very difficulty as plugins boost the entire power of WordPress blog, but it’s good to use less plugins as possible. And yes, optimizing the database is also very important and WP Optimize is a great plugin to accomplish it. Thanks for share and tweeted 🙂

  • Hi,

    I didn’t know that Cronjob.Php could also do wonders to optimize the blog performance. Really informative article specially for serious blogges who don’t want to compromise on providing best experience to their visitors.

  • thank you so much dude.recently i have purchased shared hosting account from hostgator.my site traffic is only 3000 page views per day, but my cpu usage shows 80/100 %.then i have made some changes as per this articls.now my cpu load is 25/100 %.thank you so much.

Categories

%d bloggers like this: