Methods for CPU, Memory, Disk IO, and Network Stress Testing on Linux

In embedded environments such as Linux/Android, relevant tools (some of which need to be ported) can be used to perform stress testing processes for related projects to determine stability and other results. Below are the relevant stress testing items and command usage instructions:CPU1. stressThe stress tool is a CPU, Memory, Disk IO, and load testing tool that provides users with specified CPU, memory, and disk test result reports and detected error information.To test the device, open two terminals. In one terminal, execute the following test commands:1) Create 8 CPU processes, stress for 600 seconds, allowing the CPU to be at 100% user mode load.

stress --cpu 8 --timeout 600

2) Create 100 IO processes, stress for 600 seconds, allowing the CPU to be at 100% kernel mode load.

stress --io 100 --timeout 600

3) Create 8 CPU and 100 IO processes, stress for 600 seconds, allowing the CPU to reach a total usage of 100% in both user and kernel modes.

stress -c 8 -i 100 --verbose --timeout 600

In the other terminal, execute the following command to view the CPU resource load during the above test commands:

mpstat -P ALL 2

2. dd commandLet the CPU continuously dump data from /dev/zero to /dev/null, which can also achieve CPU stress testing effects, with the following command:

i=`cat /proc/cpuinfo |grep processor |wc -l` && seq $i|xargs -P $i -I {} bash -c 'echo 'CPU' {} 'running' && dd if=/dev/zero of=/dev/null'

Similarly, you can execute the commandmpstat -P ALL 2in another terminal to check the CPU resource usage.Memory1. stressSimilarly, the stress tool can be used to stress test memory, with the following command help information:

When testing memory with stress, the parameters –vm-bytes 1G and –vm-hang 100 are key.

–vm-bytes indicates how much memory to allocate with malloc.

–vm-hang indicates how long to hold the allocated memory before releasing it with free().

–vm specifies the number of processes, with the total allocated memory being vm * vm-bytes.

–timeout indicates the duration.

Based on the help information, we use the following command to create 5 processes that allocate memory with malloc for 100 seconds before releasing it:

stress --vm 5 --vm-bytes 1G --vm-hang 100 --timeout 100s

2. ramfs file systemIn a Linux environment, you can also use the ramfs file system to operate memory, which utilizes VFS to implement a memory file system stored in Page Cache, and the following operations can be performed to write to memory and occupy its space:

mkdir /tmp/memmount -t ramfs ramfs /tmp/mem/
dd if=/dev/zero of=/tmp/mem/file bs=1024k count=2048
umount /tmp/mem/rmdir /tmp/mem/

Disk IO1. stressSimilarly, stress can also be used to stress test disk IO performance, with the following help information:

-d, –hdd forks creates multiple processes executing the write() function.

–hdd-bytes bytes specifies the number of bytes to write, default is 1GB.

Thus, we use the following command to create 2 processes that write fixed-size data to the current directory using the mkstemp() function, and you can also specify the corresponding file on the disk, which is also generated using mkstemp(). By default, the generated files are ultimately cleared using unlink:

stress --hdd 2 --hdd-bytes 3G --timeout 200

2. fiofio is a tool for testing disk bandwidth and IOPS, commonly used for hard disk stress testing, supporting IO engines such as: sync, mmap, libaio, posixaio, SG v3, splice, null, network, syslet, guasi, solarisaio, etc.1) Sequential write

fio -filename=test_file -direct=1 -iodepth 1 -thread -rw=write -ioengine=libaio -bs=64k -size=1G -numjobs=10 -runtime=60 -group_reporting -name=mytest

2) Sequential read

fio -filename=test_file -direct=1 -iodepth 1 -thread -rw=read -ioengine=libaio -bs=64k -size=1G -numjobs=10 -runtime=60 -group_reporting -name=mytest

3) Random write

fio -filename=test_file -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=10 -runtime=60 -group_reporting -name=mytest

4) Random read

fio -filename=test_file -direct=1 -iodepth 1 -thread -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=10 -runtime=60 -group_reporting -name=mytest

5) Mixed random read/write

fio -filename=test_file -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=libaio -bs=4k -size=200m -numjobs=10 -runtime=60 -group_reporting -name=mytest

6) Mixed read/write

fio -filename=test_file -direct=1 -iodepth 1 -thread -rw=rw -rwmixread=70 -ioengine=libaio -bs=4k -size=200m -numjobs=10 -runtime=60 -group_reporting -name=mytest

NetworkThe iperf or iperf3 tool is used to test the network performance of TCP or UDP protocols, testing network throughput with the following test examples:1. Server

iperf -u -s

Use the above command to start the UDP server; if the -u parameter is not added, it defaults to TCP protocol, and -s indicates it is the server.2. Client (in this example, 192.168.30.115 is the server IP address)1) Under UDP protocol, test a 100Mbps sending rate, client to server upstream bandwidth test, duration 60 seconds.

iperf -u -c 192.168.30.115 -b 100M -t 60 -i 2

2) Under UDP protocol, establish 2 connection threads, each with a sending rate of 2Mbps, for 10 seconds.

iperf -u -c 192.168.30.115 -i 1 -t 10 -b 2M -P 2

3) Under UDP protocol, test a sending rate of 1000Mbps for upstream and downstream bandwidth, duration 60 seconds, displaying results every second.

iperf -u -c 192.168.30.115 -b 1000M -d -t 60 -i 1

After the stress test ends, there will be similar printed results:

[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams[  3]  0.0-35.9 sec   449 MBytes   105 Mbits/sec   0.008 ms    0/320339 (0%)

It presents the time period, amount of data transferred, bandwidth rate, delay, packet loss and total number of packets, and packet loss rate.

Leave a Comment