JMeter performance test, complete introductory chapter

Time:2021-4-8

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

  1. 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)

  1. Download address of official website:http://www.oracle.com/technetwork/java/javase/downloads/index.html 
  2. Select Java se 8u151 / 8u152 and click JDK to download

JMeter performance test, complete introductory chapter

  1. Install the downloaded JDK
  2. Configure system environment variables

2.2 JMeter installation

  1. Download address of official website:http://jmeter.apache.org/download_jmeter.cgi
  2. Download the latest JMeter version 3.3: apache-jmeter-3.3.zip
    JMeter performance test, complete introductory chapter
  3. After downloading, unzip the package
  4. Start JMeter
    Double click under the JMeter decompression path (apache-jmeter-3.3bin) bin jmeter.bat That’s it
    JMeter performance test, complete introductory chapter
  5. 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.

  1. JMeter scripting

==============

4.1 add thread group

Right click “test plan” – > “add” – > “threads (users) – >” thread group “
JMeter performance test, complete introductory chapter 
Here, you can configure the thread group name, number of threads, ramp up period (in seconds), number of cycles, scheduler and other parameters
JMeter performance test, complete introductory chapter 
Thread group parameter details:

  1. 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.
  2. 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.
  3. 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.
  4. Delay thread creation until needed.
  5. 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”
JMeter performance test, complete introductory chapter 
For our interfacehttp://www.baidu.com/s?ie=utf-8&wd=jmeterFor performance test, please refer to the figure below
JMeter performance test, complete introductory chapter 
Details of main parameters of HTTP request:

  1. 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
  2. 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”
JMeter performance test, complete introductory chapter 
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 “.  
JMeter performance test, complete introductory chapter

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”:
JMeter performance test, complete introductory chapter 
Add a new parameter WD to store the search term:
JMeter performance test, complete introductory chapter 
This parameter is used in HTTP request, and the format is ${WD}
JMeter performance test, complete introductory chapter

4.5 adding assertions

Right click HTTP request add assertion response assertion
JMeter performance test, complete introductory chapter 
We check whether the returned text contains search terms, and add the parameter ${WD} to the pattern to be tested
JMeter performance test, complete introductory chapter

4.6 add assertion results

Right click “HTTP request” – > “add” – > “listener” – > “assertion result”
JMeter performance test, complete introductory chapter

At this point, we can run it again to see whether the assertion is successful or failed
JMeter performance test, complete introductory chapter

4.7 add aggregate Report

Right click “thread group” – > “add” – > “listener” – > “aggregate report” to store the performance test report
JMeter performance test, complete introductory chapter 
In this way, we have completed a complete HTTP interface JMeter performance test script.

  1. 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
JMeter performance test, complete introductory chapter

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.  
JMeter performance test, complete introductory chapter

  1. Analysis and test report

==========

After the performance test is completed, open the aggregation report to see:
JMeter performance test, complete introductory chapter

Details of aggregation report parameters:

  1. Label: each JMeter element (for example, HTTP request) has a name attribute, which shows the value of the name attribute
  2. 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

  3. 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
  4. Median: the median response time of 50% users
  5. 90% line: response time of 90% users
  6. Min: minimum response time
  7. Max: maximum response time
  8. Error%: error rate — number of error requests / total number of requests
  9. 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
  10. 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.

  1. 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