How To Limit CPU Usage Of A Process With cpulimit (Debian/Ubuntu)
How To Limit CPU Usage Of A Process With cpulimit (Debian/Ubuntu)Version 1.0 This tutorial shows how you can limit the CPU usage of a process with the tool cpulimit on Debian/Ubuntu. 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. I do not issue any guarantee that this will work for you!
1 Preliminary NoteI will run all commands in this tutorial as the root user, so either log in as root directly (Debian) or become root like this (Ubuntu): sudo su If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power. In any case, the percentage is the same of what you see when you run top. cpulimit should run at least with the same user running the controlled process. But it is much better if you run cpulimit as root, in order to have a higher priority and a more precise control.
2 Installing cpulimitcpulimit is available as a package for Debian and Ubuntu, so it can be installed as follows: aptitude install cpulimit
3 Using cpulimitTake a look at the cpulimit man page to learn how to use it: man cpulimit NAME Now let's assume we want to limit the process apache2 to 30%. This is how we do it: cpulimit -e apache2 -l 30 The -e switch takes the name of the executable program file. You can take that name from the output of the top command. Instead of using the name of the executable program file, we can use the process ID with the -p switch. You can find out the process ID of the apache2 process as follows: ps aux or ps aux | grep apache2 Let's assume the apache2 process ID is 4510; we can then limit that process to 30% CPU usage as follows: cpulimit -p 4510 -l 30 Instead of using the name of the executable file (-e) of the process ID (-p), we can also pass the absolute path name of the executable program file to cpulimit with the -P switch; the absolute path name of the apache2 executable is /usr/sbin/apache2 so we'd use the following command: cpulimit -P /usr/sbin/apache2 -l 30 Please note that cpulimit will run in the foreground of your terminal until you terminate it with CTRL+C - terminating it will also remove any CPU limits.
4 Links
|




Recent comments
11 hours 41 min ago
1 day 6 hours ago
1 day 8 hours ago
1 day 8 hours ago
1 day 11 hours ago
1 day 12 hours ago
2 days 4 hours ago
2 days 5 hours ago
2 days 7 hours ago
2 days 8 hours ago