Jmeter (51) - From entry to advanced mastery - jmeter's mobile warfare (detailed tutorial)

1 Introduction

Mobile warfare is a military combat method that relies on a larger combat space to buy time to move troops to surround the enemy and use superior forces to achieve a quick victory. The application of mobile warfare can be summarized in this paragraph: "Avoid the enemy's main force, lure the enemy deep, and concentrate superior forces. Defeat them one by one." Today, Brother Hong also acted as a general, commanding jmeter to destroy the enemy in motion. Okay, let’s stop talking and get back to the topic. Today we will mainly explain and share: changing the load of jmeter while jmeter is running.

2. Change the load of jmeter while running

From the text, we can easily see that the meaning is to modify the load pressure of jmeter without stopping the running script during the jmeter test to achieve our expected test results. The general steps are: Hong Ge will complete jmeter's mobile battle through a combination of Constant Throughput Time (throughput timer), a function and BeanShell server. Specific steps are as follows:

2.1 Create test script

1. Create a test plan and add a thread group. In order to easily observe load changes later, Brother Hong sets the thread group to forever. As shown below:

If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and distributed by various channels. Master technical communication: 798478386    

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. Why interface automation is needed, 2. Overall view of request for interface automation, 3. Interface practice for interface automation, etc. For more exciting videos from UP master, please follow the UP account . icon-default.png?t=N7T8https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337 

2. Add a sampler. The sampler settings are as shown in the figure below:

 3. Add Constant Throughput Time (throughput timer). Remember that this counter is under Du Niang. The settings (the function used is __P) are as shown below:

4. Finally add monitors: View Results Tree, Graph Results and jp@gc - Bytes Throughput Over Time. As shown below:

2.2BeanShell server

Use JMeter Beanshell as the server in order to issue Beanshell commands. We update the previously defined "hits" parameter by calling the beanshell function. Beanshell is a Java source code interpreter built into JMeter.

1. Uncomment the following line on jmeter.properties (around 908). You can also open the file Ctrl+F to quickly find BeanShell and locate it, as shown in the following figure:

 2. Restart jmeter and enter in the docs command window: Netstat -an | find "9000"  command to view the port running status, as shown in the following figure:

At the same time, you can also see the started port on the jmeter startup page, as shown in the figure below: 

3. Create the folder bsh in the JMeter home directory, and add a .bsh file named update_parameter.bsh, which contains the following content: setprop("hits",args[0]);   as shown in the figure below:

picture

 4. Enter the cmd command in the home directory of jmeter to enter the docs command window, as shown in the following figure:

 5. Execute  dir bash\    as shown below:

 6. File calling the setprop function to update "hits" with the value in the first argument (args[0]) is now able to call the created .bsh to update "hits" while the test is running. Update the parameters to "1200" requests per minute through the following command in jmeter's home directory:

java -jar .\lib\bshclient.jar localhost 9000 .\bsh\update_parameter.bsh 1200

7. Because it started with 1200, now 0 is updated to 120, as shown in the figure below:

8. After running for a period of time, Hongge updates from 120 to 1200, as shown in the figure below:

 9. Observe the throughput during operation. There are obvious changes. Does it show a U-shape (horseshoe shape)? Because the throughput set by Hongge was 1200 at the beginning. After running for a period of time, dynamically change it to 120 through the command, and then restart After running for a period of time, it is dynamically modified to 1200 through the command, so it becomes U-shaped as shown in the figure. If you change it to 120, it will form a V shape immediately after changing it to 1200. As shown below:

3. Summary

 My friends may not see the effect after following the steps. In fact, I didn't even see it the first time I ran it. After a round of troubleshooting, there is no problem. What exactly is the problem? The expected results are not achieved. Then after changing the number of users in the thread group to 10, the expected effect appeared. I guess it may be that for one user, the throughput of 120 is enough, so the change from 1200 to 120 and then to 1200 is basically a straight line. There is nothing. Variety. If you know the underlying principles or if something is wrong, you can tell me or point it out and I will correct it in time.

 

Guess you like

Origin blog.csdn.net/Faith_Lzt/article/details/133309490