The role of each component of Jmeter

Introduction to the main components of JMeter

1. Test Plan (Test Plan) is the starting point for testing with JMeter, it is a container for other JMeter test components.
2. Thread Group represents a certain number of concurrent users, which can be used to simulate concurrent users sending requests.
3. The sampler defines the actual request content and is contained by the thread group. We mainly use HTTP requests.
4. Listener
5. Logic Controller
6. Assertions
7. Config Element
8. Pre Processors and Post Processors
9. Timer (Timer)

Introduction to the main components of JMeter - test plan

1. Test Plan (Test Plan) is the starting point for testing with JMeter, it is a container for other JMeter test components.
2. Name: You can give your test plan a meaningful name.
3. Comments: Comments on the test plan.
4. User-defined variables: Users can define variables by themselves, and use ${variable name} to refer to this variable directly. Example: variable name=url, value=http://www.baidu.com, just use ${url} when http://www.baidu.com is needed.
5.Add directory or jar to classpath: Add directories and jar packages to the classpath, namely %JMETER-HOME%\lib.

Introduction to the main components of JMeter - thread group

1. Name: Give the thread group a name.
3. Thread attribute - number of threads: Set the number of users who send requests, that is, the number of concurrent users.
4. Thread properties - Ramp-Up Period (in second): The time interval between threads, in seconds. That is, in how much time all threads start.
5. Thread properties - number of loops: the number of repetitions of the request. If you select the following forever (default), the request will continue. If you do not select forever and enter a number in the input box, the request will repeat the specified number of times. Enter 1, then the request will be executed once, if it is 0, there will be a problem.
5. Scheduler Configuration - Start Time: When the test plan starts, the start delay will override it.
6. Scheduler Configuration - End Time: When the test plan ends, the duration will override it.
7. Scheduler Configuration - Duration: How long the test plan lasts, it will cover the end time.
8. Scheduler configuration - start delay: how long the test plan delays to start, it will cover the start time.
 

Introduction to the main components of JMeter - sampler (HTTP request)

1. Name: The name of the HTTP request.
2. Web server - server name or IP, port number, automatically added when the script is recorded, or "user-defined variables" can be used.
3. HTTP request: use the default value.
4. Send parameters together with the request: The parameters and values ​​in the request can be set here, and parameterization and dynamic data association need to be used, which we will introduce later.
5. Send file with request: I can specify which file to send with request.
6. Other tasks include: Get all contained resources from HTML files, use as monitors, Embedded URLs must match.
Introduction to the main components of JMeter - listener
1. The Listener is responsible for collecting the test results and is also informed of the way the results are displayed.
Commonly used ones include: aggregation reports, viewing result trees, and viewing results in tables, all of which support writing result data to files.
Just add the others and see. The aggregation report was introduced earlier, followed by screenshots of viewing the result tree and viewing the results in a table.
Introduction to the main components of JMeter - listener (view the results in a table)

Introduction to the main components of JMeter - logic controller

1. The Logic Controller can customize the behavior logic of JMeter sending requests. It can be used in combination with Sampler to simulate complex request sequences.

 

The vloop controller can set the requested number of loops or loop forever (if forever is checked).
v Transaction controllers can place multiple requests in the same transaction. If Gegerate parent sample is selected, only the data of the transaction controller will be displayed in the aggregated report, and the data of each request in it will not be displayed, otherwise, all the data will be displayed.
 

Introduction to the main components of JMeter - assertion

1. Assertions can be used to determine whether the result of the request response is as expected by the user. It can be used to isolate problem domains, i.e. perform stress tests while ensuring correct functionality. This limit is very useful for efficient testing.

Introduction to the main components of JMeter - configuration components

1. The Config Element maintains the configuration information required by the Sampler and modifies the requested content according to actual needs. We mainly use CSV Data Set Config in parameterization

 

Introduction to the main components of JMeter - pre-processor and post-processor

1. Pre Processors and Post Processors are responsible for completing work before and after generating requests. Preprocessors are often used to modify the settings of the request, and postprocessors are often used to process the response data. We mainly use post-processor regular expression extractors in dynamic associations.
 
 

Introduction to the main components of JMeter - timer

1. Timer is responsible for defining the delay interval between requests.
 
 
 
 

Parametric settings

1. In our test plan, we use HTTP requests, and some parameters are often submitted in HTTP requests. In order not to use the same parameter values ​​in each request, we must find a way to make each request. The values ​​of the parameters are different, so we need to perform parameterized settings. Here we introduce two methods of parameterized settings.

One is to use the _Random function in the function assistant for parameterized settings;

One is to use the CSV Data Set Config in the configuration element for parameterized settings

2. There is a function helper function in JMeter, which has multiple built-in functions. We can use the _Random function among them to perform parameterization settings in the request.

v Select "Options - Function Helper Dialog" in JMeter to open the Function Helper dialog.

 

