0

The programme cpulimit on Linux is great. You can tell it to limit a process so that it doesn't use more than X% of the CPU. For example, I know someone who's laptop overheats if the CPU runs too hot for too long. When doing some video encoding, they use cpulimit to prevent the CPU being fully used, and hence overheating. You can't use nice to stop that.

Is there something like that for the load?

Ideally I'd like to be able to do loadlimit 4 my-command-here and it will start my-command-here and every X sec loadlimit will check the (1 minute) load of the machine, and if it's above 4, then my-command-here will be paused. When the load goes below 4, the command will be paused. This is exactly what cpulimit does BTW.

Does such a tool exist?

Amandasaurus
  • 31,471
  • 65
  • 192
  • 253
  • Can you fix the root cause of your load issues? – ewwhite Nov 09 '16 at 13:15
  • System load average and CPU utilization are two completely different things, so I don't see how what you want is "exactly what cpulimit does". System load average (as reported e.g. by uptime on GNU) is simply the number of processes in a runnable or running state, plus on Linux also those in noninterruptible sleep. See https://en.wikipedia.org/wiki/Load_(computing)#Unix-style_load_calculation and [man 3 getloadavg](https://linux.die.net/man/3/getloadavg). – user Nov 09 '16 at 13:40
  • @MichaelKjörling I know load is different from CPU. When I said "the same as cpulimit" I meant "monitor the load, and then pause this process until the load gets below X" – Amandasaurus Nov 09 '16 at 14:45
  • @ewwhite In /this/ case the load is caused by me `rm -rf` on a massive directory structure, which degrades my desktop's performance. In /this/ case, I want to do a "slow" rm -rf so that I can delete the directory without affecting my desktop performance. – Amandasaurus Nov 09 '16 at 14:47
  • Not an answer because not enough time, but cgroups can do this, if you combine it with the freeze provider. – mzhaase Nov 09 '16 at 15:32

1 Answers1

1

With what you describe in the comments, it would seem that your actual problem could be solved by ionice.

ionice -c 3 -p <pid>

where -p <pid> is the pid of process you want to reschedule and -c 3 puts it into the idle class so it only gets disk time if no one else wants it. On a busy system, that can make the process in question slow, so you could experiment with different values for the priority in a higher class, e.g.

ionice -c 2 -n 6 -p <pid> 

Read man ionice for more details.

The problem with your proposed loadlimit would be that a high load can be caused by very different things and slowing one process wouldn't necessarily impact the load at all.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • Although `ionice rm -rf ..` does seem to help a little, it still increases my load and I can see some general slowdown. – Amandasaurus Nov 09 '16 at 15:47