Mixing cpu stocks and cpuset-cpus in Docker

I would like to run two containers with the following resource allocation:

  • Container "C1": cpu1 reserved, shared cpu2 with 20 cpu-share.
  • Container "C2": cpu3 reserved, shared cpu2 with 80 cpu-share.

If I run two containers as follows:

docker run -d --name='C1' --cpu-shares=20 --cpuset-cpus="1,2" progrium/stress --cpu 2 docker run -d --name='C2' --cpu-shares=80 --cpuset-cpus="2,3" progrium/stress --cpu 2 

I realized that C1 accepts 100% cpu1 as expected, but 50% cpu2 (instead of 20%), C2 accepts 100% cpu3 as expected, and 50% cpu2 (instead of 80%).

It seems that the -cpu-shares option is ignored. Is there a way to get the behavior I'm looking for?

+5
source share
1 answer

docker run mentions this parameter as:

 --cpu-shares=0 CPU shares (relative weight) 

And contrib/completion/zsh/_docker#L452 includes:

 "($help)--cpu-shares=[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" 

Thus, these values ​​are not based on%.

OP mentions --cpu-shares=20/80 works with the following Cpuset restrictions :

  docker run -ti --cpuset-cpus="0,1" C1 # instead of 1,2 docker run -ti --cpuset-cpus="3,4" C2 # instead of 2,3 

(these values ​​are checked / marked only from docker 1.9.1 with PR 16159 )

Note: There is also a CPU quota limit :

The --cpu-quota flag limits the use of CPU containers. The default value of 0 allows the container to accept 100% of the CPU resource (1 processor).

+1
source

Source: https://habr.com/ru/post/1240164/


All Articles