CPU resource limit

The docker container will think that it can use all the CPU resources of the host. After starting the container, try to occupy a completed CPU core

docker run -it --name ubuntu ubuntu /bin/bash
while : ; do : ; done &

You can see that one of the four cores is 100US

We know that the docker – CPU shares parameter can control the percentage of CPU the container can occupy
For example, when a container is started separately, because there is no competition, even if – CPU shares = 500, the container can occupy all cores

To compete, we lock two containers on the first kernel and set the percentage

docker run -it --name test1 --cpu-shares=500 --cpuset-cpus 0 ubuntu /bin/bash

Mainly, there are two bash processes on the top at the bottom right, one is 66.4 and the other is 33.2

However – CPU shares can only control the percentage of usage, which is the only parameter provided by the early docker that can allocate CPU resources

This principle is the same as requests in kubernetes resources

If you want to implement limits in kubernetes resources, you need to use

  • cpu.cfs_quota_us
  • cpu.cfs_period_us

The default period is 100ms, or 100000 US. The following statement means that 100000 units of resources can be used, 20000, or 20%

docker run -it --name test1 --cpu-period=100000 --cpu-quota=20000 --cpuset-cpus 0 ubuntu /bin/bash

The bash process in the figure below is locked at 19.9%

Send a Message