How To Install CPUTool To Limit CPU Usage on Ubuntu
We explain all the steps you must follow to know how to install and configure CPUTool in Linux to limit CPU usage
CPUTool is a simple tool which allows us to verify in real time the use of CPU and thus be able to restrict and control the use by those processes, services or users that have high levels of consumption allowing to stabilize server behavior.
For this tutorial, we will use Ubuntu 16.04 Server since CPUTools is compatible with Debian and Ubuntu environments.
To install CPUTool in Ubuntu 16.04 Server, we will execute the following command:
sudo apt install cputool
To check how this tool works we will run the next line which supposes a high CPU consumption:
dd if=/dev/zero of=/dev/null &
We can use the top command to have a real-time report of the active Ubuntu processes:
The PID 2801 is currently consuming 99.3% of CPU which is somewhat high for a single process and user and that is where CPUTools comes into action.
We can use the parameter –cpu-limit or -c to limit a specific process to a certain percentage of CPU usage, for example, if we want this process to use only 45% of the CPU we will execute the following:
cputool --cpu-limit 45 -p 2801
The -p parameter indicates the name of the PID. If we rerun the top command we will see the CPU usage that has decreased:
To stop the use of top, we will use the Ctrl + C keys.
If we want to deploy and control a group of processes we must first know which PIDs are composed, for example, if we're going to see the processes of the web server we will use the following line:
The result will be the following:
There we can use the -P parameter to limit the use of this group of processes:
cputool --cpu-limit 15 -P 1532
To see all the options, we have with CPUTool we can use the following command:
Thanks to this command we will control accurately every process that affects the performance of the CPU.