Linux performance optimization (1)-stress stress test tool

1. Introduction to stress

1. Introduction to stress

Stress is a stress testing tool for Linux, which can perform stress testing on CPU, Memory, IO, and disk.

2. Stress installation

installation:
sudo yum install stress

Two, stress use

1. The stress command

stress [OPTION [ARG]]
-c, --cpu N: Generate N processes, and each process cyclically calls the sqrt function to generate CPU pressure.
-i, --io N: Generate N processes, each process cyclically calls sync to write the contents of the memory buffer to the disk, generating IO pressure. The system call sync refreshes the data in the memory buffer to the disk to ensure synchronization. If there is less data in the buffer, less data is written to the disk, and IO pressure will not be generated. This is especially obvious in the SSD disk environment. It is possible that iowait is always 0, but because a large number of calls to the system call sync, the system CPU usage rate sys increases.
-m, --vm N: spawn N processes, and each process calls malloc/free function to allocate and release memory in a loop.
    --vm-bytes B: Specify the size of the allocated memory
    --vm-stride B: Constantly assign values ​​to part of the memory to allow COW (Copy On Write) to occur
    --vm-hang N: Indicate that each memory-consuming process is allocated After reaching the memory, go to sleep for N seconds, then release the memory, and repeat this process
    --vm-keep: Always occupy memory, which is different from continuous release and reallocation (the default is to continuously release and reallocate memory)
-d, --hdd N: Generate N processes that continuously execute write and unlink functions (create files, write content, delete files)
    --hdd-bytes B: specify the file size
--hdd-noclean: do not write random ASCII data Unlink
-t, --timeout N: end the program after N seconds        
--backoff N: wait for N microseconds to start running
-q, --quiet: the program does not output information during the running process
-n, - dry-run: output what the program will do without actually performing related operations
--version: display the version number
-v, --verbose: display detailed information

2. CPU test

stress --cpu 2 --timeout 60
Start 2 CPU processes to perform sqrt calculation, which will end after 60 seconds
Linux performance optimization (1)-stress stress test tool

3. IO test

stress --io 2 --timeout 60s
Start 2 IO processes, execute the sync system call, flush the memory buffer to the disk, and
Linux performance optimization (1)-stress stress test tool
use stress cannot simulate the rise of iowait, but the rise of sys. The stress -i parameter indicates that the system calls sync to simulate IO problems, but sync refreshes the memory buffer data to the disk to ensure synchronization. If there is not much data in the memory buffer, there will not be much data read and written to the disk, and IO pressure cannot be generated. This is particularly obvious in the environment where SSD disks are used. iowait is always 0, but due to a large number of system calls, the system CPU usage rate sys increases.
stress --io 2 --hdd 2 --timeout 60s
Open 2 IO processes, 2 disk IO processes
Linux performance optimization (1)-stress stress test tool

4. Memory test

stress --vm 2 --vm-bytes 1G --vm-hang 100 --timeout 100s
Start 2 processes to allocate memory, allocate 1GB of memory each time, release it after 100 seconds, and exit after 100 seconds.
Linux performance optimization (1)-stress stress test tool

5. Disk IO test

stress --hdd 2 --hdd-bytes 10G --backoff 2000000
Start 2 disk IO processes, write 10GB data to disk each time
Linux performance optimization (1)-stress stress test tool

Three, stress test scenario

1. CPU-intensive processes

stress --cpu 2 --timeout 600
Simulate starting two CPU-intensive processes to
uptime
view the average load of the system, as follows:
Linux performance optimization (1)-stress stress test tool
mpstat -P ALL 5 1
view the CPU usage, as follows:
Linux performance optimization (1)-stress stress test tool
pidstat -u 5
view the process load, as follows:
Linux performance optimization (1)-stress stress test tool
(1) You can observe the higher average load of the system through uptime.
(2) Observed by mpstat that the user mode CPU usage of CPU0 and CPU2 is very high, and iowait is 0, indicating that the process is CPU-intensive. The intensive use of CPU by processes leads to higher average system load and higher CPU usage.
(3) You can use pidstat to check that the stress process causes high CPU usage.

2. IO-intensive processes

stress -i 1 --hdd 1 --timeout 600
Simulate a worker calling sync to flush the memory buffer and write to disk.
uptime
Check the average load of the system as follows:
Linux performance optimization (1)-stress stress test tool
mpstat -P ALL 5
Check the CPU usage as follows:
Linux performance optimization (1)-stress stress test tool
(1) It can be observed through uptime that the average load of the system is very high.
(2) Observed by mpstat that the kernel mode CPU usage is very low, but the iowait is very high, and it has been waiting for IO processing, indicating that the process is IO-intensive. Processes frequently perform IO operations, resulting in a high average system load and low CPU usage.

3. Wait for the CPU process

This machine has 4 logical CPUs, simulating 8 processes.
stress -c 8 --timeout 600
Simulate 8 CPU-intensive processes to
uptime
view the average load of the system, as follows:
Linux performance optimization (1)-stress stress test tool
mpstat -P ALL 5
View the CPU usage, as follows:
Linux performance optimization (1)-stress stress test tool
pidstat -u 5
View the CPU usage of the process, as follows:
Linux performance optimization (1)-stress stress test tool
(1) Observe that the average load of the system is high through uptime
(2) ) Observed by mpstat that the user mode CPU usage is very high, and iowait is 0, indicating that the process is CPU intensive or there is CPU contention between processes.
(3) The high wait index observed by pidstat indicates that there is CPU contention between processes, and there are a large number of processes in the system waiting to use the CPU.

4. Introduction to stress-ng

1. Introduction to stress-ng

Stress-ng is fully compatible with stress, and hundreds of optional parameters are added on the basis of stress to support the generation of various complex stresses.

2. Stress-ng installation

stress-ng source download:
https://kernel.ubuntu.com/~cking/tarballs/stress-ng/
compile:
make
install:
sudo make install

3. The stress-ng command

stress-ng [OPTION [ARG]]
stress-ng --cpu 2 --cpu-method pi
Generate 2 workers to do the pi algorithm Pressure
stress-ng --cpu 2 --cpu-method all
generate 2 workers iteratively use more than 30 different pressure algorithms, including pi, crc16, fft, etc.
stress-ng --sock 2
Generate 2 workers call socket related functions to generate pressure
stress-ng --tsc 2
generate 2 workers read tsc to generate pressure
stress-ng --sock 4 --taskset 0-1,3
strss- ng assign the pressure to the specified CPU

Guess you like

Origin blog.51cto.com/9291927/2593578