3

I'm calling cpulimit from cron:

00 16 * * * /usr/bin/cpulimit --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh

When the job kicks off, the CPU spikes and alerts as it always has, with no actual identifiable limit having taken place. The job itself iterates over a directory of many subdirectories and performs rsync's each time, which I believe is spawning rsync child processes (running top will have a pid available for the called rsync, which after a few minutes will have a different pid for rsync).

I'm unsure how to properly utilize cpulimit to effectively limit the usage this process consumes.

It might be important to keep in mind this is a VM with 2G RAM and 1vCPU.

6

By default cpulimit doesn't limit child processes, so the rsync is not being limited at all. If you are running a recent enough version of cpulimit you should be able to use the --include-children (or -i) option. (See also this answer.)

$ cpulimit -h
Usage: cpulimit [OPTIONS...] TARGET
   OPTIONS
      -l, --limit=N          percentage of cpu allowed from 0 to 400 (required)
      -v, --verbose          show control statistics
      -z, --lazy             exit if there is no target process, or if it dies
      -i, --include-children limit also the children processes
      -h, --help             display this help and exit
   TARGET must be exactly one of these:
      -p, --pid=N            pid of the process (implies -z)
      -e, --exe=FILE         name of the executable program file or path name
      COMMAND [ARGS]         run this command and limit it (implies -z)

Report bugs to <marlonx80@hotmail.com>.

That would change your cron entry to:

00 16 * * * /usr/bin/cpulimit --include-children --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh

EDIT: As the OP answered (themselves) it would work to cpulimit to the rsync commands within the script, but that would not ensure that your script is being nice while it is doing other functions. For example, if the script has to process a massive directory, it could bog down the system and cause a CPU spike and alert.

1
  • 2
    I believe that it is -m, --monitor-forks instead of -i in some versions.
    – Skybbles
    Feb 20 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.