I\'m trying to set absolute limits on Docker container CPU usage. The CPU shares concept (docker run -c
) is relative, but I would like to say som
I believe I've gotten this working. I had to restart my Docker daemon with --exec-driver=lxc
as I
could not find a way to pass cgroup arguments to libcontainer
. This approach worked for me:
# Run with absolute limit
sudo docker run --lxc-conf="lxc.cgroup.cpu.cfs_quota_us=50000" -it ubuntu bash
The necessary CFS docs on bandwidth limiting are here.
I briefly confirmed with sysbench that this does seem to introduce an absolute limit, as shown below:
$ sudo docker run --lxc-conf="lxc.cgroup.cpu.cfs_quota_us=10000" --lxc-conf="lxc.cgroup.cpu.cfs_period_us=50000" -it ubuntu bash
root@302e651c0686:/# sysbench --test=cpu --num-threads=1 run
<snip>
total time: 90.5450s
$ sudo docker run --lxc-conf="lxc.cgroup.cpu.cfs_quota_us=20000" --lxc-conf="lxc.cgroup.cpu.cfs_period_us=50000" -it ubuntu bash
root@302e651c0686:/# sysbench --test=cpu --num-threads=1 run
<snip>
total time: 45.0423s