背景:

测试活动中,需要构造cpu打满、磁盘打满、网卡打满的场景

场景1:cpu打满

环境信息:

虚拟机,物理核数16个,每个物理核的虚拟核数1个,虚拟核数16个:

[root@vm10-0-0-8 test_data]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
16
[root@vm10-0-0-8 test_data]# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores : 1
[root@vm10-0-0-8 test_data]# cat /proc/cpuinfo| grep "processor"| wc -l
16

top命令查看到当前cpu 占用率:

[root@vm10-0-0-8 test_data]# top
top - 21:20:02 up 16 days, 6:07, 6 users, load average: 10.29, 8.05, 3.80
Tasks: 198 total, 1 running, 197 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 32778624 total, 18760920 free, 701276 used, 13316428 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 31481428 avail Mem

%Cpu(s):

0.0 us,用户占用率(没有nice调度过)

0.1 sy,系统占用率

0.0 ni,用户空间通过nice调度过的程序cpu占用率

99.9 id,idle,空闲率

0.0 wa, 0.0 hi, 0.0 si, 0.0 st

构造cpu打满的场景:

[root@vm10-0-0-8 test_data]# cat while_1.sh 
#!/bin/bash function while_1()
{     while ((1));
    do
        i=2;
    done
} while_1 &

执行while_1.sh后,发现cpu中1个core被打满了:

[root@vm10-0-0-8 test_data]# sh while_1.sh
[root@vm10-0-0-8 test_data]#
[root@vm10-0-0-8 test_data]# ps -ef |grep while_1.sh
root 21553 1 99 21:29 pts/4 00:00:03 sh while_1.sh [root@vm10-0-0-8 test_data]# top
top - 21:29:54 up 16 days, 6:17, 6 users, load average: 1.17, 4.11, 3.58
Tasks: 196 total, 2 running, 194 sleeping, 0 stopped, 0 zombie
%Cpu(s): 4.5 us, 1.7 sy, 0.0 ni, 93.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 32778624 total, 18763900 free, 698328 used, 13316396 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 31484616 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21553 root 20 0 113176 392 200 R 100.0 0.0 0:20.97 sh

将16个core都打满:

[root@vm10-0-0-8 test_data]# cat run_while.sh
#!/bin/bash function while_1()
{
while ((1));
do
i=2;
done
} function run_while()
{
for ((i=0; i<$1; i++));
do
while_1 &
done
} run_while $1
[root@vm10-0-0-8 test_data]# sh run_while.sh 16    (16是core的数,可自定义)
[root@vm10-0-0-8 test_data]# ps -ef |grep while
root 21751 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21752 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21753 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21754 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21755 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21756 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21757 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21758 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21759 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21760 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21761 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21762 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21763 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21764 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21765 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16
root 21766 1 99 21:31 pts/4 00:00:55 sh run_while.sh 16

查看cpu占用清空,idle为零了:

[root@vm10-0-0-8 test_data]# top
top - 21:33:55 up 16 days, 6:21, 6 users, load average: 14.08, 7.45, 4.85
Tasks: 211 total, 17 running, 194 sleeping, 0 stopped, 0 zombie
%Cpu(s): 73.3 us, 26.7 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 32778624 total, 18758856 free, 702964 used, 13316804 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 31479616 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21761 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21751 root 20 0 113176 388 196 R 100.0 0.0 2:05.11 sh
21752 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21753 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21754 root 20 0 113176 388 196 R 100.0 0.0 2:05.12 sh
21756 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21758 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21759 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21760 root 20 0 113176 388 196 R 100.0 0.0 2:05.13 sh
21762 root 20 0 113176 388 196 R 100.0 0.0 2:05.12 sh
21764 root 20 0 113176 388 192 R 100.0 0.0 2:05.10 sh
21766 root 20 0 113176 388 192 R 100.0 0.0 2:05.13 sh
21755 root 20 0 113176 388 196 R 100.0 0.0 2:05.11 sh
21757 root 20 0 113176 388 196 R 100.0 0.0 2:05.10 sh
21763 root 20 0 113176 388 192 R 100.0 0.0 2:05.11 sh
21765 root 20 0 113176 388 192 R 100.0 0.0 2:05.04 sh

