gpt4 book ai didi

docker - 如何设置Docker容器的CPU优先级(niceness)?

转载 作者:行者123 更新时间:2023-12-02 05:51:07 27 4
gpt4 key购买 nike

我的一个容器总是很忙,并且正在从其他需要响应且仅不时处于事件状态的容器(网络服务器)中占用 CPU。

我想降低CPU消耗容器的CPU优先级,这样每当其他容器需要CPU时,它就不会被阻塞。

我该怎么做?我在网上搜索了一段时间,但找不到答案。

我尝试使用 --entrypoint='nice 10 mybinary' 运行容器,但结果 --entrypoint 只能运行二进制文件,而不能运行 shell 命令。

最佳答案

您可以在容器级别限制 CPU 资源。我建议针对您的情况使用 --cpu-shares 512

https://docs.docker.com/config/containers/resource_constraints/ :

Set this flag to a value greater or less than the default of 1024 to increase or reduce the container’s weight, and give it access to a greater or lesser proportion of the host machine’s CPU cycles. This is only enforced when CPU cycles are constrained. When plenty of CPU cycles are available, all containers use as much CPU as they need. In that way, this is a soft limit. --cpu-shares does not prevent containers from being scheduled in swarm mode. It prioritizes container CPU resources for the available CPU cycles. It does not guarantee or reserve any specific CPU access.

关于docker - 如何设置Docker容器的CPU优先级(niceness)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54392310/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com