preface

You may be wondering, as a front-end siege lion, why do I need pressure testing, and what does it have to do with me? If you want to build a full stack and write node services, you definitely need to. If you’re a backend, you need to know if the interface you’re providing has performance issues and if your code is robust. For testing, there is definitely a need to master, the reasons need not be described. First write in the front, where write bad, welcome to communicate with teachers.

Today’s tool is JMeter, because it’s free and powerful.

First of all, stress testing is a requirement of every Web application before it goes live. It can help us find bottlenecks in the system and reduce the chances of problems after release to production. Estimate the carrying capacity of the system so that we can make some countermeasures based on it. So the stress test is a very important step. Now I would like to introduce my favorite JMeter to you.

About the jmeter

Apache JMeter is a Java-based stress testing tool developed by the Apache organization. Used to stress test software, it was originally designed for Web application testing, but has since expanded to other testing areas. It can be used to test static and dynamic resources, such as static files, Java applets, CGI scripts, Java objects, databases, FTP servers, and so on. JMeter can be used to simulate heavy loads on servers, networks, or objects, test their strength under different stress categories, and analyze overall performance. In addition, JMeter can perform functional/regression tests on applications, verifying that your program returns the results you expect by creating scripts with assertions. For maximum flexibility, JMeter allows you to create assertions using regular expressions. Apache JMeter can be used to test the performance of both static and dynamic resources (files, servlets, Perl scripts, Java objects, databases and queries, FTP servers, and so on). It can be used to simulate heavy loads on servers, networks, or objects to test their strength or analyze overall performance under different stress types. You can use it to do graphical analysis of performance or test your servers/scripts/objects under large concurrent loads.

The preparatory work before starting

Jmeter was developed in Java, soJDKThe JDK doesn’t need to configure environment variables after version 8.

After Java is installed, run the javac -version command to check whether the Java version is successfully installed.

There’s another onejmeter! Above is the version you can use directly, below is the source code, you can do secondary development, or compile yourself.

After decompressing, go to the directory (jmeter/bin) and execute sh jmeter to see the GUI.



The command line message is:

Do not use GUI to run stress tests, only use GUI for stress test creation and debugging; Do not use guIs when performing stress tests.

Can be changed to Chinese language:

Introduce a strange trick, here the appearance to choose, choose the first, do not modify, otherwise their Settings can not save.

Start to create

First, create a thread group

Set the number of threads and loops here. I’m going to set the number of threads to 100 and loop once.

Second, create the configuration element and select the HTTP default values.

Configure the protocol, address, and port of the program we need to test

Third, construct the HTTP request.

Configure the protocol, address, and port of the program we need to test

Fourth, add the HTTP request header.

Right-click add – > Configure Components – > HTTP Header Manager on the thread group we just created.

Step 5, add assertions.

Right-click Add — > Assert — > Response Assert on the thread group we just created.



Determine whether the request is healthy based on the response data. I’m just checking here if the response code is 200. Error information can also be configured.

Sixth, add the view result tree.

Right-click add – > Listener – > View Result Tree on the thread group we just created.

Step 7: Create a summary report.

Right-click add – > Listener – > Summary Report on the thread group we just created.

Start testing.

Summary report:

Details of each request:

Initiate pressure test schedule

As mentioned earlier, we can’t test directly through the GUI, we need to use the command line. Run the following command: jmeter -n -t [JMX file] -l [results file] -e -o [Path to Web Report Folder]

JMX file is the path to the test plan file

Results file is the path to the test result file

Path to Web Report Folder Report Path

After executing, view the summary results from the report Path in the “Path to Web Report Folder” and open the HTML: