frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How to limit CPU resource for your processes?

CPULimit is a fine tool to manage and limit the CPU utilization of your VPS server. It allows you to limit each process that you might think is utilizing more CPU and affecting another process on the server. Or perhaps, you just want to manage the CPU usage better for a few different CPU-consuming processes, but at the same time leave some of the CPU available for any unexpected tasks and etc.

Installing CPULimit

Ubuntu/Debian:

sudo apt get install cpulimit

CentOS:

sudo yum install epel release
sudo yum install cpulimit

CPULimit usage

An example is that we run dd command to have a heavy CPU usage process and limiting it using the CPULimit.

Running dd command:

dd if=/dev/zero of=/dev/null &

Check the dd process usage and PID

top

You should see something like:

PID    USER PR  NI   VIRT      RES SHR S %CPU %MEM TIME+   COMMAND
19739 root    20   0     108096   616   520  R    39.5     0.0     0:09.48   dd

You can see the CPU usage for the dd process is 39.5%, now let's use CPULimit to limit the process CPU usage to 15%

cpulimit -l 15 -p 19739 &

  • argument -l refers to a percentage value of how much CPU we are going to assign;
  • argument -p refers to the process ID.

After this command is executed you can use top again to check the CPU usage. The value should be around 15% (+/- 2%).

That is it, now you know how to use CPULimit to manage your CPU utilization for a specific process.

Tagged:

Comments

  • cpulimit wasn't effective. I've also tried timeout but that doesn't work too well either.

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch