将某些进程限制为CPU%-Linux [英] Limiting certain processes to CPU % - Linux

查看:73
本文介绍了将某些进程限制为CPU%-Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:动态生成的某些进程趋向于消耗100%的CPU.我想将符合某个条件(例如进程名称)的所有进程限制为一定数量的CPU百分比.

I have the following problem: some processes, generated dynamically, have a tendency to eat 100% of CPU. I would like to limit all the process matching some criterion (e.g. process name) to a certain amount of CPU percentage.

我要解决的特定问题是利用folding @ home worker进程.我能想到的最好的解决方案是一个定期执行的perl脚本,该脚本使用cpulimit实用程序来限制进程(如果您对更多详细信息感兴趣,请检查此

The specific problem I'm trying to solve is harnessing folding@home worker processes. The best solution I could think of is a perl script that's executed periodically and uses the cpulimit utility to limit the processes (if you're interested in more details, check this blog post). It works, but it's a hack :/

有什么想法吗?我想将处理流程留给OS :)

Any ideas? I would like to leave the handling of processes to the OS :)

再次感谢您的建议,但我们仍然缺少要点:)

Thanks again for the suggestions, but we're still missing the point :)

"slowDown"解决方案实质上是"cpulimit"实用程序的工作.我仍然必须注意要减慢哪些进程,在工作进程完成后终止"slowDown"进程,并为新的工作进程启动新的进程.这正是我对Perl脚本和cron工作所做的事情.

The "slowDown" solution is essentially what the "cpulimit" utility does. I still have to take care about what processes to slow down, kill the "slowDown" process once the worker process is finished and start new ones for new worker processes. It's precisely what I did with the Perl script and a cron job.

主要问题是我事先不知道要限制什么过程.它们是动态生成的.

The main problem is that I don't know beforehand what processes to limit. They are generated dynamically.

也许有一种方法可以将一个用户的所有进程限制为一定数量的CPU百分比?我已经设置了一个执行执行folding @ home作业的用户,希望我可以使用/etc/security/limits.conf文件来限制他.但是我能得到的最接近的是每个用户的总CPU时间...

Maybe there's a way to limit all the processes of one user to a certain amount of CPU percentage? I already set up a user for executing the folding@home jobs, hoping that i could limit him with the /etc/security/limits.conf file. But the nearest I could get there is the total CPU time per user...

如果有什么可以让你说的话,那会很酷: 此用户进程的所有CPU%使用率的总和不能超过50%".然后让进程根据优先级争取那50%的CPU ...

It would be cool if to have something that enables you to say: "The sum of all CPU % usage of this user's processes cannot exceed 50%". And then let the processes fight for that 50% of CPU regarding to their priorities...

伙计们,谢谢您的建议,但这与优先级无关-即使有足够的CPU时间可用,我也想限制CPU%.这些进程的优先级已经很低,因此不会引起任何性能问题.

Guys, thanks for your suggestions, but it's not about priorities - I want to limit the CPU % even when there's plenty of CPU time available. The processes are already low priority, so they don't cause any performance issues.

我只是想防止CPU长时间以100%的速度运行...

I would just like to prevent the CPU from running on 100% for extended periods...

推荐答案

我在gzip上有一个类似的问题.

I had a slightly similar issue with gzip.

假设我们要减少gzip进程的CPU:

Assuming we want to decrease the CPU of a gzip process:

    gzip backup.tar & sleep 2 & cpulimit --limit 10 -e gzip -z

选项:

  • 我发现sleep很有用,因为cpulimit有时没有立即采用新的gzip流程
  • --limit 10gzip CPU使用率限制为10%
  • -zgzip进程完成时自动关闭cpulimit
  • I found sleep useful as the cpulimit sometimes didn't pick up the new gzip process immediately
  • --limit 10 limits gzip CPU usage to 10%
  • -z automatically closes cpulimit when gzip process finishes

另一种选择是运行cpulimit守护程序.

Another option is to run the cpulimit daemon.

这篇关于将某些进程限制为CPU%-Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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