[Solved] Dynamically throttling CPU usage via command line in Linux?

If you're new to FAH and need help getting started or you have very basic questions, start here.

Moderators: Site Moderators, FAHC Science Team

Post Reply
darkextratoasty
Posts: 4
Joined: Wed Nov 08, 2023 6:53 pm

[Solved] Dynamically throttling CPU usage via command line in Linux?

Post by darkextratoasty »

Is there a scriptable command that can be used to adjust the total CPU usage that fah consumes? Either by adjusting the number of CPU cores that fah utilizes, or by adjusting a CPU usage cap? I'm looking to automate the total CPU usage of a system through scripting, and it would be very convenient if fah has some built in way of adjusting its usage.
Last edited by darkextratoasty on Wed Nov 08, 2023 9:20 pm, edited 1 time in total.
bikeaddict
Posts: 193
Joined: Sun May 03, 2020 1:20 am

Re: Dynamically throttling CPU usage via command line in Linux?

Post by bikeaddict »

The cpulimit command can restrict CPU use by percentage. It might also be possible using cgroups, but I haven't tested that.

Example to limit to 50% CPU on a 32-thread system:

Code: Select all

cpulimit -l 1600 -p $(pgrep FahCore_a)
darkextratoasty
Posts: 4
Joined: Wed Nov 08, 2023 6:53 pm

Re: Dynamically throttling CPU usage via command line in Linux?

Post by darkextratoasty »

Perfect, thank you for the help!
toTOW
Site Moderator
Posts: 6309
Joined: Sun Dec 02, 2007 10:38 am
Location: Bordeaux, France
Contact:

Re: [Solved] Dynamically throttling CPU usage via command line in Linux?

Post by toTOW »

Usually, the FAH compute core doesn't like when the number of threads is adjusted too often ... it increases the risk of loosing WUs.

It is also highly inefficient to run more working thread than available CPU threads ... :(
Image

Folding@Home beta tester since 2002. Folding Forum moderator since July 2008.
darkextratoasty
Posts: 4
Joined: Wed Nov 08, 2023 6:53 pm

Re: [Solved] Dynamically throttling CPU usage via command line in Linux?

Post by darkextratoasty »

toTOW wrote: Sat Nov 11, 2023 8:15 pm Usually, the FAH compute core doesn't like when the number of threads is adjusted too often ... it increases the risk of loosing WUs.
What would be considered 'too often'? Every 15 minutes, every hour, every 8 hours? Being about to dynamically adjust the workload is a hard requirement for me, so if doing so with fah is going to ruin my ability to complete WUs, I might have to find a different program to run.
toTOW wrote: Sat Nov 11, 2023 8:15 pm It is also highly inefficient to run more working thread than available CPU threads ... :(
Can you elaborate on this a bit more in relation to the 'cpulimit' command? Does the cpulimit command work by starting an stopping work threads and using it poses a risk of starting more work threads than there are CPU threads? I'm a bit lost as to where your comment connects to the topic at hand.
bikeaddict
Posts: 193
Joined: Sun May 03, 2020 1:20 am

Re: [Solved] Dynamically throttling CPU usage via command line in Linux?

Post by bikeaddict »

The github project's documentation describes how cpulimit works:

https://github.com/opsengine/cpulimit
The control of the used CPU amount is done sending SIGSTOP and SIGCONT POSIX signals to processes.
It seems to pause and resume the process for short intervals.
darkextratoasty
Posts: 4
Joined: Wed Nov 08, 2023 6:53 pm

Re: [Solved] Dynamically throttling CPU usage via command line in Linux?

Post by darkextratoasty »

So what exactly does that mean for my application? Does using the cpulimit command break fah or is it perfectly fine to use or...? Sorry I'm very new to all this and I don't really understand how any of this, aside from the first comment, is relevant.
bikeaddict
Posts: 193
Joined: Sun May 03, 2020 1:20 am

Re: [Solved] Dynamically throttling CPU usage via command line in Linux?

Post by bikeaddict »

I haven't used cpulimit on the folding app other than testing it briefly to see that is appeared to work as expected. So I don't know if it causes any problems with long term use. I think you should test it and report back. :wink:
miczac
Posts: 7
Joined: Wed Jan 03, 2024 5:44 am

Re: [Solved] Dynamically throttling CPU usage via command line in Linux?

Post by miczac »

On a side note you also could renice the FahCore_a process.
Something like

Code: Select all

renice 19 -p $(pgrep FahCore_a)
would give it lowest priority.
HTH, Michael.
Post Reply