Jmeter (fourteen) - from entry to master - JMeter timer - the next part (detailed tutorial)

content

1 Introduction

2. Preview timer

3. Detailed explanation of common timers

4. Summary


1 Introduction

  When the user actually operates, it is not a continuous click, but there are many pauses. For example, the user needs time to read the text content, fill in the form, or find the correct link. In order to simulate the actual user situation, we need to consider think time in performance testing. Failure to take thinking time into consideration can distort test results. For example, the estimated number of users that can be supported is too small. In performance testing, the pause time between access requests is called think time, so how to simulate this pause? We can achieve this with the help of JMeter's timers.

  Timers in JMeter are generally used by us to set delay and synchronization. The execution priority of the timer is higher than that of the Sampler (sampler). When there are multiple timers in the same scope (for example, under the controller), each timer will be executed. Once the sampler is valid, the timer can be added under the sampler node.

2. Preview timer

First, let's take a look at JMeter's timers, the path: thread group (user) -> add -> timer (Timer); we can clearly see that there are 9 timers in JMeter5, as shown in the following figure:

 

If you can't see the above picture clearly, Brother Hong summed up a mind map, about the type of logic controller of JMeter5, as shown in the following figure:

 

Through the above understanding, we have a general understanding and understanding of the timer. Below, Brother Hong will share and explain some timers that are usually used in work to friends or children's shoes.

3. Detailed explanation of common timers

In this section, Brother Hong will explain the commonly used timers in detail from top to bottom .

3.1Gaussian Random Timer

Gaussian timer, Gaussian timer, generates a time interval with a Gaussian distribution. If the delay time of each thread is required to be a random time pause that conforms to the standard normal distribution, then use this timer, total delay = Gaussian distribution value (mean 0.0 and standard deviation 1.0) * specified deviation value + fixed delay offset ( Calculation reference: Math.abs((this.random.nextGaussian() * bias value) + fixed delay offset)). Another way to interpret it, in a Gaussian random timer, the random time is around a fixed delay offset and the probability follows a Gaussian curve distribution.

Total delay time = Gaussian distribution value (mean 0.0 and standard deviation 1.0) * specified deviation value + fixed delay offset

1. Let's take a look at what this Gaussian Random Timer looks like. Path: Thread Group > Add > Timer > Gaussian Random Timer , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Deviation: Ignore the sub-controller, that is, the sub-controller fails, and the alternate controller takes over.

Constant Delay Offset:

3.1.1 Examples

1. Create a new test plan, add 2 samplers under the thread group to visit the blog garden home page, and visit Beijing Hongge's garden, as shown in the following figure:

 

2. Then add the Gaussian random timer, set the deviation of the Gaussian random timer to 1000ms, and the fixed delay offset to 3000, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results (the sampler visits the homepage of the blog garden and the interval between visits to Duniang is 3s), as shown in the following figure:

 

3.2JSR223 Timer

JSR timer, in the latest version of jemter, this timer is added. It can be understood that this timer is equivalent to the "parent set" of the BeanShell timer. It can be implemented in various languages ​​such as java, JavaScript, and beanshell. things you wish to accomplish.

1. Let's take a look at what this JSR223 Timer looks like. Path: Thread Group > Add > Timer > JSR233 Timer , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Thread Delay: The sub-controller is ignored, that is, the sub-controller fails, and the alternate controller takes over.

3.2.1 Examples

1. Create a new test plan, add 2 samplers under the thread group to visit the homepage of the blog garden and visit Du Niang, as shown in the following figure:

2. Then add the JSR223 timer, and write a script to set the delay time to 5s, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results (the sampler accesses the blog garden home page and the interval between visits to Duniang is 5s), as shown in the following figure:

 

3.3Poisson Random Timer

Poisson random timer, this timer pauses at a random time before each thread request, the total delay is the sum of the Poisson distribution value and the offset value. This timer is paused at random times before each thread request, and the total delay is the sum of the Poisson distribution value and the offset value.

Poisson Distribution: Discrete probability distribution in probability

1. Let's take a look at what this Poisson Random Timer looks like. Path: Thread Group > Add > Timer > Poisson Random Timer , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Lambda(in milliseconds): Lambda value;

Constant Delay Offset(in milliseconds): The number of milliseconds to pause minus the number of milliseconds of random delay.

3.3.1 Examples

1. Create a new test plan, add 2 samplers under the thread group to visit the homepage of the blog garden and visit Du Niang, as shown in the following figure:

 

2. Then add the Poisson timer, and set the pause time to be distributed between 100 and 400 milliseconds, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results (the interval between the sampler accessing the blog garden home page and the visit to Duniang is between 100 and 400 milliseconds), as shown in the following figure:

 

3.4Synchronizing Timer

Synchronous timers are used to simulate multi-user concurrency, or more strict concurrency scenarios, such as seckill activities.

Function: It is also used to set the rendezvous point, block threads, and synchronize virtual users. After the specified number of threads is reached, the tasks are executed at the same time, and then released together, which can instantly generate a lot of pressure.

Note: Knock on the blackboard, knock on the head! ! !

In general, the number of concurrent users is limited by the number of synchronization timers written. (How many concurrent people have to wait for how many people to release together)

