当前位置:网站首页>JMeter pressure measuring tool beginner level chapter

JMeter pressure measuring tool beginner level chapter

2022-06-23 22:50:00 Weijingwei

background : The main content of this document is jmeter Introduction to script configuration and debugging methods , With the help of existing jmeter Templates , Quickly understand and write a more successful jmeter Script

1. jmeter scripting

1.1 jmeter Script template

Get the script template file , Just make corresponding changes on the template , The template contains the required configuration and the selected configuration , Can quickly complete a successful script , Reduce trial and error and save time .

The template can see many components . The highlighted part is the required configuration , Selection and configuration of gray setting , You can set what needs to be highlighted according to your own usage scene , What needs to be grayed out .

2. jmeter Required configuration

2.1 Thread group

Use jmeter When performing a performance test , All tasks are based on thread groups , A thread group can impersonate several users :

2.1.1 Add thread group

Right click test plan , Select thread group , You can see the thread group panel as follows :

1) By default, thread group is selected after sampler error , Continue to execute the following request

2) Number of threads 、ramp-up Time 、 The default number of cycles is 1

2.1.2 Scheduler

The scheduler is grayed out by default , If checked, you can use . The scheduler can configure the duration and startup delay time , It is used to simulate the pressure measurement of stability performance .

( Delay time is often used when multiple thread groups execute serially , If there is only one thread group in the test plan , It can be configured as 0)

2.2 HTTP request

2.2.1 add to http request , Request in panel url The configuration is as follows :

2.2.2 except url Out of configuration , The parameter transfer module in the panel has 3 Ways of planting :

1) Key to parameter

2) Message body data transfer parameters ( Commonly used ):

3) File upload type :

Step one : Some interface parameters may need to import a file , It can be realized through file uploading

Step two : View the interface header by capturing packets Content-Type What is the type of ? As shown in the figure below , The parameter type of this interface is :image/jepg

Step three : The most important step , Check right post Use multipart/from-data, Select... In advanced settings java Realization

2.3 Assertion

Commonly used BeanSell Assertion ,jmeter In its bean shell Variable built in , Users can use these variables with jmeter Interact . Common script contents are as follows :

// The assertion response code is 200 Request 
if(!ResponseCode.equals("200")){
	Failure = true;
	FailureMessage=ctx.getPreviousResult() + "  request was aborted , Return code :" + ResponseCode + "\n";
	String response = new String(ResponseData);
	log.info(FailureMessage);
	log.info("============================= Division 1==========================");
	log.info(response);
	return;
}

// Assert the contents of the response body 
String response = new String(ResponseData);
Failure = !(response.contains("<!--STATUS OK-->")); // Need modification contains The content in , Make assertions based on the actual content in the response body 

if (Failure) {
	Failure = true;
	FailureMessage=ctx.getPreviousResult() + " No assertion results found " + response + "\n";
	log.info("============================= Division 2==========================");
	log.info(response);
	return;
	
}

The assertion only needs to be changed according to the content in the interface response body Failure = !(response.contains("<!--STATUS OK-->")) This sentence , The rest need not be changed !

2.4 HTTP Header Manager

http The header manager plays an important role in sending requests , Usually in use jmeter When sending a request to the server , Often the back end needs some authentication information . for example web The server needs to cookie Take it to the server to verify , It is usually placed in header In the head . Therefore, the data in the request header can be placed in the form of key value pairs http In header Manager .

The following are common header fields :

2.4.1 content-type

content-type The function is to tell the server the format of the request we send . Commonly used content-type There are the following 3 Kind of :

1)content-type: application/x-www-form-urlencoded

http Request defaults , If not specified content-type, This format is used by default . Parameters in this format can be found in “ Parameters ” perhaps “ Message body data ” Internal input , The format is different , As shown in the figure below :

2)content-type:application/json

The supported format is json

3)content-type:multipart/form-data

This type is in post When asked , Support the method of file uploading parameters . Please refer to 1.2.2 http Parameter transfer method in request .

Step one : Some interface parameters may need to import a file , It can be realized through file uploading

Step two : View the interface header by capturing packets Content-Type What is the type of ? As shown in the figure below , The parameter type of this interface is :image/jepg