v Select a function _Random.
v Set the minimum value to 1.
v Set the maximum value to 100.
vThe function name is set to func1.
vClick Generate to generate a reference string ${_Random(1,100,func1}, just copy the string in the required request parameters.
v where the function name is used to distinguish between references, that is, we can set different names to refer to the same function in different places.
 
 
 
v For example: we generate two strings ${_Random(1,100,func1)}, ${_Random(1,100,func2)}, in the request to add a book, we refer to ${_Random(1,100, func1)}, apply ${_Random(1,100,func2)} to the parameter value of bookConcern, see screenshot, so that different threads will generate different bookName and bookConcern when the test is running.
 
 

Parameterization - CSV Data Set Config(1)

v Right-click on the thread group and select Add-Configuration Components-CSV Data Set Config to open CSV Data Set Config.
vFilename file name: that is, the parameterized file name to be referenced. here is d:\number.txt
vFile encoding File encoding: can be left blank.
vVariable Names (comma-delimited) variable names (separated by commas): Multiple variables can refer to the same file, separated by commas. here is num1,num2
vDelimiter(use '\t' for tab): The delimiter of multiple variable values ​​in the parameter file, \t means to use the tab key to separate, the default is a comma.
vRecycle on EOF?: Does it cycle after the end? Default is True.
The content of the vNumber.txt file is shown in the screenshot.
v In the request to add a book, we refer to ${num1} in the parameter value of bookName, and apply ${num2} in the parameter value of bookConcern, as shown in the screenshot, so that different threads will generate different bookName and bookConcern when the test is running .

 

Dynamic data association

1. In the parameters of HTTP requests, the values ​​of some parameters are often the corresponding dynamic data from the server. These data need to be correlated so that each request can be successfully accepted by the server. In JMeter, regular expressions are used to extract to obtain these dynamic data.
2. Regular expressions allow users to obtain data from the server response. As a post-processor, the regular expression extractor will be executed after each request is executed. The regular expression extracts the parameter values ​​of the request and generates a template string. and save the result into the given variable.
 

Dynamic Data Association (1) - Regular Expression Extractor

1. In the parameters of HTTP requests, the values ​​of some parameters are often the corresponding dynamic data from the server. These data need to be correlated so that each request can be successfully accepted by the server. In JMeter, regular expressions are used to extract to obtain these dynamic data. For example, if we want to get the corresponding TOKEN from the server, we can use the following regular expression extractor.
 
 
 

Dynamic Data Association (2)

When v is used, ${token_g1} can be used to represent the obtained TOKEN value. As shown below:
 
 
 

Running JMeter scripts using the command line

v JMeter  -n -t my_test.jmx -l log.jtl
vn tells JMeter to run JMeter scripts non-graphically
vt specifies the script file to run
vl specifies the file name to save the execution result
v Before executing the command, check whether the current directory is the %JMeter_Home%\bin directory;
v If  the JMeter  script is not in the current directory, you need to specify the full path; if you want to save the execution result elsewhere, you also need to specify the full path.
 

Using XSLT to analyze JMeter result files (1)

1. Change the extension of the result file to xml, for example: change log.jtl to log.xml.
2. In the file header of log.xml

<?xml version="1.0" encoding="UTF-8"?>

<testResults version="1.2">

added in

<?xml-stylesheet type=“text/xsl” href=“jmeter-results-report.xsl” ?>

make it into

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="jmeter-results-report.xsl" ?>

<testResults version="1.2">

Among them, href specifies the path of the xsl file. If it is in the same directory as the xml file, just write the file name. Otherwise, specify the detailed path.

 

Using XSLT to analyze JMeter result files (2)

1. Open the modified xml file with a browser to get the statistical results:

 

 
 

Distributed testing in JMeter

As a pure JAVA GUI application, JMeter's consumption of CPU and memory is still amazing, so when it is necessary to simulate thousands of concurrent users, using a single machine to simulate all concurrent users is somewhat incapable, and even causes JAVA memory overflow error. However, JMeter can also share the pressure of the load generator itself by using multiple machines to run so-called proxies like LoadRunner, and use this to obtain a larger number of concurrent users, we only need to configure it manually.
v1. Install JMeter on all machines expected to run JMeter as a load generator, and identify one of the machines as the controller and the others as agents. Then run the JMeter -server.bat file on all proxy machines - assuming we use two machines 172.20.80.47 and 172.20.80.68 as proxies;
v2. Find the bin directory in the JMeter installation directory of the Controller machine, then find the jmeter.properties file, and open it with Notepad or other text editing tools;
v3. Look for the string "remote_hosts=" in the opened file, you can find such a line "remote_hosts=127.0.0.1". Among them, 127.0..0.1 represents the machine running the JMeter agent, which needs to be modified to "remote_hosts=172.20.80.47, 172.20.80.68";
v4, save the file, and restart JMeter on the controller machine, and go to the Start->Remote Start menu item. You will see the addresses of the two agents we just added, select them to run, and if you want to start all agents at the same time, select Remote Start All.
To perform distributed testing, you need to add environment variables on the agent machine, that is, add the user variable JMETER_HOME=d:\jmeter, and add d:\jmeter\bin to the path in the system variable (assuming that jmeter is placed in the root directory of the d disk).
 
 

Run Jmeter for testing (4) - detailed explanation of aggregated reports

vLabel: Each JMeter element (such as HTTP Request) has a Name property, and the value of the Name property is displayed here
v#Samples: Indicates how many requests you have issued in this test. If the test plan simulates 10 users and each user iterates 10 times, 100 will be displayed here.
vAverage: Average response time - by default the average response time for a single Request, when using the transaction controller, the average response time can also be displayed in units of transactions
vMedian: Median, i.e. response time for 50% of users
v90% Line: Response time for 90% of users
vMin: minimum response time
vMax: maximum response time
vError%: Error rate, the number of requests with errors in this test / the total number of requests
vThroughput: Throughput - By default it represents the number of requests completed per second ( Request per Second )
vKB/Sec: The amount of data received from the server per second

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325269521&siteId=291194637