Internally, OpenVZ sets the CPU limit for virtual machines and containers in percent. On multi-core systems, each logical CPU core is considered to have the CPU power of 100%. So if a server has 4 CPU cores, the total CPU power of the server equals 400%.
You can also set a CPU limit in megahertz (MHz). If you specify the limit in MHz, OpenVZ uses the following formula to convert the CPU power of the server from MHz into percent: CPULIMIT_% = 100% * CPULIMIT_MHz / CPUFREQ
, where
-
CPULIMIT_%
is the total CPU power of the server in percent. -
CPULIMIT_MHz
is the total CPU power of the server in megahertz. -
CPUFREQ
is the CPU frequency of one core on the server.
When setting CPU limits, note the following:
- Make sure that the CPU limit you plan to set for a virtual machine or container does not exceed the total CPU power of the server. So if a server has 4 CPUs, 1000 MHz each, do not set the CPU limit to more than 4000 MHz.
- The processes running in a virtual machine or container are scheduled for execution on all server CPUs in equal shares. For example, if a server has 4 CPUs, 1000 MHz each, and you set the CPU limit for a virtual machine or container to 2000 MHz, the virtual machine or container will consume 500 MHz from each CPU.
- All running virtual machines and containers on a server cannot simultaneously consume more CPU power than is physically available on the node. In other words, if the total CPU power of the server is 4000 MHz, the running virtual machines and containers on this server will not be able to consume more than 4000 MHz, irrespective of their CPU limits. It is, however, perfectly normal that the overall CPU limit of all virtual machines and containers exceeds the Node total CPU power because most of the time virtual machines and containers consume only part of the CPU power assigned to them.