The most detailed in the whole network, Jmeter performance test-distributed stress test environment construction (super detailed)


foreword

JMeter was originally designed for performance testing. At the same time, it is relatively mature in implementing calls to various interfaces. Therefore, it is often used for interface function testing and performance testing.

It can well support various common interfaces, such as HTTP(S), WebService, JDBC, FTP, etc., and display test results in various forms.

When JMeter performs pressure measurement, the single machine is limited by memory, CPU, and network IO. We found that when the tested interface requires a high amount of concurrency, or some interfaces have a high number of accesses, it is easy to cause the local port to be fully occupied, and a request error occurs.

Jmeter distributed execution principle

When JMeter is executed in a distributed manner, one of them is selected as the scheduling machine (master), and the other machines are used as the execution machine (slave);

The master will edit the jmx pressure test script locally. When executing, the master will send the jmx script to the slave. The slave does not need to start jmeter when executing, but only needs to open the jmeter-sever.bat file to execute it in a non-GUI form;

After the slave is executed, the result is sent back to the master, and the master summarizes the results;

Simply speaking, the effect that can be achieved is: for example, if the number of threads set up in the JMeter jmx script is 100, 100 requests will be generated when running on a local stand-alone machine. If there is 1 master machine and 2 slave machines, then the total number of requests sent to the server each time is 100*3 times.

Environment construction method

Environment preparation
master: JMeter version 5.1.1, jdk version 1.8;
slave: another test machine, JMeter version 5.1.1, jdk version 1.8;

Note: The JMeter and jdk versions are consistent with the master, otherwise some unexpected problems may occur. The specific installation tutorial will not be repeated here.

Master machine configuration
To ensure the effective distribution of test scripts by the master machine, it is necessary to configure the ip address and port number of the slave machine. Under the bin file of the master installation directory, open Jmeter/bin/jmeter.properties, find the value of remote_hosts=127.0.0.1 and modify it:

Please add a picture description

PS: If there are multiple remote machines that need to be added, separate them with commas. The preceding 127.0.0.1 is the local machine, and the default port is 1099 (customizable)

parameterized configuration

The parameter file must be an absolute path, otherwise the parameter configuration file cannot be found when the script is executed, because the master scheduler will not distribute the corresponding parameter file in the script when distributing the jmx script. Therefore, you need to manually distribute the parameter file to the slave machine (and put it in the corresponding location under the absolute path, otherwise the slave will not find the file)

Please add a picture description

Configuration of the slave machine

The slave installs jdk and JMeter, and configures environment variables. Try to keep the version consistent with the master machine. The installation path of JMeter on the two slave machines is also consistent, which is convenient for subsequent parameterized configuration;

On the Slave machine, find the Jmeter/bin/jmeter.properties setting: server_port=1099;

Please add a picture description

In the bin directory of the slave, execute jmeter-server.bat to start the JMeter service;

Please add a picture description

Verify that the distributed environment is successfully built

Start the GUI interface of JMeter in the master machine, and you can see the configured slave machine in the Run-Remote Start option, which means that the remote slave machine has been connected.

Please add a picture description

If your environment does not report an error after you choose to start all, and the number of requests initiated is consistent with the number of threads set by jmx in advance, it means that the JMeter distributed test environment is successfully built and you can start testing.

Problems and Precautions

The master and slave must be in the same network segment;
close the firewall;
when the master starts the remote machine, it prompts FileNotFoundException;

Reason: Since JMeter 4.0, the default transport mechanism of RMI will use ssl protocol. The ssl protocol requires keys and certificates to work.

Solution: In Jmeter/bin/jmeter.properties, find server.rmi.ssl.disable, and set: server.rmi.ssl.disable=true, indicating that ssl is not used. Both master and salve have to be modified.
Please add a picture description

The setting of the number of threads;

The final number of concurrent threads = the number of concurrency set by the jmx script * the number of salve machines

JMeter distributed testing distributes execution scripts to machines through network connections, that is, the scripts obtained by each execution machine are independent and will execute the concurrency number set in jmx.

The use of a synchronous timer;
the function of this timer is to set the rendezvous point, thereby blocking the thread until the specified number of threads is reached, and then release them together, which can generate a lot of pressure instantly. So how is it applied in distributed?

for example:

We set the number of threads in a thread group to 100, because there are 3 slaves, so we expect the instantaneous concurrency to reach 300, so we add a fixed timer, and expect to reach 300 instantaneous concurrency, as shown in the figure below:

Please add a picture description

After using 3 slave machines, it was found that there was no request. This is because the setting of the synchronization timer only works in the current jvm, and 3 slaves are 3 independent jvms, and the synchronization timer needs to be released after the number of threads reaches the set number of threads. If there is no If you reach it, you will die forever.

Obviously, each independent slave will never reach 300 threads, because the number of threads set by each slave is only 100, so it will not be executed. Therefore, in the case of distribution, the number of blocked threads in the established synchronous timer should not be greater than the number of threads enabled in each jvm.

After the slave machine printed "starting..." after a period of time, there has been no change and no finish, and the master machine has no execution results;

Check JMeter-sever.log found: connection refused to host: 172.2x.xxx.x...

Where did the IP come from? Finally, it is found that the IP is a virtual machine network... Solution: If the remote load machine has a virtual network, the virtual network needs to be closed.

Please add a picture description

JMeter is a JAVA application, which occupies a lot of memory and CPU. When using a single machine for testing, for high-concurrency pressure testing, JMeter itself will consume a lot of local resources. If you want to increase concurrency, a machine will appear If you have no intentions, you can easily reach the performance bottleneck. Using distributed stress testing can effectively reduce the impact of local machine performance on stress testing results.

The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Life is not only about the present, but also a distant place waiting for us to conquer. We must bravely face challenges, dare to break through ourselves, strengthen our beliefs, and continue to work hard. Only in this way can we reach the other shore that our hearts yearn for.

Never give up on your dreams, because there is nothing more important than persistence. Even if the road is long, we must support ourselves with faith and courage and move forward firmly. Only by constantly striving can we move towards a brilliant life.

Life is like a marathon, not the fastest one wins, but the one who lasts till the end. As long as you have enough enthusiasm and perseverance, and are willing to work hard for your dreams, success is not far away.

Guess you like

Origin blog.csdn.net/shuang_waiwai/article/details/130367429