Ограничить ЦП / ОЗУ во всем процессе для Debian

906
heailraiser

Всякий раз, когда я запускаю задачи с интенсивным использованием ЦП / ОЗУ, я не могу использовать свой компьютер, он зависает, пока задача не будет завершена. Я искал способ ограничить ресурсы на процесс для всех процессов.

т.е. ни один из процессов не проходит выше 25% ЦП или 3 ГБ ОЗУ.

Спасибо

0
Я так понимаю, вы находитесь на одноядерном процессоре? Frank Thomas 8 лет назад 0
четырехъядерный процессор i3 heailraiser 8 лет назад 0
В этом случае одна занятая задача не должна блокировать другие потоки / процессы, и даже если задача была в значительной степени многопоточной, временные интервалы linux между активными процессами (с использованием планировщика), таким образом, каждый получает свой ход. Приоритеты для процессов определяются тем, что называется любезностью, что может быть лучшим решением для вашей проблемы. Я рекомендую вам хорошо выглядеть и хорошо выглядеть. Тем не менее, поведение, которое вы описываете, касается меня тем, что я не уверен, что проблема заключается в использовании процессора как таковой. Если вы хотите ограничить произвольные процессы, посмотрите на http://www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/ Frank Thomas 8 лет назад 0

1 ответ на вопрос

1
txtechhelp

Limiting all processes to an arbitrary limit might not be as beneficial as you might initially think.

As a comment pointed out, you can limit the CPU, but depending on the process, you might better be served by simply setting the nice-ness of the process (also known as process priority). Doing this will allow the process to run at full speed when you're just reading a site and not using any CPU, but yield and give way to your browser once it needs to start utilizing the CPU(s) for any JavaScript (as an example).

Another option is to set the CPU affinity of the process. This lets the OS only run the process on one specific CPU core, leaving the other 3 (in your case) free for anything else that might need it. This is nice when your process is a single-threaded process (like a video encoding process or source building process, for example); you can set the affinity to the 1st CPU core and you've got 3 others at idle (until used that is).

And there's also ulimit, which you can use to set soft and hard limits or RAM/CPU (though this is system wide and not per process).

It should be noted that limiting your RAM might have unintended consequences (like swap usage), and instead you should try the nice value, CPU affinity or ulimit for CPU time before limiting the RAM. RAM is not like CPU in that more usage of it will degrade overall system performance; on the contrary, system performance tends to increase when more RAM can be used and you should only notice a performance decrease if swap area has to be used over RAM (since swap is usually disk based and orders of magnitude slower than RAM), and if you notice a lot of swap area being used with a bunch of free RAM, then there's something else going on that needs to be addressed (like a kernel setting).

Hope that can help.

Похожие вопросы