Configuring CPU Limits for Virtual Machines and ContainersCPU limit indicates the maximum CPU power a virtual machine or Container may get for its running processes. The Container is not allowed to exceed the specified limit even if the server has enough free CPU power. By default, the CPU limit parameter is disabled for all newly created virtual machines and Containers. This means that any application in any virtual machine or Container can use all the free CPU power of the server. To set a CPU limit for a virtual machine or Container, you can use one of these options:
Both options are described below in detail. Using --cpulimit to set CPU limits
As a rule, you set a CPU limit for a virtual machine or Container by using the
# prlctl set 101 --cpulimit 25 This command sets the CPU limit for Container 101 to 25% of the total CPU power of the server. The total CPU power of a server in per cent is calculated by multiplying the number of CPU cores installed on the server by 100%. So if a server has 2 CPU cores, 2 GHz each, the total CPU power will equal 200% and the limit for Container 101 will be set to 500 MHz. Now imagine the situation when you migrate Container 101 to another Hardware Node with 2 CPU cores, 3 GHz each. On this server, Container 101 will be able to get 25% of 6 GHz—that is, 750 MHz. To ensure that Container 101 always has the same CPU limit on all servers, irrespective of their total CPU power, you can set the CPU limits in megahertz (MHz). For example, to make Container 101 consume no more than 500 MHz on any Hardware Node, run the following command: # prlctl set 101 --cpulimit 500m Note : For more information on setting CPU limits for virtual machines and Containers, see also CPU Limit Specifics . Using --cpus to set CPU limits
Another way of setting a CPU limit for a virtual machine or Container is to use the
# prlctl set 101 --cpus 2 To check that the CPU limit has been successfully set, you can execute the following command: # vzlist -o cpulimitM 101 CPUL_M 6000 As you can see, the CPU limit for Container 101 is now set to 6000 MHz (or 6 GHz).
Note:
To check the CPU limit set for a virtual machine, run the
Along with setting the CPU limit for a virtual machine or Container on the server, the
# prlctl exec 101 cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 15 model : 4 model name : Intel(R) Xeon(TM) CPU 3.00GHz stepping : 1 cpu MHz : 2993.581 cache size : 1024 KB ...
processor : 1 vendor_id : GenuineIntel cpu family : 15 model : 4 model name : Intel(R) Xeon(TM) CPU 3.00GHz stepping : 1 cpu MHz : 2993.581 cache size : 1024 KB ... Using --cpulimit and --cpus simultaneously
If you use both parameters (
# prlctl set 101 --cpus 2 # prlctl set 101 --cpulimit 2000m |
||||
|