背景:

测试活动中,需要构造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. 汇桔网被曝拖欠12月份工资至今,强制买产品,CEO称去年交易额超400亿

    三言财经消息,近日有汇桔网员工爆料,汇桔网拖欠12月工资至今,通知延迟到4月才发放. 此外爆料还指出,"各种手法逼迫大家离开,员工要么继续忍受,要么主动离职,要么停薪留职.都不同意只能仲裁. ...

  2. java script 内置对象

    java script 内置对象 Date 日期对象 字符串对象 定义字符串的方法就是直接赋值 使用 String 对象的 toUpperCase() 方法来将字符串小写字母转换为大写,反之 toLo ...

  3. mysql第八课

    开启事务: START TRANSACTION; 提交事务: COMMIT; 回滚事务: ROLLBACK; 事务的概念:原子性,一致性,隔离性,持久性 READ UNCOMMITTED(读了未提交) ...

  4. chorme输入框autocomplete(移动端)

    输入框自动填充密码即使是type是text也别填充,尝试了 https://developer.mozilla.org/zh-CN/docs/Web/Security/Securing_your_si ...

  5. JAVA类变量、类方法

    类变量(static) 类变量是该类的所有对象共享的变量,任何一个该类的对象去访问它时,取到的都是相同的值,同样任何一个该类的对象去修改它时,修改的也是同一个变量. public class C { ...

  6. 【笔记】机器学习 - 李宏毅 - 10 - Tips for Training DNN

    神经网络的表现 在Training Set上表现不好 ----> 可能陷入局部最优 在Testing Set上表现不好 -----> Overfitting 过拟合 虽然在机器学习中,很容 ...

  7. php ftp 使用 以及 php_connect_nonb() failed: Operation now in progress (115)

    设置 ftp_pasv($conn,true);  会出现下面错误   不设置 调用ftp 连接没问题  ftp_nlist  ftp_put ftp_get 等函数都不成功 ftp_nb_fput( ...

  8. JS:JS中常见的 “函数名 is not a function” 错误

    js中常见的错误,例如Uncaught TypeError: x is not a function 其原因除了函数本身有错之外,还有一种很奇怪的情况:函数本身没有错,但是运行时就是不能正常运行.这种 ...

  9. Mac下安装MySQL8的问题

    黑苹果用了一段时间之后,发现很多方面用起来比Windows还舒服些,没什么具体指标,就是纯粹一种感觉. 所以,慢慢将很多程序都迁移过来,在迁移过程中发现的一些有意思的事儿,我都把他们记录下来.如果,不 ...

  10. PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)

    Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...