1. Let's take a look at what this Synchronizing Timer looks like. Path: Thread Group > Add > Timer > Synchronizing Timer , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Number of Simulated Users to Group by: The number of rendezvous points (the number of threads to execute), if set to 0, it is equal to the number of threads set to the thread lease.

Timeout in milliseconds: Specifies how many seconds the number of threads does not collect to count as timeout (in milliseconds). If set to 0, the timer will wait for the number of threads to reach the value set in "Number of Simultaneous Users toGroup" before releasing, otherwise it will die. If it is greater than 0, then if the value set in "Number of Simultaneous Users toGroup" has not been reached after the maximum waiting time set in Timeout inmilliseconds, Timer will no longer wait and release the thread that has arrived. Default is 0

Note: Knock on the blackboard, knock on the head! ! !

(1) If the values ​​of the above two parameters are both set, which condition is reached first and the timer executes first in practice, if the number of released threads of the first parameter is reached first, the value of the timeout time will not be considered, timer It will be released; if the timeout time of the second parameter is reached first, it will not wait for the number of threads, and the timer will be released according to the number of threads in the set at the current time-out time point.

(2) Timeout setting requirements for Synchronizing Timer: Timeout > Number of Request Sets * 1000 / (Number of Threads / Thread Loading Time)

The number of thread group users is 100, and a synchronization timer is added.

Number of threads (100)

Number of threads waiting for the timer (depending on the situation)

Timeout setting (default is 0, in milliseconds)

Set the effect (the effect achieved by the script running)

100

100

0

Users wait to reach 100 users with concurrent requests

100

90

100

1. The timeout is just 100ms, and wait until 90 users concurrently request; 2. Wait until 90 users, no timeout, continue to wait until the end, and then concurrently, the number of users will be greater than 90; 3. Wait until it is less than 90 and users, and it exceeds Set 100ms, then the concurrent request of the waiting user may be less than 90;

100

110

0

The user cannot reach 110 users, the thread will always wait and will not stop;

100

100

100

1. If the timeout is just 100ms, wait until 100 users concurrently request; 2. After the timeout of 100ms, the timer will make concurrent requests with the maximum number of users that have been waited; 3. If the timeout is 100ms, the number of users will not reach 100, and the number of users will be concurrently requested. , which is that the number of users may be less than 100;

100

0

0

The number of users set by the timer is equivalent to the number of users of the thread. The default timeout is set to 0, and users make concurrent requests at the same time.

3.4.1 Examples

a. If a request requires concurrent testing, a synchronization timer can be added under the request.

1. Create a new test plan, add 2 samplers under the thread group (set 10 thread groups, load time 1s) to access the blog garden home page (disabled), and visit Du Niang, as shown in the following figure:

2. Then add a synchronization timer, set the number of simulated user groups: 10, and the timeout time: 5000, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results (almost at the same time, 10 users concurrently access Duniang), as shown in the following figure:

 

b. If several requests need to be concurrent, a synchronization timer can be added at the same level of the request.

1. Create a new test plan, add 2 samplers under the thread group to visit the homepage of the blog garden and visit Du Niang, as shown in the following figure:

 

 

2. Then add a synchronization timer, set the number of simulated user groups: 10, and the timeout time: 5000, as shown in the following figure:

 

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results (the sampler visits the homepage of the blog garden and the interval between visits to Duniang is 3s), as shown in the following figure:

 

 

c. If several threads need to be synchronized and concurrent, a synchronization timer can be added under the test plan (the thread group is at the same level) (applicable to multi-service mixed concurrent tests).

1. Create a new test plan, add a synchronization timer, set the number of simulated user groups: 10, and the timeout time: 5000, as shown in the following figure:

 

 

2. Then add two thread groups. Add 2 samplers under one thread group to access the blog garden homepage and visit Du Niang, and add 1 sampler to visit Du Niang 1 under the other thread group, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results, as shown in the following figure:

 

3.5BeanShell Timer (important - commonly used)

Bean Shell timers, as the name implies, alternate with each other, and the samplers under its nodes are executed alternately. According to the number of executions triggered by the controller, execute the child nodes <logic controller, sampler> under the controller in sequence. Triggered execution can be triggered by the number of threads in the thread group, the number of loops, and the logic controller.

1. Let's take a look at what this Bean Shell timer looks like. Path: Thread Group > Add > Timer > Bean Shell Timer , as shown in the following figure:

 

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Reset Interpreter: Whether to reset the parser for each iteration, the default is false; it is recommended to set it to true in long-running scripts.

Parameters: Input parameters of the BeanShell script. The input parameter can be a single variable; it can also be an array, if it is a string array, the two elements are separated by a space; it can also be a constant.

File Name: BeanShell scripts can read from script files.

Script: Write the BeanShell script directly in the Script area.

3.5.1 Examples

1. Create a new test plan, add 2 samplers under the thread group to visit the homepage of the blog garden and visit Du Niang, as shown in the following figure:

 

2. Then add the Bean Shell timer, and the script code sets the delay time to 5s, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the result tree (the sampler accesses the homepage of the blog garden and the interval between visits to Duniang is 5s), as shown in the following figure:

 

4. Summary

   Well, all the timers of JMeter have been introduced here today, thank you for your patient reading and learning.

Guess you like

Origin blog.csdn.net/ZangKang1/article/details/124275057