5

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

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

If I run the two containers in this way:

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 got that C1 takes 100% of cpu1 as expected but 50% of cpu2 (instead of 20%), C2 takes 100% of cpu3 as expected and 50% of cpu2 (instead of 80%).

It looks like the --cpu-shares option is ignored. Is there a way to obtain the behavior I'm looking for?

1 Answers1

1

docker run mentions that 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)"

So those values are not %-based.

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

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

(those values are validated/checked only since docker 1.9.1 with PR 16159)

Note: there is also CPU quota constraint:

The --cpu-quota flag limits the container’s CPU usage. The default 0 value allows the container to take 100% of a CPU resource (1 CPU).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I know, I used 20 and 80 to simplify the scenario. Because I have only two containers that need both 100% of cpu (stress) with shares set to 20 and 80 they should run at 20% and 80% respectively on the shared cpu (cpu2). Of course I could have used something like 4 and 16 or 80 and 320. – Giovanni Quattrocchi Jan 08 '16 at 12:49
  • No, I mean those values might not be recognized. Try 200 and 800 to see if that works better. – VonC Jan 08 '16 at 12:51
  • @GiovanniQuattrocchi and if you reverse the values? (800 and 200 instead of 200 and 800) – VonC Jan 08 '16 at 15:03
  • I don't know why but if use cpuset-cpus=0,1 for C1 and cpuset-cpus=1,2 for C2 i got the expected behavior... – Giovanni Quattrocchi Jan 08 '16 at 16:59
  • @GiovanniQuattrocchi What version of docker are you using? – VonC Jan 11 '16 at 07:25