Previous page

Next page

Locate page in Contents

Print this page

Configuring CPU Limits for Virtual Machines and Containers

CPU 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:

  • --cpulimit
  • --cpus

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 --cpulimit option with the prlctl set command. In the following example, Container 101 is set to receive no more than 25% of the server CPU time even if the CPUs on the server are not fully loaded:

# 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 --cpus option with the prlctl set command. You may want to use this command if your server has several CPU cores. In this case, you can specify the desired number of CPU cores after --cpus and the CPU limit will be set to the sum of CPU powers of the specified cores. For example, if a server has 4 CPU cores, 3 GHz each, you can allow Container 101 to consume no more than 6 GHz of CPU power by running this command:

# 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 prlctl list -i VM_Name command and check the value of the cpulimit parameter in the command output.

Along with setting the CPU limit for a virtual machine or Container on the server, the --cpus option also defines how the information on available CPUs is shown to users. So in the example above, if you log in to Container 101 and run the cat /proc/cpuinfo command, you will see that only 2 CPUs are installed in the Container:

# 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 ( --cpulimit and --cpus ) to set the CPU limit for a virtual machine or Container, the smallest limit applies. For example, running the following commands on a server with 4 CPUs, 2 GHZ each, will set the limit for Container 101 to 2 GB:

# prlctl set 101 --cpus 2

# prlctl set 101 --cpulimit 2000m