Setting absolute limits on CPU for Docker containers Setting absolute limits on CPU for Docker containers docker docker

Setting absolute limits on CPU for Docker containers


I believe I've gotten this working. I had to restart my Docker daemon with --exec-driver=lxc as Icould not find a way to pass cgroup arguments to libcontainer. This approach worked for me:

# Run with absolute limitsudo 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 bashroot@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 bashroot@302e651c0686:/# sysbench --test=cpu --num-threads=1 run   <snip>     total time:                          45.0423s