How to check the pressure of a Linux system
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.
You should read it
- 12 best Linux server operating systems
- 10 reasons to switch to Linux right in 2012
- The new threat in Linux operating system can have 'incalculable' consequences.
- Why are Linux computers still important?
- Is Linux the operating system or the kernel?
- How to check your Linux version
- Linux Network Administration Test with Answers - Part 1
- How to install Solus Linux
May be interested
- What is blood pressure? What is normal blood pressure?the concept of blood pressure is quite familiar and is mentioned a lot in everyday life. however, many people are still quite vague about them. this article will answer for you what is the definition of blood pressure? and how much is blood pressure normal?
- How to use a professional car washerprofessional car wash machine also known as high-pressure car washer is often equipped with extreme pressure, ultra-durable pump, to meet the frequency of continuous car washing in the garage, spray conveyor, house workshop, .. to help users use high-pressure car washers properly, refer to quantrimang's article below.
- 10 things to keep in mind when switching to Linux mobile operating systembecause it is an important component of the android operating system (os), linux is still very important to the mobile world. however, while android uses the linux kernel, it is just a linux distribution, but linux for mobile devices offers a completely different experience. find out why using a linux mobile phone is a great option, as well as a downside when switching from your favorite mobile operating system to this operating system.
- How to use electric pressure cooker to ensure safety for the familyhow to use electric pressure cookers safely and effectively is not well known. the following article will tell you how to use electric pressure cooker properly. stay tuned!
- Buy the best blood pressure monitoryou are looking for a genuine blood pressure monitor, good price without knowing which brand to choose. so this article will introduce you to the top 5 popular blood pressure monitors most commonly used today.
- How to install Linux operating system on Macif you have a mac and want to explore a new open source operating system, check out the instructions on how to install linux on a mac below.
- How to check MAC address on Linuxthe steps to find and check mac address on windows and macos are quite simple. so what about on linux? what ways are there to check mac address on linux?
- Which type of pressure cooker, electronic pressure cooker should be purchased?if you are wondering if you should buy a pressure cooker or electric pressure cooker, see the article below to facilitate the cooking process.
- Instructions on how to measure blood pressure at homewrist blood pressure monitors or arm blood pressure monitors all have the same mechanism of self-pumping and flushing of the cuff, then returning the blood pressure readings to the screen. however, people who have not used a blood pressure monitor will never be surprised. to get accurate blood pressure readings, you can refer to the guide on how to measure blood pressure at home below.
- Monitor your blood pressure with selfie photos, why not?many of the sudden deaths caused by high blood pressure are preventable if diagnosed early.