How to check the pressure of a Linux system

Testing pressure on Linux servers is a good idea if you want to see if they work well. In this post, TipsMake introduces some tools that can help you add pressure to the system to test and evaluate results.

Stress testing Linux servers is a good idea if you want to see if they are working properly.

Why increase the pressure on Linux systems?

This is because sometimes you may want to know how a system will perform when under a lot of pressure from a large number of running processes, large network traffic, excessive memory usage, etc. This test can help ensure that a system is ready for general use.

Manual loop

The first way consists of running some loops on the command line and see how they affect the system. This technique burdens the CPU by downloading a lot of data. Results can easily be seen using uptime or similar commands.

In the command below, four non-ending loops are started. You can increase the number of loops by adding numbers or using the bash expression like {1.6} instead of "1 2 3 4".

for i in 1 2 3 4; do while : ; do : ; done & done

Enter the command line, this command will start four endless loops on the system platform.

$ for i in 1 2 3 4; do while : ; do : ; done & done [1] 205012 [2] 205013 [3] 205014 [4] 205015

In this case, session 1-4 has been started. Both session number and process ID are displayed.

To observe the effect above average load, use the command shown below. In this case, the uptime command is run every 30 seconds:

$ while true; do uptime; sleep 30; done

If you plan to run the test periodically, you can set the loop command as follows:

#!/bin/bash while true do uptime sleep 30 done

In the output, you can see the load average increase and then begin to decrease as the loops have ended.

 11:25:34 up 5 days, 17:27, 2 users, load average: 0.15, 0.14, 0.08 11:26:04 up 5 days, 17:27, 2 users, load average: 0.09, 0.12, 0.08 11:26:34 up 5 days, 17:28, 2 users, load average: 1.42, 0.43, 0.18 11:27:04 up 5 days, 17:28, 2 users, load average: 2.50, 0.79, 0.31 11:27:34 up 5 days, 17:29, 2 users, load average: 3.09, 1.10, 0.43 11:28:04 up 5 days, 17:29, 2 users, load average: 3.45, 1.38, 0.54 11:28:34 up 5 days, 17:30, 2 users, load average: 3.67, 1.63, 0.66 11:29:04 up 5 days, 17:30, 2 users, load average: 3.80, 1.86, 0.76 11:29:34 up 5 days, 17:31, 2 users, load average: 3.88, 2.06, 0.87 11:30:04 up 5 days, 17:31, 2 users, load average: 3.93, 2.25, 0.97 11:30:34 up 5 days, 17:32, 2 users, load average: 3.64, 2.35, 1.04 <== loops 11:31:04 up 5 days, 17:32, 2 users, load average: 2.20, 2.13, 1.01 stopped 11:31:34 up 5 days, 17:33, 2 users, load average: 1.40, 1.94, 0.98

Because the load is averaged over 1, 5 and 15 minutes, the values ​​will take a while to return to normal for the system.

To stop the loop, issue the kill command as shown below - assume the number of sessions is 1-4 as above. If you are unsure, use the jobs command to verify the session ID.

$ kill %1 %2 %3 %4

Dedicated tool to add pressure to the system

Another way to create related system pressure is to use a tool built to add pressure to the system for you. One of these is called 'stress' and can add system pressure in a number of ways. The pressure addition tool is a session volume builder that provides I / O pressure tests of the CPU, memory and disk.

With the --cpu option, the stress command uses the square root function to force the CPU to work harder. The higher the number of CPUs specified, the faster the load will increase.

The watch-it-2 command can be used to evaluate the efficiency of system memory usage. Note that it uses the free command to view pressure feedback.

$ cat watch-it-2 #!/bin/bash while true do free sleep 30 done

Start monitoring system pressure:

$ stress --cpu 2
$ ./watch-it 13:09:14 up 5 days, 19:10, 2 users, load average: 0.00, 0.00, 0.00 13:09:44 up 5 days, 19:11, 2 users, load average: 0.68, 0.16, 0.05 13:10:14 up 5 days, 19:11, 2 users, load average: 1.20, 0.34, 0.12 13:10:44 up 5 days, 19:12, 2 users, load average: 1.52, 0.50, 0.18 13:11:14 up 5 days, 19:12, 2 users, load average: 1.71, 0.64, 0.24 13:11:44 up 5 days, 19:13, 2 users, load average: 1.83, 0.77, 0.30

The more CPUs specified on the command line, the faster it loads.

$ stress --cpu 4 $ ./watch-it 13:47:49 up 5 days, 19:49, 2 users, load average: 0.00, 0.00, 0.00 13:48:19 up 5 days, 19:49, 2 users, load average: 1.58, 0.38, 0.13 13:48:49 up 5 days, 19:50, 2 users, load average: 2.61, 0.75, 0.26 13:49:19 up 5 days, 19:50, 2 users, load average: 3.16, 1.06, 0.38 13:49:49 up 5 days, 19:51, 2 users, load average: 3.49, 1.34, 0.50 13:50:19 up 5 days, 19:51, 2 users, load average: 3.69, 1.60, 0.61

The stress command can also exert pressure on the system by adding I / O and loading memory with the --io (input / output) and --vm (memory) options.

For example, this command adds the memory pressure to be run, and then uses watch-it-2 to get started:

$ stress --vm 2
$ watch-it-2 total used free shared buff/cache available Mem: 6087064 662160 2519164 8868 2905740 5117548 Swap: 2097148 0 2097148 total used free shared buff/cache available Mem: 6087064 803464 2377832 8864 2905768 4976248 Swap: 2097148 0 2097148 total used free shared buff/cache available Mem: 6087064 968512 2212772 8864 2905780 4811200 Swap: 2097148 0 2097148

Alternatively, you can use the --io option to add input / output operations to the system. In this case, use the command:

$ stress --io 4

You can then observe the IO pressure level with iodine. Note iotop requires root access.

before

$ sudo iotop -o Total DISK READ: 0.00 B/s | Total DISK WRITE: 19.36 K/s Current DISK READ: 0.00 B/s | Current DISK WRITE: 27.10 K/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 269308 be/4 root 0.00 B/s 0.00 B/s 0.00 % 1.24 % [kworker~fficient] 283 be/3 root 0.00 B/s 19.36 K/s 0.00 % 0.26 % [jbd2/sda1-8]

after

Total DISK READ: 0.00 B/s | Total DISK WRITE: 0.00 B/s Current DISK READ: 0.00 B/s | Current DISK WRITE: 0.00 B/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 270983 be/4 shs 0.00 B/s 0.00 B/s 0.00 % 51.45 % stress --io 4 270984 be/4 shs 0.00 B/s 0.00 B/s 0.00 % 51.36 % stress --io 4 270985 be/4 shs 0.00 B/s 0.00 B/s 0.00 % 50.95 % stress --io 4 270982 be/4 shs 0.00 B/s 0.00 B/s 0.00 % 50.80 % stress --io 4 269308 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.09 % [kworker~fficient]

summary

System pressure testing tools will help you know how the operating system will react in real life situations.

4 ★ | 2 Vote