关于linux运维:Linux系统使用cpulimit对CPU使用率进行限制

4次阅读

共计 1132 个字符,预计需要花费 3 分钟才能阅读完成。

介绍

cpulimit 是一个限度过程的 CPU 使用率的工具(以百分比示意,而不是以 CPU 工夫示意)。

当不心愿批处理作业占用太多 CPU 时,管制批处理作业很有用。

指标是避免过程运行超过指定的工夫比率。

它不会更改 nice 值或其余调度优先级设置,而是更改实在的 CPU 使用率,而且可能动静且疾速地适应整个零碎负载。

应用的 CPU 数量的管制是通过向过程发送 SIGSTOP 和 SIGCONT POSIX 信号来实现的。指定过程的所有子过程和线程将共享雷同百分比的 CPU。

源装置【举荐】

Centos:

yum install cpulimit

Debian / Ubuntu:

apt-get install -y cpulimit`

编译装置

cd /tmp
wget 'https://sunpma.com/other/oss/cpulimit-1.1.tar.gz'
tar cpulimit-1.1.tar.gz
cd cpulimit-1.1
make
cp cpulimit  /usr/local/sbin/
rm -rf cpulimit*

应用实例

限度程序名为 xmrig 的程序仅应用 60% 的 CPU 使用率,并在后盾始终运行;

cpulimit -e xmrig -l 60 -b

限度过程号为 10086 的程序仅应用 60% 的 CPU 利用率,并在后盾始终运行;

cpulimit -p 10086 -l 60 -b

限度绝对路径下的软件仅应用 60% 的 CPU 利用率,并在后盾始终运行;

cpulimit -e /usr/local/nginx/sbin/nginx -l 60 -b

敞开 cpulimit 后盾过程(勾销所有限度)

kill $(pidof cpulimit)

应用办法

-p –pid=N pid of the process 过程的 PID
-e –exe=FILE name of the executable program file 可执行程序文件名
-P –path=PATH absolute path name of the 过程的绝对路径名
-b –background run in background 后盾运行
-l –limit=N percentage of cpu allowed from 1 up 容许的 CPU 百分比,最低为 1%
-z –lazy exit if there is no suitable target process 如果指标过程退出或无指标过程则终止
-h –help display this help and exit 显示帮忙并退出

注意事项

  • 限度 CPU 的百分比依照理论的 CPU 数量而定,比方单核最高为 100%,双核最高为 200%,三核最高为 300%,以此类推即可;
  • ROOT 用户能够限度所有的过程,普通用户只能限度用户有权限治理的过程;

以上就是 cpulimit 这个小工具的一些根底用法和进阶用法,心愿对大家有所帮忙。

正文完
 0