Friday, September 30, 2011

Limiting CPU Usages in Linux using cpulimit

January 27, 2010 by  
Filed under cPanel, General, Helm, HyperVM, Kloxo, Plesk, Webmin

2 Comments

You might have already know how to check the CPU usages of any process. However, worried about any process consuming too much CPU? You should know, you can control the CPU usages of any process by CPU limiter. cpulimit is a free software to limit the CPU of any process. Here is the excepts from there site:

cpulimit is a simple program that attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don’t want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.


How it works

Note that you don’t need to read this paragraph in order to use cpulimit, you can safely skip it if you are not interested in tweaking cpulimit.
So, you are curious to know the secrets of cpulimit Of course there is no secret if you are a C developer, but I will try to explain to everyone. The work of cpulimit is done all in userspace, so it doesn’t interfere with the Linux scheduler. Basically, the target process, which you can specify by pid, name, or command line, is continuosly paused and resumed by sending it SIGSTOP and SIGCONT signals. Signals are sent by cpulimit in appropriate moments, based on the limit specified by user and the process statistics read from /proc.

System Requirements

cpulimit should run on every Linux 2.2 or greater. It has been reported by several users that cpulimit works fine even on SMP hardware, but consider that if you have more than one cpu there is a little difference in the meaning of cpu usage (see below).
If you can modify the source code of cpulimit to make it run in another OS, please notify me, so I can publish your code. I think that the only non-portable code is to iterate through the process list and get process statistics.

Installation

You may download the latest from the site. Now the latest is 1.1.

You may also download from  SVN source:

svn checkout https://cpulimit.svn.sourceforge.net/svnroot/cpulimit/trunk cpulimit

A Remarkable Book from Wiley-Finance
PQD
"An excellent book!"
  — Paul Wilmott
Want to break into the lucrative world of trading and quantitative finance? You need this book!

Then extract the source and compile with make:

zxf cpulimit-.tar.gz
cd cpulimit-
make

Usages

Limit the process pidgin by executable name to 20% CPU:

cpulimit –exe bigloop –limit 20
cpulimit –exe /usr/bin/pidgin –limit 20

Limit a process by PID to 25% CPU:

cpulimit –pid 3982 –limit 55

Launch a process by command line and limit it to 30% (in development version only!):

cpulimit –limit 30 /etc/rc.d/rc.boinc start

GD Star Rating
a WordPress rating system
Limiting CPU Usages in Linux using cpulimit, 10.0 out of 10 based on 1 rating
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Related posts:

  1. Secure your Linux Servers
  2. DoS Protection via APF, BFD, DDOS and RootKit
  3. Installing Suhosin by Patching PHP Source
  4. How do I find out Linux Resource utilization to detect system bottlenecks?
  5. Installing Suhosin as PHP Extension in Linux

Comments

2 Responses to “Limiting CPU Usages in Linux using cpulimit”
  1. boss says:

    This is a great idea. I have seen far too many sites get suspended due to over-using a server’s processor. This could save a lot of time, trouble and money for both the host and the customer. =)

    GD Star Rating
    a WordPress rating system
    Reply

Trackbacks

Check out what others are saying about this post...
  1. Limit Accounts by CPU - cPanel Forums says:

    [...] Limiting CPU Usages in Linux using cpulimit | Control Panel Blog Quote: [...]

    Reply


Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
Click here to cancel reply.