Jmeter series-Basic introduction to timers (11)

Introduction

The timer (Timer) in JMeter is an important component used to simulate scenarios where users send requests at different time intervals. By using timers, you can simulate how often requests are sent under different conditions such as load, concurrency, and capacity.

Use timer

  • You can add a timer under the sampler , so that the timer will only act on the current sampler
  • You can also add multiple timers under the thread group , count the sum of the timers, and then act on all samplers under the thread group

Timer scope

  • The timer is executed before each sampler (sampler), not after (regardless of whether the timer position is before or below the sampler);
  • When executing a sampler, all timers in the current scope will be executed;
  • If you want the timer to only apply to one of the samplers, add the timer as a child node;

Timer introduction

Insert image description here

1. Fixed timer

Insert image description here
1. If you need to make each thread pause for the same specified time before requesting, you can use this timer; it should be noted that the delay of the fixed timer will not be included in the response time of a single sampler, but will be included in the transaction. controller time.

2. The fixed timer is placed under the thread group and its scope is that all requests will be delayed by the time set by the fixed timer. If it is placed within the request, the scope is the delay time of a single request (commonly used).

3. For the "java request" sampler, the timer is equivalent to pacing in loadrunner (the interval between two iterations);

4. For the "transaction controller", the timer is equivalent to the think time in loadrunner (thinking time: in actual operation, simulates the waiting time of real users during the operation).

2. Unified random timer

Insert image description here
The delay time it generates is a random value, and the probability of each random value appearing is equal. The total delay time is equal to a random delay time plus a fixed delay time. The user can set the random delay time and the fixed delay time.

Total delay time = random time within the specified range + fixed delay time.
Insert image description here

andom Delay Maximum(in milliseconds): The maximum time unit of random delay in milliseconds. For example, I set it to 1000ms here.

Constant Delay Offset (in milliseconds): fixed delay time unit milliseconds, I set it here to 2000ms

Then the total delay time range is a value between 2000 milliseconds and 3000 milliseconds.

3. Precise Throughput Timer

Insert image description here
Timer used to control throughput. Similar to Constant Throughput Timer, but can control requests more accurately. The difference is that Constant Throughput Timer sets a timer based on time (sends a request when the number of seconds is reached); Precise Throughput Timer sets a timer based on throughput (sends a request when the amount reaches a certain amount). That is to say, the speed and number of requests can be controlled.

Parameter introduction
Delay threads to ensure target throughput

  • Target throughput (in samples per “throughput period”): The TPS expected to be tested can be accurate to multiple decimal places (but the final report will only have 1 decimal place)
  • Throughput period (seconds): How many seconds to execute the TPS test (because the TPS unit is seconds, 1 second is used here)
  • Test duration (seconds): test duration, just keep it consistent with the value of the previous thread group

Batch leave

  • Number of threads in the batch (threads): refers to how many threads are prepared to initiate requests together (ie, the rendezvous point), and the value is consistent with TPS (if TPS is Decimal, then round up here)
  • Delay between threads in the batch (ms): Delay time between the first batch and the second batch; the default is sufficient

Set up to ensure repeatable order

  • Random seed (change from 0 to random): non-0 random seeds can be repeated; 0 cannot be repeated, and the default is enough

4. Constant Throughput Timer

Insert image description here
You can let JMeter execute at a specified number of throughput (that is, specify TPS). Note that this requires specifying the number of executions per minute, not per second. It is very practical to control the pressure on the server. For example, if you know the maximum number of threads the server can handle per minute, you need to conduct a long-term fatigue strength test on the server.

Calculate Throughput based on has 5 options, namely:

  • this thread only : Control the throughput of each thread. When this mode is selected, the total throughput = Target throughput * number of threads.

  • all active threads : The set Target throughput will be allocated to each active thread, and each active thread will wait for a reasonable time after the previous run ends before running again. Active threads refer to threads running at the same time.

  • all active threads in current thread group : The set Target throughput will be allocated to each active thread in the current thread group. When there is only one thread group in the test plan, this option has the same effect as the all active threads option.

  • all active threads (shared) : Basically the same option as All active threads, the only difference is that each active thread will wait a reasonable time after all active threads have finished running before running again.

  • all active threads in current thread group (shared) : Basically the same as All active threads in current thread group, the only difference is that each active thread will wait a reasonable time after the previous run of all active threads to run again.

