How to use jmeter for pressure measurement

Table of contents

1 Overview

2. Test plan, thread group, sampler

3. Debugging and running

4. Request Defaults

5. Traffic recording

6. Simulate time intervals

7. Stress test

8. Report


1 Overview

A tool often has many functions and many details. In the actual test work, most of the scenarios will use some core functions. It is not necessary for us to master all the functions of the tool in detail. . Therefore, this article will explain how to quickly get started using jmeter for pressure measurement with the least expensive way.

JMeter, an interface testing tool, is a Java program that requires a JDK environment. It is recommended to use JDK8 or JDK11.

download link:

https://jmeter.apache.org/download_jmeter.cgi

start up:

Installation path/bin/jmeter.bat (.sh)

2. Test plan, thread group, sampler

test plan:

Test plan, a test plan in jmeter corresponds to a test scenario.

thread group:

Thread group, a thread group in jmeter corresponds to a behavior. A behavior can be understood as a scene, which can be composed of multiple interfaces, such as placing an order, which can include multiple interfaces such as deducting inventory and generating orders.

Sampler:

It can be understood as a request, and jmeter supports many types of samplers, of course, we often use http samplers.

The relationship between the three:

The use of the entire jmeter is actually to create a test plan, and then add various required things under the test plan, such as thread groups, listeners, etc.,

A thread group contains multiple samplers, and a sampler is a request. Each thread in the thread group will execute the samplers under the group completely from top to bottom.

Create a test plan and add a thread group:

The thread group adds a sampler, and the request for the http interface adds the http sampler:

After a complete test plan is built, it supports exporting as a file. After exporting to a file, you can leave the interface to run the entire test plan through instructions:

 

3. Debugging and running

Direct execution of the test plan will not display any results. You need to add a listener to debug and view intermediate results.

Generally use the view results tree to view the listener of the results tree, and you can view the running results.

The meaning of some core parameters:

Connect Time: The time to establish a TCP connection.

latency: The time between when the request is sent and when the first response is received.

loadtime: The time from before the request is sent to when all responses are received.

Size in bytes: The size of the entire response message = header+body.

Headers size in bytes: The header size of the response.

Body size in bytes: The body size of the response.

4. Request Defaults

Request Defaults, which is the default configured default value for the request. After configuration, all requests in a test plan default to the configuration in Request Defaults.

 

5. Traffic recording

When testing a web page, in addition to the API, there are also many requests for static resources (html/js/css) in the http request. How many urls are requested from this page? You can use the traffic recording function of jmeter to record all http requests in a certain visit. This function is rarely used in actual stress testing. Here is just a mention of this function, without expanding it. When you need to use it, you can search it and find out how to use it.

6. Simulate time intervals

Time intervals can be simulated by using a timer, and the scope of the timer is all sibling nodes and their child nodes under the node.

There are many kinds of timers, and some timers are not fixed time intervals, such as Gaussian timers whose time interval satisfies Gaussian changes, etc. You can search for specific types.

 

7. Stress test

Run command:

The real stress test does not use a graphical interface for testing, because the graphical interface will also have performance loss as an intermediate layer, but directly uses the command line mode.

{base dir}\bin\jmeter -n -t XXX.jmx -l log.jtl

XXX.jmx is a jmx file exported after configuration using the graphical interface.

Stress tests generally give test cases to describe performance requirements. The following is a performance test case:

Users do not need to log in, they first visit the home page, then visit the single course page, and finally visit the news page.

Access pages every 10 seconds.

The number of users is 1200, and they go online in 10 minutes.

Just configure jmeter according to the test case. The configuration of converting the above requirement description into jmeter is:

Create a thread group with 1200 threads and execute it within 10 minutes;

There are three http samplers under the thread group, which are the request home page, request single course page, and request news page in order;

Create a timer that samples every 10 seconds.

8. Report

jmeter can generate HTML reports

jmeter -n -t [Jmx script location] -l [intermediate file result.jtl location] -e -o [report specified folder]

An HTML file will be generated in the report folder, which will contain detailed statistics of requests for all urls, such as success, failure, and time-consuming information.

Here is an example:

 

Guess you like

Origin blog.csdn.net/Joker_ZJN/article/details/130663229