背景:

测试活动中,需要构造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. 利用 serviceStack 搭建web服务器

    1,资料地址 参考资料 https://docs.servicestack.net/ https://docs.servicestack.net/create-your-first-webservic ...

  2. javaSE学习笔记(15) ---缓冲流、转换流、序列化流

    javaSE学习笔记(15) ---缓冲流.转换流.序列化流 缓冲流 昨天复习了基本的一些流,作为IO流的入门,今天我们要见识一些更强大的流.比如能够高效读写的缓冲流,能够转换编码的转换流,能够持久化 ...

  3. 剑指offer-面试题55-平衡二叉树-递归

    /* 题目: 判断二叉树是否为平衡二叉树. */ /* 思路: 判断二叉树的左子树和右子树高度相差是否为1. */ #include<iostream> #include<cstri ...

  4. Python函数进阶:闭包、装饰器、生成器、协程

    返回目录 本篇索引 (1)闭包 (2)装饰器 (3)生成器 (4)协程 (1)闭包 闭包(closure)是很多现代编程语言都有的特点,像C++.Java.JavaScript等都实现或部分实现了闭包 ...

  5. python全栈学习 day03

    换行符: \n 制表符: \t 字符串截取:顾头不顾尾 s[首:尾:步长] 首--->尾走向 和 步长方向一致 s[0:4:2] s[4:0:-2] a = "qwertyui&quo ...

  6. CF1299D Around the World

    题意 \(n\)阶无向图,\(m\)条带权边,保证\(1\)不会被"超过\(3\)阶的圈"所包含.求删除与\(1\)相邻的边集,使得不存在从\(1\)出发的权值为\(0\)的非平凡 ...

  7. 在mac下初次使用pygame踩坑纪实(卡死)

    初次使用pygame实现绘图功能就踩坑 直接上代码 import pygame pygame.init() # 创建游戏的窗口 480 * 700screen = pygame.display.set ...

  8. python递归删除目录本身以及目录下文件

    import os def local_rm(dirpath): if os.path.exists(dirpath): files = os.listdir(dirpath) for file in ...

  9. Tiptop ERP 采购运费一键分摊

    项目背景: 公司的采购运费在逐年上升,之前财务都是做在管理费用中,金额大了后已经严重造成成本失真,所以财务要求it部能帮助分摊运费   1.纸质单据 2.系统入库单apmt720 3.系统请款单apm ...

  10. 大话STM32F103系统架构

    前言 许多像我一样的STM32初学者,都往往忽视了STM32系统架构的学习.这对于实际应用并没有啥大的影响,但是总感觉怎么学也无法看清STM32的全貌,所以本文我将带领大家一起厘清STM32F103的 ...