【问题标题】:Setting absolute limits on CPU for Docker containers为 Docker 容器设置 CPU 的绝对限制
【发布时间】:2014-12-08 12:56:09
【问题描述】:

我正在尝试对 Docker 容器 CPU 使用设置绝对限制。 CPU 共享概念 (docker run -c <shares>) 是相对的,但我想说“让这个容器每 100 毫秒最多使用 20 毫秒的 CPU 时间。我能找到的最接近的答案是 hint from the mailing list 使用 cpu.cfs_quota_uscpu.cfs_period_us。使用docker run时如何使用这些设置?

我对 LXC 支持的 Docker(例如 pre0.9)或更高版本没有严格要求,只需要查看正在使用的这些设置的示例——任何指向相关文档或有用博客的链接都非常有用同样欢迎。我目前使用的是 Ubuntu 12.04,在 /sys/fs/cgroup/cpu/docker 下我看到了这些选项:

$ 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 cpu-usage scheduler lxc cgroups


    【解决方案1】:

    我相信我已经完成了这项工作。我不得不用--exec-driver=lxc 重新启动我的Docker 守护进程,因为我 找不到将 cgroup 参数传递给 libcontainer 的方法。这种方法对我有用:

    # Run with absolute limit
    sudo docker run --lxc-conf="lxc.cgroup.cpu.cfs_quota_us=50000" -it ubuntu bash
    

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

    我用sysbench简单确认了一下,这似乎确实引入了一个绝对限制,如下图:

    $ 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
    

    【讨论】:

      猜你喜欢
      • 2021-03-29
      • 2020-12-18
      • 1970-01-01
      • 2022-11-02
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      相关资源
      最近更新 更多