Step three : The most important step , Check right post Use multipart/from-data, Select... In advanced settings java Realization

2.4.2 accept-encoding

accept-encoding It is the coding method that the client indicates that it is connected , Compression method is usually specified , for example gzip,deflate etc. . This configuration is carried by default when actually accessing a web page from a browser , therefore jmeter When designing scripts , You can configure... In the request header .

accept-encoding:gzip, deflate, br. It means to support this 3 A compression method , Server may return content-encoding:gzip, It means that the server is in the form of gzip Compression by .

2.5 User defined variables

During scripting , There are often a large number of repeated variables that need to be set , If it's modified , It has to be modified many times . To save this time , We can configure user-defined variable components to define global variables , Variables need to be changed only once , And better manage .

  1. The procedure is as follows :

2、 Which attributes are often set as variables :

1) Thread group related properties : Number of threads 、ramp-up Time 、 Duration, etc , Like the picture above

2)http The domain name in the request or ip: Usually, only a few domain names are used in a project , There are dozens or even hundreds of interfaces , Therefore, the domain name or ip Set to global variable

2.6 HTTP Request defaults

This component can be set for us http Request defaults , When multiple requests in a test plan are sent to the same server, You can directly set the default domain name or ip, then http Domain name is not filled in the request , The final request will default to http Request the value in the default value .

Be careful : If the following 2 Configurations :

1) If two are set in a test plan http Request defaults , The last one shall prevail

2) If it is in the test plan , Global settings http Default request value , A thread group is also set http Default request value , Finally, the settings under the thread group shall prevail

2.7 View the result tree

The view result tree component is mainly a debug script , No setting is required after configuration , You can see the sending and returning information of the request . The following instructions show how to quickly debug scripts by viewing the result tree :

2.7.1 The display request on the left side of the panel is successful / Failed state , The status code can be seen in the rear sampler . The following are common status codes :

200: The server has successfully processed the request

400: Wrong request , The server does not understand the syntax of the request

401: unauthorized , It is usually not logged in or the login status is invalid

503: Service not available , Unable to process request

2.7.2 The request is divided into two parts , Part is the request body , Part is the request header

2.7.3 The response data is divided into two parts , Part is the response body , Part is the response header

2.8 Aggregation report

2.9 Back end listener

The back-end listener is an asynchronous listener , The pressure measurement data can be pushed to the database , Provides influxDB、graphite Options are selectable . We choose... For pressure measurement influxdb Do persistent storage , combination grafana Panel monitoring jmeter Piezometric data .

2.9.1 The panel of the back-end listener is as follows :

2.9.2 How to configure the monitoring panel

1) Get the default script template , change influxdbUrl, From the default host_to_change Change to your own address

We usually use as :http://jmeter-influxdb:8086/write?db=jmeter

2) change application Name your project , It can be quickly identified .

3. jmeter Script debugging

Modify the information of the script template to the interface you want to use , Need to debug script , See if the single interface can be debugged .

3.1 Script startup method

The debugging script only needs to run one piece of data , There are two debugging methods , Recommend the second

1) Modify thread group configuration , take threads and loop count Change to 1, Click on start function

2) Right click thread group , Click on validate, Requests under this thread group run only once

3.2 View debugging results - View the result tree

For the results of script debugging, it is preferred to view the result tree component , No setting is required after configuration , You can see the sending and returning information of the request . The following instructions show how to quickly debug scripts by viewing the result tree :

3.2.1 The display request on the left side of the panel is successful / Failed state , The status code can be seen in the rear sampler . The following are common status codes :

200: The server has successfully processed the request

400: Wrong request , The server does not understand the syntax of the request

401: unauthorized , It is usually not logged in or the login status is invalid

503: Service not available , Unable to process request

3.2.2 The request is divided into two parts , Part is the request body , Part is the request header

3.2.3 The response data is divided into two parts , Part is the response body , Part is the response header

3.3 View debugging results -jmeter Log viewer

When the script runs , When there is no response in the result tree , You can view the log for error analysis .

choice jmeter Options -> Check the log to view , The log module will be displayed in the lower right corner of the panel :

The error messages in the log module are usually in the form of info perhaps error Print out the prefix of

原网站

版权声明
本文为[Weijingwei]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112101739155442.html