1

shell 修改系统cpu使用率

 1 year ago
source link: https://blog.51cto.com/u_13236892/5978827
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

shell 修改系统cpu使用率

精选 原创
问题:
部分机器cpu使用率太低,无法申请新资源

解决思路:
通过启动新进程来提高cpu使用率,但是进程只占据一颗cpu,如果CPU核数较多,得多启动几个进程
nohup dd if=/dev/zero of=/dev/null & #此进程会占据一颗cpu,并且会将占据的cpu使用率提升到百分百
1、配置好ansible的hosts

2、检测配置
ansible all -m ping -i hosts

3、使用单个ip测试
ansible 192.168.10.131 -m shell -a "nohup dd if=/dev/zero of=/dev/null &" -i hosts
#执行完去对应机器使用top查看一下

4、批量执行
ansible all -m shell -a "nohup dd if=/dev/zero of=/dev/null &" -i hosts
#如果cpu核数比较多,需要多执行几次,多个进程占据多颗cpu

5、查询cpu使用率
ansible all -m shell -a "top -n1|grep Cpu" -i hosts

三、附录限制CPU使用率

前面的方法虽然能提高cpu使用率,但是无法控制单颗cpu使用率的大小
用cpulimit限定进程占用上限
1、安装cpumit
下载cpulimit-master
https://github.com/opsengine/cpulimit/archive/master.zip
unzip cpulimit-master.zip
cd cpulimit-master
make
cp src/cpulimit /usr/bin
2、不间断复制,提高占用率到100%
nohup dd if=/dev/zero of=/dev/null &
3、限制该进程的cpu使用率
①使用top查看进程号
②限定最高占用率,nohup cpulimit -l 60 -p 39425 &,-l后限定最高占用百分比,-p后是进程PID
③再次执行top命令,CPU占用率已经稳定在60%
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK