In this article we'll discuss how you can limit the CPU usage of an intensive task and spread it out over a longer period of time. This can help ensure that you aren't causing problems of sluggishness on your own website, or affecting other users on the same server while running an intensive task.

Limiting your CPU usage is a more advanced task that would require a VPS or dedicated server hosting plan. On a VPS you can limit CPU usage to help ensure that you're remaining within the limits of your VPS package, so that you don't affect your VPS neighbors sharing the same physical hardware with you and possibly risk a temporary suspension. On a dedicated server you can limit the CPU usage of these intensive tasks to help ensure you don't slow things down overall on your own server.

For instance lets say that you run a nightly backup of your site's files, this type of task typically isn't too time sensitive, so letting the intensive archiving of the backup process run over the course of an hour or so should be fine. If the server is busy at the time it would need most of its CPU time to handle website/email/database requests, and if you throw an intensive task in the mix it could make everything slow down.

cPanel comes with a script called cpuwatch which allows you to watch the current load of your server while a process is running. If the load on the server exceeds the limit that you've set for the load, it will go ahead and pause the process and leave it paused until the server has become stable again. This is a great way to start something intensive and set it and forget it, without having to worry about it bogging down your server.

In the example below I'll be backing up a /public_html/ directory to an archived file and limiting the CPU usage so it doesn't slow down the server at all.

  1. Login to your server via SSH
  2. If you're on a VPS you'll always want to set the CPU limit to 1 or lower (.9 .8 .7 etc...), or on a dedicated server you can run the following command to see how many processors you have which will affect how high your load average can get before things start running slow:

    grep pro /proc/cpuinfo -c

    This should simply give back the number of cores: 4

  3. Now you can enter in the path to the cpuwatch script, followed by the limit on how high the load can get before the task is paused, followed by your task to run:

    /usr/local/cpanel/bin/cpuwatch 4 tar cvzf 11-30-2012.tar.gz ./public_html/

    In this case we are setting the limit to pause at to a 4, using the tar cvzf command to archive files into a file called 11-30-2012.tar.gz, and we're doing this to all files in our /public_html directory.

    Because we used the verbose option on our tar command, we'll see the active file that is being archived as the task runs. While this is happening if our server's load reaches a 4 or higher you'll start seeing that the process gets paused until it falls back below that threshold.

    ./public_html/.htaccess
    ./public_html/index.php
    ./public_html/images/logo.gif
    Waiting for load to go down to continue
    Waiting for load to go down to continue
    Waiting for load to go down to continue
    ./public_html/images/magnify.gif
    ./public_html/images/nested.gif
    

You should now understand how to use the powerful cpuwatch script to help keep your intensive tasks from overloading your server. You can also use cpuwatch in your cronjobs so you don't have to be sitting there at the console to take advantage of it.

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?

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: 2220
Heartbleed 0-day OpenSSL security bug
Updated 2014-04-14 04:43 pm EST
Hits: 5642

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!