Stress testing with JMeter

I. Introduction

Stress test before each Web application on line will need to do a test, he can help us find bottlenecks in the system, reducing the chance of release into the production environment after the problem; the estimated carrying capacity of the system, so that we can in accordance with it to make some response. So the pressure test is a very important step, here I take everyone to use a stress testing tool JMeter.

II. About JMeter

Apache JMeter is a Java-based stress test tools developed by Apache. For software to do the stress test, which was originally designed for testing Web applications, but later extended to other test 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 so on. JMeter can be used to great load to a server, or network objects in the simulation, testing and analysis of their strength from the overall performance under different load types. In addition, JMeter can do functional / regression testing for application by creating a script with the assertion to verify your program returns the results you expect. For maximum flexibility, JMeter allows the use of regular expressions to create assertion.
Apache jmeter can be used in the performance of static and dynamic resources (files, Servlet, Perl scripts, java objects, database and query, FTP server, etc.) for testing. It can be used on a server, or network subject to heavy load simulation test its strength or overall performance analysis types at different pressures. You can use it to do a graphical analysis of performance or in large concurrent load test your server / script / object.

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

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

More introduce https://baike.baidu.com/item/Jmeter/3104456

III. Preparations

Because JMeter is written using JAVA, so before using JMeter, install the JAVA environment, we do not talk about is better to install a JAVA environment. .

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

Unzip the downloaded binary packages, go to the bin directory, use the jmeter.batlauncher.

After the start there will be two windows, a cmd window, a JMeter's GUI. Front Do not ignore the message CMD window:

 

JMeter:

CMD prompt window

================================================================================
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 above means: Do not use the GUI to run stress tests, GUI only for creating and debugging stress testing; perform stress tests do not use GUI. Use the following commands to perform the test:

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

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

Change language to Chinese

Simplified Chinese official default provides for us. By [Options] -> [Choose Language] changed to Simplified Chinese

IV. Create a test

1. Create a thread group

On the "Test Plan" right [Add] -> [Threads (Users)] -> [group] thread.

Set the number of threads and number of cycles. I set the number of threads here for the 500, the cycle time.

Configuration elements

On the thread group we just created, right [Add] -> [configuration elements] -> [HTTP Request Defaults].

We need to test the configuration procedure protocol, addresses and ports

When all of the interface test access port and domain name are the same, you can use the device, once the server address changes, you only need to modify the default value of the request.

3. The configuration of the HTTP request

In the "thread group" Right to add [-] -> [samlper] -> [HTTP] request to set the API request path and the data we need to test. I'm here with the json

4. Add the HTTP request header

在我们刚刚创建的线程组上右键 【添加】-->【配置元件】-->【HTTP信息头管理器】。

因为我要传输的数据为json,所以设置一个 Content-Type:application/json

5.添加断言

在我们刚刚创建的线程组上右键 【添加】-->【断言】-->【响应断言】。

根据响应的数据来判断请求是否正常。我在这里只判断的响应代码是否为200。还可以配置错误信息

6.添加察看结果树

在我们刚刚创建的线程组上右键 【添加】-->【监听器】-->【察看结果树】。

直接添加,然后点击运行按钮就可以看到结果了。

7.添加Summary Report

在我们刚刚创建的线程组上右键 【添加】-->【监听器】-->【Summary Report】。

直接添加,然后点击运行按钮就可以看到结果了。

为了不引起不必要的争论,隐藏了TPS。此数据不具备任何价值,仅仅为文章演示。

8.测试计划创建完成

记得点保存。

五.执行测试计划

前面我们说过,执行测试计划不能用GUI,需要用命令行来执行。

我这里执行的命令为:

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

说明:

testplan/RedisLock.jmx 为测试计划文件路径
testplan/result/result.txt 为测试结果文件路径
testplan/webreport 为web报告保存路径。

Web报告如下:

六.写在最后

线程数量和循环次数将会影响最终的测试报告,请大家多多测试。

 

Guess you like

Origin blog.csdn.net/xulong5000/article/details/91491734