linux - systemd中CPUQuota的使用

标签 linux limit cpu fedora systemd

我正在尝试对 dd 命令的 CPU 使用率设置一个硬性限制。我创建了以下单元文件

[Unit]
Description=Virtual Distributed Ethernet

[Service]
ExecStart=/usr/bin/ddcommand
CPUQuota=10%

[Install]
WantedBy=multi-user.target

调用下面的简单脚本

#!/bin/sh
dd if=/dev/zero of=/dev/null bs=1024k

正如我在本指南中所见: http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html 我的 dd 服务的 CPU 使用率不应超过 10%。但是当我运行 system-cgtop 命令时,使用率约为 70-75%。

关于我做错了什么以及如何解决它有什么想法吗?

附:当我执行 systemctl show dd 时,我得到以下关于 CPU 的结果

CPUShares=18446744073709551615
StartupCPUShares=18446744073709551615
CPUQuotaPerSecUSec=100ms
LimitCPU=18446744073709551615

最佳答案

我不小心遇到了在 https://unix.stackexchange.com/questions/213903/linux-cgroups-limit-cpu-usage-in-absolute-values-which-do-not-depend-on-cpu-spe 上给出的另一个有效答案

如果你想对 CPU 带宽进行硬性限制,可以使用 cpu.cfs_quota_us 和 cpu.cfs_period_us。来自内核的 CFS 文档:

组允许的带宽是使用配额和期限指定的。在每个给定的“周期”(微秒)内,一个组最多只能消耗“quota”微秒的 CPU 时间。当一个组的 CPU 带宽消耗超过此限制(在那个时期)时,属于其层次结构的任务将被限制,直到下一个时期才允许再次运行。

关于linux - systemd中CPUQuota的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29667758/

相关文章:

linux - 如何在相同的环境下生成新的 xterm

linux - notify-send -i 图标的条件

limit - Iptables 限制每个连接的时间

cpu - echo $$>尝试使用cpuset时,任务会给出 "no space left on device"

Python - 核心速度

linux - bash linux - 从标准输入和标准输出写入和读取

python - 阻塞套接字并选择

mysql - SQL 中的排序依据/限制执行

azure - 如何限制每个节点附加托管磁盘的 Pod 数量

cpu - Vultr 虚拟 CPU 与 DigitalOcean Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz