为Docker容器设置CPU的绝对限制 [英] Setting absolute limits on CPU for Docker containers

查看:873
本文介绍了为Docker容器设置CPU的绝对限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置Docker容器CPU使用的绝对限制。 CPU共享概念( docker run -c< shares> )是相对的,但我想说一句让这个容器每次使用最多20ms的CPU时间100ms最接近的答案是邮件列表中的提示使用 cpu.cfs_quota_us cpu.cfs_period_us 。使用<$ c $时如何使用这些设置c> docker运行?

I'm trying to set absolute limits on Docker container CPU usage. The CPU shares concept (docker run -c <shares>) is relative, but I would like to say something like "let this container use at most 20ms of CPU time every 100ms. The closest answer I can find is a hint from the mailing list on using cpu.cfs_quota_us and cpu.cfs_period_us. How does one use these settings when using docker run?

我没有对LXC支持的Docker(例如pre0.9)或更高版本的严格要求,只需要看到这些设置被使用的例子 - 任何链接到相关文档或有帮助的博客也是非常受欢迎的我正在使用Ubuntu 12.04,在 / sys / fs / cgroup / cpu / docker 我看到这些选项:

I don't have a strict requirement for either LXC-backed Docker (e.g. pre0.9) or later versions, just need to see an example of these settings being used--any links to relevant documentation or helpful blogs are very welcome too. I am currently using Ubuntu 12.04, and under /sys/fs/cgroup/cpu/docker I see these options:

$ ls /sys/fs/cgroup/cpu/docker
cgroup.clone_children  cpu.cfs_quota_us   cpu.stat
cgroup.event_control   cpu.rt_period_us   notify_on_release
cgroup.procs           cpu.rt_runtime_us  tasks
cpu.cfs_period_us      cpu.shares


推荐答案

我相信我已经有了这个工作。我不得不重新启动我的Docker守护进程与 - exec-driver = lxc ,因为
找不到一个方法来传递cgroup参数到$ code> libcontainer 。这个方法对我有用:

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

有关带宽限制的必要CFS文档是 here

The necessary CFS docs on bandwidth limiting are here.

我简要地通过sysbench证实这似乎引入了绝对限制,如下所示:

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

这篇关于为Docker容器设置CPU的绝对限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