5. JSR223 Timer (JSR223 Timer)

JSR timer, in the latest version of jemter, this timer has been added. It can be understood that this timer is equivalent to the "parent set" of the BeanShell timer. It can be implemented using multiple languages ​​​​such as java, JavaScript, and beanshell. What you hope to accomplish.
Insert image description here
Parameter Description

  • Language: Select script language;
  • Parameters (parameters: String/String[] type parameters): parameters passed to the script;
  • Script file: script file path. After the script is executed, the return value is the timer delay time (unit: milliseconds);
  • Script compilation caching (if available): If the language used supports compilable interfaces (Groovy is one of them, Java, BeanShell and javascript do not), JMeter will cache the script compilation using a unique string across the test plan result.
  • Script: Manually write scripts.

use
Insert image description here
Insert image description here

6. Synchronizing Timer

Insert image description here
Synchronization timer is used to simulate multi-user concurrency, or more strict concurrency scenarios.

It is used to set the rendezvous point, block threads, and synchronize virtual users until the specified number of threads is reached, execute tasks at the same time, and then release them together, which can create a lot of pressure in an instant.

Note: In general, the synchronization timer is written as much as the number of concurrent users. (The number of concurrency depends on how many people have arrived to release it together.

Parameter Description

Number of Simulated Users to Group by(模拟用户组数量):
集合点个数 (执行的线程数),如果设置为0,等于设置为线程租中的线程数量。 
 
Timeout in milliseconds(超时时间):
指定线程数多少秒没集合到算超时(以毫秒为单位),默认为0。
如果设置为0,该定时器将会等待线程数达到了 "模拟用户组数量" 中设置的值才释放,不够的话就死等。
如果大于0,那么如果超过 "超时时间" 中设置的最大等待时间后还没达到 "模拟用户组数量" 中设置的值,Timer 将不再等待,释放已到达的线程。

(1)上面两个参数如果都设置了值,则在实际中是哪个条件先达到,定时器先执行哪个,如第一个参数释放线程数量先达到,则不会管超时时间的值,timer 会释放;如果第二个参数超时时间先达到,则不会再等线程数量,按照目前超时的时间点集合的线程数,timer 释放。 
(2)同步定时器(Synchronizing Timer)的超时时间设置要求: 超时时间 > 请求集合数量 * 1000 / (线程数 / 线程加载时间)

7. Poisson Random Timer

Insert image description here

This timer pauses at random intervals before each thread request. Most of the time intervals occur at a specific value. The total delay is the sum of the Poisson distribution value and the offset value.

The above indicates that the pause time will be distributed between 100 and 400 milliseconds:

(1) Lambda (in milliseconds): Lambda value (in milliseconds);

(2) Constant Delay Offset (in milliseconds): Fixed delay offset (in milliseconds), the number of milliseconds of pause minus the number of milliseconds of random delay.

8. Gaussian Random Timer

Insert image description here

Gaussian timer, generates a Gaussian distributed time interval.

If you need the delay time of each thread to be a random time pause that conforms to the standard normal distribution, then use this timer, the total delay = Gaussian distribution value (average 0.0 and standard deviation 1.0) * specified deviation value + fixed delay offset ( Calculation reference: Math.abs((this.random.nextGaussian() * deviation value) + fixed delay offset)).

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

Parameter Description

  • Deviation: Deviation value, which is a floating range;
  • Constant Delay Offset: Fixed delay time.

9. BeanShell Timer

Insert image description here

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

Parameter Description

Reset Interpreter(重置解释器):
每次迭代是否重置解析器,默认为 false;在长时间运行的脚本中建议设置为 true。 
 
Parameters(参数:String 或者 String[] ):
BeanShell 脚本的入参。入参可以是单个变量(字符串);也可以是(字符串)数组,若是字符串数组,两个元素之间用空格隔开;也可以是常量。 
 
File Name(文件名):
BeanShell 脚本可以从脚本文件中读取。 
 
Script(脚本):
在 Script 区直接写 BeanShell 脚本。

Demo
Insert image description here
Insert image description here

Reference article

Guess you like

Origin blog.csdn.net/m0_62091240/article/details/132919255