New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Are there any way to limit CPU of long running task on Linux?
Hi,
I am managing some servers running Debian. Sometime there are long-running, CPU hogging tasks that eat a lot of CPU so the server becomes unresponsive. Currently, I have to login to the server and manually limit those tasks by nice or cpulimit. I want to ask if there are any script or software that can automatically do the work for me so I can have more free time for beer? Any suggestions are highly appreciated.
Comments
LXC/LXD
Sorry for not mentioning that the processes should be run directly without containers.
Both are in Debian. I see you already mention the 1st one and want some automation, the 2nd tool seems to provide that.
Or alternatively maybe just consider running those tasks at a lower priority (e.g.
nice -+19 <programname>
), so they can have all the CPU they want, but can never interfere with other tasks for it.The easiest way is Docker, I know you said you do not want to run them as containers but Docker has some options to share the system resources:
https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities
A container is not a virtual machine, and can be provided with access to all system resources, so I do not know what the limitation would be, and why not use a container.
There is also here some information on cgroups:
https://www.linuxjournal.com/content/everything-you-need-know-about-linux-containers-part-i-linux-control-groups-and-process
Debian/Ubuntu:
apt-get install cpulimit
CentOS:
yum install epel-release
yum install cpulimit
Gee it's so useful you explain him how to install something he already uses...
Poor @levnode - every answer is something he's already tried :-(
There are batch management solutions that manage resources, but I haven't seen a FOSS one.
You may be able to create a poor man's renicer. A script like this which runs out of cron every 5 minutes:
Here is an example I googled:
https://www.refining-linux.org/archives/64-Programmatically-limit-CPU-usage-of-certain-processes.html
Are they started by SystemD? If so, just set a cpuquota/nice in the service definition.
Exactly, you got me. Thank you so much, your link is a very useful suggestion. I will try to rewrite it to fit my need and share it here if I got success.