TODO:如何模拟cpu打满,磁盘打满,网卡打满的更多相关文章

  1. MySQL ibdata1撑爆占满磁盘空间

    MySQL主从由于ibdata1占满磁盘空间-->主从失效 因为设置了innodb_file_per_table = 1,ibdata1依旧撑爆占满磁盘空间 主从断的时候,IO线程在连接,SQL ...

  2. jenkins log文件突然占满磁盘空间

    今天早上同事反应jenkins构建job发生异常,于是登录机器查看发现磁盘空间已满.进一步排查之后发现jenkins的catalina.out文件已占满磁盘空间. 用tail看了下日志后面都是关于DN ...

  3. python之psutil模块(获取系统性能信息(CPU,内存,磁盘,网络)

    一.psutil模块 1. psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...

  4. ubuntu16系统磁盘空间/dev/vda1占用满的问题

    参考文档: https://www.cnblogs.com/moonandstar08/p/6091507.html (系统磁盘空间/dev/xvda1占满原因分析) https://blog.csd ...

  5. centos7-java模拟cpu占用高及排查

    环境 centos7 1核2GB Java8 模拟cpu占用高 新建一个名为jvm-learn的springboot项目 模拟代码如下 import org.springframework.boot. ...

  6. WPF 动态模拟CPU 使用率曲线图

    原文:WPF 动态模拟CPU 使用率曲线图      在工作中经常会遇到需要将一组数据绘制成曲线图的情况,最简单的方法是将数据导入Excel,然后使用绘图功能手动生成曲线图.但是如果基础数据频繁更改, ...

  7. CENTOS7-JAVA模拟CPU占用高及排查( 转)

    环境 centos7 1核2GB Java8 模拟cpu占用高 新建一个名为jvm-learn的springboot项目 模拟代码如下 import org.springframework.boot. ...

  8. linux下模拟CPU占用100%小程序

    在做一个测试时,需要模拟服务器CPU占用满的情况,在查阅相关资料后,发现网上程序不太好用, 原文在这:http://www.2cto.com/os/201304/202068.html 优化后如下: ...

  9. windows系统c盘占满/linux系统磁盘block、inode占满处理

    windows系统 下载c盘清理.bat到服务器,双击bat文件将自动清理 linux系统 先远程ssh登录上服务器,登录教程:http://www.west263.com/faq/list.asp? ...

随机推荐

  1. 如何在Idea中使用Git将项目代码上传到码云

    参考链接:https://blog.csdn.net/zzybbh/article/details/88172140

  2. JAVA中级开发应该掌握的小知识点

    一.悲观锁.乐观锁的区别: 悲观锁:一段执行逻辑加上悲观锁,不同线程同时执行,只有一个线程可以执行,其他线程在入口处等待,直到锁被释放.乐观锁:一段执行逻辑加上乐观锁,不同线程同时执行,可以同时进入执 ...

  3. opencv —— 同时识别三种颜色

    要点: 1.识别一种颜色 minH = ; //色相 maxH = ; minS = ; //饱和度 maxS = ; minV = ; // inRange(原图像, 最小值的范围, 最大值的范围, ...

  4. maven的核心概念——创建war工程

    第十七章第四个Maven工程(war工程) 17.1 创建步骤 ①第一步:创建maven web工程 ②第二步:修改web.xml <?xml version="1.0" e ...

  5. XSY2666

    题意 有\(n\)种颜色的球,第i种有\(a_i\)个.设\(m=\sum a_i\).你要把这\(m\)个小球排成一排.有\(q\)个询问,每次给你一个\(x\),问你有多少种方案使得相邻的小球同色 ...

  6. Pr常用的键盘操作

    Pr常用的键盘操作 Shift选中切开的小段 Alt复制效果

  7. TCP 协议快被淘汰了,UDP 协议才是新世代的未来?

    TCP 协议可以说是今天互联网的基石,作为可靠的传输协议,在今天几乎所有的数据都会通过 TCP 协议传输,然而 TCP 在设计之初没有考虑到现今复杂的网络环境,当你在地铁上或者火车上被断断续续的网络折 ...

  8. 谷歌F12获取接口信息

  9. Linux网络课程学习第四天

    课程内容包括:管道符.重定向与环境变量. 学习心得:个人感觉本章节还是不太好理解,尤其是对自己的基础还不是特别的扎实课余时间还是要反复的复习.

  10. 关于SkinTextBox中SkinTxt的事件使用

    SkinTxt的事件中的事件不能像一般的事件那样在属性中直接双击生成,它里面的事件都需要进行一定的转换间接使用,具体用法如下: 1.手动编写事件需要做的操作的方法 public void txtCod ...