Stress testing with JMeter

I. Introduction

Stress testing is a test that every web application needs to do before it goes online. It can help us find bottlenecks in the system and reduce the probability of problems after publishing to the production environment; estimate the carrying capacity of the system, so that we can It takes some countermeasures. So stress testing is a very important step. Let me take you to use JMeter, a stress testing tool.

2. About JMeter

Apache JMeter is a Java-based stress testing tool developed by the Apache organization. Used for stress testing 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 servlets, CGI scripts, Java objects, databases, FTP servers, and more. JMeter can be used to simulate huge loads on servers, networks or objects, test their intensity from different stress categories and analyze overall performance. Additionally, JMeter can do functional/regression testing of your application by creating scripts with assertions to verify that your program returns the results you expect. For maximum flexibility, JMeter allows the use of regular expressions to create assertions.
Apache jmeter can be used to test the performance of static and dynamic resources (files, servlets, Perl scripts, java objects, databases and queries, FTP servers, etc.). 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.

Official website: http://jmeter.apache.org/download_jmeter.cgi

Here I choose the binary package of version 4.0: http://mirror.bit.edu.cn/apache//jmeter/binaries/apache-jmeter-4.0.zip

More content introduction https://baike.baidu.com/item/Jmeter/3104456

3. Preparations

Because JMeter is written in JAVA, before using JMeter, install the JAVA environment first. This article will not talk about how to install the JAVA environment. .

JAVA environment variable configuration: https://jingyan.baidu.com/article/fd8044fa2c22f15031137a2a.html

Unzip the downloaded binary package, enter the bin directory, and use jmeter.batthe startup program.

After startup, there will be two windows, a cmd window and a JMeter GUI. Don't ignore the prompt information of the CMD window before :

JMeter:

CMD window prompt information

================================================================================
Don't use GUI mode for load testing !, only for Test creation and Test debugging.
For load testing, use NON GUI Mode:
   jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
& increase Java Heap to meet your test requirements:
   Modify current env variable HEAP="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m" in the jmeter batch file
Check : https://jmeter.apache.org/usermanual/best-practices.html
================================================================================

The meaning of the above is: do not use the GUI to run the stress test, the GUI is only used for the creation and debugging of the stress test; please do not use the GUI to execute the stress test. Use the following command to execute the test:

 jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]

And modify the environment variables of the JMeter batch file:HEAP="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m"

Change language to Chinese

The official default provides us with simplified Chinese. Change to Simplified Chinese through 【Options】->【Choose Language】

4. Create a test

1. Create a thread group

Right-click on "Test Plan" [Add]-->[Threads(Users)]-->[Thread Group].

Set the number of threads and loops. I set the number of threads here to 500 and loop once.

2. Configuration components

Right-click on the thread group we just created [Add]-->[Configuration Component]-->[HTTP Request Default].

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

When the access domain name and port of all interface tests are the same, this component can be used. Once the server address is changed, it is only necessary to modify the default value of the request.

3. Construct an HTTP request

Right-click on "Thread Group" [Add-]->[samlper]-->[HTTP Request] to set the request path and data of the API we need to test. I am using json here

4. Add HTTP request header

Right-click on the thread group we just created [Add]-->[Configuration Elements]-->[HTTP Information Header Manager].

Because the data I want to transmit is json, set aContent-Type:application/json

5. Add assertions

Right-click on the thread group we just created [Add]-->[Assertions]-->[Response Assertion].

According to the response data, it is judged whether the request is normal or not. I'm only judging if the response code is 200 here. Error messages can also be configured

6. Add view result tree

Right-click on the thread group we just created [Add]-->[Listener]-->[View Result Tree].

Add it directly, and then click 运行the button to see the result.

7. Add Summary Report

Right-click on the thread group we just created [Add]-->[Listener]-->[Summary Report].

Add it directly, and then click 运行the button to see the result.

In order not to cause unnecessary arguments, TPS is hidden. This data has no value and is only for presentation purposes.

8. The test plan is created

Remember to click save.

5. Execute the test plan

As we said earlier, the execution of the test plan cannot be done with the GUI, it needs to be executed with the command line.

The command I execute here is:

jmeter -n -t testplan/RedisLock.jmx -l testplan/result/result.txt -e -o testplan/webreport

illustrate:

testplan/RedisLock.jmxPath to the test plan file Path
testplan/result/result.txtto the test result file Path
testplan/webreportto save the web report.

The web report is as follows:

6. Write at the end

The number of threads and the number of loops will affect the final test report, please test more.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325339497&siteId=291194637