Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to conduct stress test for Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how Linux carries on the stress test". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to conduct Linux stress test" can help you solve the problem.

Software stress testing is a basic quality assurance behavior, and it is a part of every important software testing work. The basic idea of software stress testing is very simple: not to run manual or automatic tests under normal conditions, but to run tests under the conditions of a small number of computers or lack of system resources. Resources that typically perform software stress testing include internal memory, CPU availability, disk space, and network bandwidth.

Make a cycle by yourself

The first technique is to run some loops on the command line to observe their impact on the system. This method can greatly increase the load of CPU. You can easily see the results using uptime or similar commands.

In the following command, we start four endless loops. You can increase the number of loops by adding numbers or using bash expressions such as {1. 6} instead of 1, 2, 3, 4:

For i in 1 2 34; do while:; do:; done & done

After you type on the command line, four endless loops are started in the background:

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

In this case, job 1-4 is initiated, and the job number and process number are displayed accordingly.

To observe the effect on the average load, use the command shown below. In this example, the uptime command runs every 30 seconds:

$while true; do uptime; sleep 30; done

If you plan to run such tests on a regular basis, you can put loop commands into the script watch-it.

#! / bin/bashwhile truedouptimesleep 30done

In the output, you can see how the average load increases, and then starts to fall again at the end of the cycle.

11:25:34 up 5 days, 17:27, 2 users, load average: 0.15, 0.14, 0.0811:26:04 up 5 days, 17:27, 2 users, load average: 0.09, 0.12, 0.0811:26:34 up 5 days, 17:28, 2 users, load average: 1.42, 0.43, 0.1811:27:04 up 5 days, 17:28, 2 users, load average: 2.50, 0.79 0.3111:27:34 up 5 days, 17:29, 2 users, load average: 3.09, 1.10, 0.4311:28:04 up 5 days, 17:29, 2 users, load average: 3.45, 1.38, 0.5411:28:34 up 5 days, 17:30, 2 users, load average: 3.67, 1.63, 0.6611:29:04 up 5 days, 17:30, 2 users, load average: 3.80, 1.86 0.7611:29:34 up 5 days, 17:31, 2 users, load average: 3.88, 2.06, 0.8711:30:04 up 5 days, 17:31, 2 users, load average: 3.93, 2.25, 0.9711:30:34 up 5 days, 17:32, 2 users, load average: 3.64, 2.35, 1.04

Because the displayed loads represent averages of 1, 5, and 15 minutes, it takes a while for these values to return to a near-normal state of the system.

To stop the loop, issue a kill command like this-- assuming the job number is 1-4, as shown earlier in this article. If you are not sure, you can use the jobs command to confirm the assignment number.

$kill 1 2 3 4 dedicated tools to increase stress

Another way is to use tools that specifically create system pressure for you. One of them is called stress (pressure), which can stress the system in a variety of ways. The stress tool is a workload generator that provides CPU, memory, and disk Imax O stress tests.

When using the-- cpu option, the stress command uses the square root function to force CPU to work hard. The more CPU you specify, the faster the load will rise.

The second script (watch-it-2) below can be used to measure the impact on system memory usage. Note that it uses the free command to see the effect of compression.

$cat watchit, talk, talk, purchase, bind, truedofreesleep 30done, while, while

Initiate tasks and observe stress:

$stress-- cpu 2 $. / watch-it13:09:14 up 5 days, 19:10, 2 users, load average: 0.00,0.00,0.0013 days 09 days 44 up 5 days, 19:11, 2 users, load average: 0.68,0.16,0.0513 up 5 days, 19:11, 2 users, load average: 1.20,0.34,0.121314 up 5 days, 1913 users, load average: 1.52,0.50 0.1813:11:14 up 5 days, 19:12, 2 users, load average: 1.71, 0.64, 0.2413:11:44 up 5 days, 19:13, 2 users, load average: 1.83, 0.77, 0.30

The more CPU you specify on the command line, the faster the load increases.

$stress-- cpu 4 $. / watch-it13:47:49 up 5 days, 19:49, 2 users, load average: 0.00,0.00,0.0013 48 days 19 up 5 days, 19:49, 2 users, load average: 1.58, 0.38, 0.1313 up 48 up 5 days, 19:50, 2 users, load average: 2.61,0.75, 0.2613 up 5 days, 1915 50, 2 users, load average: 3.16,1.06 0.3813:49:49 up 5 days, 19:51, 2 users, load average: 3.49, 1.34, 0.5013:50:19 up 5 days, 19:51, 2 users, load average: 3.69, 1.60, 0.61

The stress command can also put pressure on the system by increasing the load on Icano and memory with the-- io (input / output) and-- vm (memory) options.

In the next example, run the command that increases the memory pressure, and then start the watch-it-2 script.

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

Another option for stress is to use the-- io option to add input / output activities to the system. In this case, you can use the following command:

$stress-- io 4

Then you can use iotop to observe the compressed I _ map O. Note that root permission is required to run iotop.

Before:

$sudo iotop-oTotal DISK READ: 0.00 Bjbd2/sda1 s | Total DISK WRITE: 19.36 K/sCurrent DISK READ: 0.00BUnip s | Current DISK WRITE: 27.10 K/sTID PRIO USER DISK READ DISK WRITE SWAPIN IO > COMMAND269308 be/4 root 0.00BUnip s 0.00 BUnip 0.00% 1.24% [kworker~fficient] 283 be/3 root 0.00BUnip s 19.36K Universe 0.00% 0.26% [jbd2/sda1-8]

After that:

Total DISK READ: 0.00Bash s | Total DISK WRITE: 0.00 B/sCurrent DISK READ: 0.00Barcs | Current DISK WRITE: 0.00 B/sTID PRIO USER DISK READ DISK WRITE SWAPIN IO > COMMAND270983 be/4 shs 0.00BUnip s 0.00BUnip s 0.00% 51.45% stress-- io 4270984 be/4 shs 0.00BUnip s 0.00% stress-- io 4270985 be/4 shs 0.00Barcs 0. 00 stress 0.00% 50.95% stress-- io 4270982 be/4 shs 0.00 B be/4 root 0.00 B be/4 root 0.00% 50.80% stress-0.00 B be/4 root 0.00% 0.09% [kworker~fficient]

Stress is just one of several tools to put pressure on the system.

This is the end of the introduction to "how Linux conducts stress testing". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report