当前位置:网站首页>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 .
- 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
边栏推荐
- Flush cache clear
- How to set secondary title in website construction what is the function of building a website
- Heat transfer oil electric heater
- Micro build low code tutorial - variable definition
- Detailed explanation of bitmap optimization
- 脚本之美│VBS 入门交互实战
- Hugegraph: hugegraph Hubble web based visual graph management
- Problem solving: inittramfs unpacking failed:decoding failed
- PHP时间戳
- C#/VB.NET Word转Text
猜你喜欢

SLSA: 成功SBOM的促进剂

Ant won the finqa competition champion and made a breakthrough in AI technology of long text numerical reasoning

解密抖音春节红包背后的技术设计与实践

Section 30 high availability (HA) configuration case of Tianrongxin topgate firewall

為什麼你的數據圖譜分析圖上只顯示一個值?

Application practice | Apache Doris integrates iceberg + Flink CDC to build a real-time federated query and analysis architecture integrating lake and warehouse

SAVE: 软件分析验证和测试平台

【技术干货】蚂蚁办公零信任的技术建设路线与特点

Section 29 basic configuration case of Tianrongxin topgate firewall

Chaos engineering, learn about it
随机推荐
How to set up links for website construction how to build a website
Is the website under construction because there is no FTP upload? Can I upload without FTP
API gateway monitoring function the importance of API gateway
Batch production of plant hangtag
How to access the server through the fortress machine? What if the fortress computer can't jump to the server?
Ant group's self-developed tee technology has passed the national financial technology product certification
Advantages of micro service registry Nacos over Eureka
混沌工程,了解一下
How to deploy the deep learning model to the actual project? (classification + detection + segmentation)
Command line setting the next boot to enter safe mode
How to use FTP to upload websites to the web
How to use data warehouse to create time series
What is the difference between RosettaNet, EDI ANSI X12 and EDIFACT
Source code analysis of jmeter5.1 core class testcompiler
How to set the website construction title bar drop-down
The time deviation is more than 15 hours (54000 seconds), and the time cannot be automatically calibrated
Interviewer: the difference between uselayouteffect and useeffect
How to set secondary title in website construction what is the function of building a website
Detailed explanation of GC principle
Grpc: quickly configure the general API to obtain process meta information