zoukankan      html  css  js  c++  java
  • TODO:如何模拟cpu打满,磁盘打满,网卡打满

    背景:

        测试活动中,需要构造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 
    
    大道至简
  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    算法の序列
  • 原文地址:https://www.cnblogs.com/liurong07/p/11853061.html
Copyright © 2011-2022 走看看