The original text is transferred from:https://blog.csdn.net/lovesoo…
Apache JMeter is a pure Java programming load function testing and performance testing open source tool software. Compared with LoadRunner, JMeter is small, light and free, and has gradually become a mainstream performance testing tool. It is one of the tools that every tester must master.
This article is a complete introduction to JMeter performance test, from JMeter download and installation to write a complete performance test script, and finally perform the performance test and analyze the performance test results.
The running environment is windows 10 system, JDK version is 1.8, JMeter version is 3.3
- JMeter installation
============
2.1 JDK installation
As JMeter is developed based on Java, you need to download and install JDK first (currently JMeter only supports Java 8, not Java 9)
- Download address of official website:http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Select Java se 8u151 / 8u152 and click JDK to download
- Install the downloaded JDK
- Configure system environment variables
2.2 JMeter installation
- Download address of official website:http://jmeter.apache.org/download_jmeter.cgi
- Download the latest JMeter version 3.3: apache-jmeter-3.3.zip
- After downloading, unzip the package
- Start JMeter
Double click under the JMeter decompression path (apache-jmeter-3.3bin) bin jmeter.bat That’s it - Test case
========
We select the most common Baidu search interface:
3.1 interface address
http://www.baidu.com/s?ie=utf-8&wd=jmeterperformance testing
3.2 request parameters
Ie: encoding mode, the default is UTF-8
WD: search term
3.3 return results
For the search results, we can judge whether the request is successful or failed by checking whether the search term WD is included in the results.
- JMeter scripting
==============
4.1 add thread group
Right click “test plan” – > “add” – > “threads (users) – >” thread group “
Here, you can configure the thread group name, number of threads, ramp up period (in seconds), number of cycles, scheduler and other parameters
Thread group parameter details:
- Number of threads: number of virtual users. A virtual user occupies a process or thread. Set the number of virtual users here, that is, set the number of threads.
- Ramp up period (in seconds) preparation time: how long does it take to set the number of virtual users to start all. If the number of threads is 10 and the preparation time is 2, it takes 2 seconds to start 10 threads, that is, 5 threads per second.
- Number of loops: the number of times a thread sends a request. If the number of threads is 10 and the number of loops is 100, then each thread sends 100 requests. The total number of requests is 10 * 100 = 1000. If “forever” is checked, all threads will send requests all the time, and then choose to stop running the script.
- Delay thread creation until needed.
- Scheduler: set the start time and end time of thread group startup (when configuring the scheduler, you need to check that the number of cycles is always)
Duration (seconds): test duration, which will cover the end time
Startup delay (seconds): test the startup delay time, which will cover the startup time
Start time: test start time, start delay will override it. When the start-up time has passed, the current time will also be covered when you only need to test manually.
End time: the end time of the test, and the duration will cover it.
Because of the need of interface debugging, we use the default settings for the time being, and then come back to configure when we really perform the performance test later.
4.2 add HTTP request
Right click “thread group” – > “add” – > “sampler” – > “HTTP request”
For our interfacehttp://www.baidu.com/s?ie=utf-8&wd=jmeterFor performance test, please refer to the figure below
Details of main parameters of HTTP request:
- Web server
Protocol: send HTTP request protocol to the target server. It can be HTTP or HTTPS. The default is http
Server name or IP: the name or IP of the server to which the HTTP request is sent
Port number: the port number of the target server. The default value is 80
2. HTTP request
Methods: the methods of sending HTTP request include get, post, head, put, options, trace, delete, etc.
Path: target URL path (the remaining part of the URL after removing the server address, port and parameters)
Content encoding: encoding method. The default is iso-8859-1 encoding, which is configured as UTF-8 - Send parameters with request
For the URL parameters sent in the request, users can set all the parameters in the URL in this table. Each line in the table has a parameter (corresponding to the name = value in the URL). Note that when the parameter is transferred into Chinese, you need to check “code”
4.3 add view result tree
Right click “thread group” – > “add” – > “listener” – > “view result tree”
At this time, we run the HTTP request and modify the response data format to “HTML source formatted”. We can see that the search result page is titled “JMeter performance test”_ Baidu search “.
4.4 add user defined variables
We can add user-defined variables to parameterize HTTP requests. Right click “thread group” – > “add” – > “configuration component” – > “user defined variables”:
Add a new parameter WD to store the search term:
This parameter is used in HTTP request, and the format is ${WD}
4.5 adding assertions
Right click HTTP request add assertion response assertion
We check whether the returned text contains search terms, and add the parameter ${WD} to the pattern to be tested
4.6 add assertion results
Right click “HTTP request” – > “add” – > “listener” – > “assertion result”
At this point, we can run it again to see whether the assertion is successful or failed
4.7 add aggregate Report
Right click “thread group” – > “add” – > “listener” – > “aggregate report” to store the performance test report
In this way, we have completed a complete HTTP interface JMeter performance test script.
- Perform performance test
==========
5.1 configure thread group
Click the thread group to configure the relevant parameters of this performance test: number of threads, number of loops, duration, etc. Here we configure the number of concurrent users to be 10 and the duration to be 60s
5.2 performing tests
Click the small green arrow button to start the test. Before the test, you need to click the small broom button to clear the previous debugging results.
- Analysis and test report
==========
After the performance test is completed, open the aggregation report to see:
Details of aggregation report parameters:
- Label: each JMeter element (for example, HTTP request) has a name attribute, which shows the value of the name attribute
-
Samples: number of requests – indicates the total number of requests issued in this test. If 10 users are simulated and each user iterates 10 times, 100 will be displayed here
- Average: average response time – by default, it is the average response time of a single request. When transaction controller is used, the average response time is displayed in transaction unit
- Median: the median response time of 50% users
- 90% line: response time of 90% users
- Min: minimum response time
- Max: maximum response time
- Error%: error rate — number of error requests / total number of requests
- Throughput: throughput – by default, it represents the number of requests per second completed. When transaction controller is used, it can also represent the number of transactions per second similar to LoadRunner
- KB / sec: the amount of data received from the server per second, which is equivalent to the throughput / sec in LoadRunner
Generally speaking, the data we need to focus on in performance testing are: number of samples requests, average response time, min minimum response time, Max maximum response time, error% error rate and throughput.
- Source code download
========
So far, we use JMeter to complete a complete HTTP interface performance test process, from script writing, execution to final result analysis.
Complete script source code download link:https://pan.baidu.com/s/1eS90cVoPassword: St15