Setting absolute limits on CPU for Docker containers

后端 未结 1 1628
轻奢々
轻奢々 2020-12-15 13:46

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

相关标签:
1条回答
  • 2020-12-15 14:22

    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
    
    0 讨论(0)
提交回复
热议问题