我从cron打电话给D1:
00 16 * * * /usr/bin/cpulimit --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh
当作业开始时,CPU会像往常一样发出尖峰和警报,没有实际的可识别的限制发生。作业本身遍历一个由许多子目录组成的目录,每次执行rsync's操作,我认为这是生成rsync子进程(运行top将为被调用的rsync提供一个pid,几分钟后,rsync将有一个不同的pid )。
我不知道如何正确地利用cpulimit来有效地限制这个过程所消耗的使用量。
记住这是一个带有2GRAM和1vCPU的VM,这一点可能很重要。
发布于 2019-11-27 17:16:36
默认情况下,cpulimit不限制子进程,因此rsync完全不受限制。如果您正在运行一个最新版本的cpulimit,您应该能够使用--include-children (或-i)选项。(另见这个答案。)
$ 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 .将您的cron条目更改为:
00 16 * * * /usr/bin/cpulimit --include-children --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh
编辑:正如OP自己回答的那样,它将对脚本中的cpulimit命令进行rsync操作,但这并不能确保脚本在执行其他功能时表现得很好。例如,如果脚本必须处理一个庞大的目录,它可能会使系统陷入瘫痪,并导致CPU尖峰和警报。
https://unix.stackexchange.com/questions/554459
复制相似问题