好的
你的解决方案是正确的,实际上应该是非常适合未来的;通过使用systemd来控制服务cgroup设置,例如. cpuQota.
[Unit]
Description=Virtual Distributed Ethernet
[Service]
ExecStart=/usr/bin/ddcommand
cpuQuota=10%
[Install]
WantedBy=multi-user.target
有关systemd中更有用的cgroup设置,请参阅man systemd.resource-control.
坏
虽然有两点需要注意,我(可能还有其他几个)会对此进行讨论.这些警告很难追查,因为似乎没有太多容易找到的信息,这是这个答案的主要原因.
警告1:
* The CFS cpu quota cgroup attribute is now exposed for
services. The new cpuQuota= switch has been added for this
which takes a percentage value. Setting this will have the
result that a service may never get more cpu time than the
specified percentage,even if the machine is otherwise idle.
这是Debian Jessie的一个问题,它只附带systemd 208.作为替代方案,可以使用cgroup-bin包中的cgcreate和cgset手动配置cpu.cfs_period_us和cpu.cfs_quota_us,例如.
sudo cgcreate -g cpu:/cpulimited
sudo cgset -r cpu.cfs_period_us=50000 cpulimited
sudo cgset -r cpu.cfs_quota_us=10000 cpulimited
sudo cgexec -g cpu:cpulimited /usr/bin/ddcommand
警告2
对于可用的设置cpu.cfs_period_us和cpu.cfs_quota_us,需要使用config-flag CONFIG_CFS_BANDWIDTH编译内核.遗憾的是,默认情况下,Debian Jessie的3.16.x内核未使用此标志进行编译,请参阅此feature request.
这将在Debian Stretch中提供.也可以使用jessie-backports中的内核,它应该启用标志.
我希望这个答案能帮助一些与我有同样问题的人……
PS:在您的环境中测试更好的cpuquota的简单方法是:
$apt-get install stress
$systemd-run -p cpuQuota=25% --slice stress --cpu
并且使用顶部或顶部观察,负载应该(均匀地)分布在所有cpus /核心上,总计高达25%.
替代
作为替代工具,可以使用cpu-limit,这应该在大多数发行版中可用,例如.
$apt-get install cpulimit
$cpulimit -l 10 -P /usr/bin/ddcommand
它的工作原理是将SIGSTOP和SIGCONT发送到附加命令以暂停和恢复其操作.
AFAIK难以同时控制多个独立/独立的流程,在类似的组中它们在一起,但也可能有解决方案……