JMeter Timers: Constant, BeanShell And Guassian Random Timer

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated March 7, 2024

In this tutorial, you will learn how to use JMeter Timers to increase the time between the subsequent requests to avoid server overloading:

Requests which are sent to the server go without any interval. If a large number of requests are sent in a short span of time, i.e. in few seconds, it will overload the web server.

Timers are the solution to avoid server overloading as they give the option to delay requests between the multiple user requests.

Timers also help manage real-time scenarios as in real-time also the load on the server does not come at the same time.

=> Click here for The Complete Free Training On JMeter (20+ Videos)

JMeter Timers

Video Tutorial On JMeter Timers

Timers are used to delay JMeter sending next request. If there are no timers, JMeter will send next request in fractions of seconds. Constant Timers are used to delay the next request by a constant time which you can configure by adding the value of constant delay time.

Gaussian and Poisson Random timer works on some mathematical calculations with lambda coefficient. You can add Constant Delay Offset and Deviation time and rest will be calculated automatically.

For Constant Delay Offset of 3000 ms and Deviation time of 300 ms, each thread of JMeter would execute after {3000+(0-300 ms (could be any value between 0-300 ms)}.

Some commonly used JMeter Timers are:

  1. Constant Timer
  2. Uniform Random Timer
  3. Precise Throughput Timer
  4. Constant Throughput Timer
  5. Gaussian Random Timer
  6. JSR223 Timer
  7. Poisson Random Timer
  8. Synchronizing Timer
  9. BeanShell Timer

How To Add JMeter Timers

Select the Test Plan and then go to Test Plan->Add->Timer and observe the list of all timer names available there. Selecting any of them will open the window for the same with their attributes.

Timers in Jmeter list

#1) Constant Timer

Constant Timers are used to delaying the request with a constant time span i.e. if there are multiple requests the next request will be sent to the server with the same delay.

Go to Test Plan->Add->Timer->Constant Timer

Same can be selected from Edit->Add->Timer as well.

The delay which is required between the requests can be specified in “Thread delay” which is in milliseconds. For example, Say a user has given 300 ms then every request will hit the server in an interval of 300 ms.

Constant Timer

Name: Name of the timer
Comments: If any can be provided over here
Thread delay (in milliseconds): The number will show the thread delay time in milliseconds.

#2) Uniform Random Timer

Uniform Random timer delays every request for the random intervals.

Two options are given for the same:

  1. Random delay in maximum (in milliseconds)
  2. Constant delay offset (in milliseconds)

Delay interval is the total of Random delay in maximum (in milliseconds) and constant delay offset time in milliseconds.

Uniform Random Timer

Name: Name of the timer
Comments: If any can be provided over here.

Thread Delay Properties:

  • Random Delay Maximum (in milliseconds): The number which the user provides here is the maximum number which can be added to Constant Delay offset.
  • Constant Delay Offset (in milliseconds): This number is the one which shows constant delay which in turn is added to the random number.

In the above image, user has chosen Random delay maximum as 100.0 and Constant delay offset as 0. Uniform random timers will get a random number between 0 and 100.

If it would have been 100 as Random delay maximum and 100 as constant delay offset, the random number generated would have been between 100 to 200.

#3) Precise Throughput Timer

Precise Throughput Timer allows the user to judge the throughput required for their tests to run. The user provides the samples per throughput period i.e. in hr/min/seconds.

Precise Throughput Timer

#4) Constant Throughput Timer

Constant Throughput timer is similar to Precise Throughput timer.

Constant Throughput Timer

Name: Name of the timer.
Comments: If any can be provided over here.

Delay before each affected sampler:

  • Target Throughput: Target throughput is the value that the user wants the timer to give or produce.
  • Calculate Throughput based on: It has 5 options as,
    • This thread only.
    • All active threads.
    • All active threads in the current thread group.
    • All active threads (shared).
    • All active threads in the current. thread group (shared)

Let us understand these options below:

This thread only: The throughput will be relative to the threads which are active. Threads will maintain the provided target throughput.

All active threads: The target throughput provided will be allocated to all the active threads in the thread group. Delay of threads will be dependent on the last thread run time. For other thread groups, constant throughput timer would be required.

All active threads in the current thread group: The target throughput provided will be allocated to all the active threads in the thread group. Delay of threads will be dependent on the last thread run time.

All active threads (shared): Delay of threads will be dependent on the last thread run time.

All active threads in the current thread group (shared): Delay of threads will be dependent on the last thread run time in the current thread group only.

#5) Gaussian Random Timer

Gaussian Random Timer delays the request for a random amount of time. This timer works on Normal or Gaussian distribution function.

Gaussian Random Timer

Name: It defines the Name of the timer.
Comments: If any can be provided over here.

Thread Delay Properties:

  • Deviation (in milliseconds): The number provided for deviation represents the deviation in delay provided in constant delay offset.
  • Constant Delay offset (in milliseconds): Constant delay offset number is the number which shows a constant delay to be added in random number generated.

In the above case Deviation (in milliseconds) provided is 100.0 and Constant delay offset (in milliseconds) is 300. As per the Gaussian random timer, the random number generated will be between 200 and 400 as the deviation is of 100 milliseconds.

#6) JSR223 Timer

JSR223 timer requires coding in languages like JavaScript, beanshell, jexl to create a custom function. Using the scripting language, delay time between the user requests can be generated.

JSR223 Timer

JSR223 Timer_02

#7) Poisson Random Timer

Poisson Random timer is similar to Gaussian Random timer. It provides delay time between the requests for a random interval of time. The total delay in time is the sum of both Lambda (in milliseconds) and Constant Delay offset (in milliseconds). Random number generation is based on Poisson distribution.

Poisson Random Timer

#8) Synchronizing Timer

Synchronizing Timer is different from other timers which we have gone through till now. It has only one parameter i.e. “number of simulated users to Group by”. The number provided in this parameter will be the number of threads it will wait for grouping and release.

For example, in case 30 is the number provided in the parameter “number of simulated users to group by” and the number of threads is 60, in that case, 2 groups of 30 threads will be released.

In case the number of simulated users to group by is more than the number of threads, then it will hang the test as the timer will not work.

Synchronizing Timer

Name: Name of the timer
Comments: To provide comments if any.

Grouping:

  • Number of Simulated Users to group by: This defines the number of threads to be grouped.
  • Timeout in milliseconds: This is the time in milliseconds.

#9) BeanShell Timer

With BeanShell timer, the user has to implement the delay logic by them using the script.

BeanShell Timer

Name: Name of the timer
Comments: To provide comments if any.

Attributes:

  • Reset bsh.Interpreter before each call: Interpreter will be recreated if the value of this option is selected as Yes.
  • Parameters: This is not mandatory to provide. User just need to provide the parameters which have to be passed to Beanshell
  • Script file: Script file is a file that contains a BeanShell script to run. The wait time is based on the return value and is calculated in milliseconds.
  • Script: It is a BeanShell script that is used to get the think time. The wait time is based on the return value and is calculated in milliseconds.

FAQs About JMeter Timers

Q #1) What are Timers in JMeter?

Answer: Timers play an important role in JMeter as timers help to delay the next request sent, else the requests will be sent to the server every fraction of a second and will overload the server. There are different type of timers available which makes it easier to work as per the requirement.

Q #2) What is a Uniform Random timer in JMeter?

Answer: Uniform Random timer delays consecutive requests for a random amount of time. Random time is calculated as the sum of value provided for “Random delay maximum” and “Constant Delay offset” in milliseconds.

Q #3) How do I add a delay between requests in JMeter?

Answer: Add constant timer is one way as the value provided in Thread Delay (in milliseconds) applies a delay of provided time before the execution of each of the threads.

Q #4) How can you add random thinking time to a JMeter test plan?

Answer: To add random thinking time to test plan- the user needs to right-click on the thread group and from there need to select the second option i.e. “Add think times to children”. Selecting the same will result in an addition of think time after each transaction. “Uniform Random timer” will be added as a child to “Test Action”.

Q #5) What is JMeter Sample?

Answer: Samplers are the requests which are sent to the server by JMeter. Different type of requests can be sent to the server. Sample results can be checked once the request is executed and the result shows attributes like Success/ Fail.

Samplers are added in thread Groups i.e. Test Plan->Thread Groups->Add->Sampler

Q #6) Which Assertion is not used in JMeter?

Answer: Assertions such as JSR223 and BeanShell which does not have GUI element i.e. are code-based cannot be used in JMeter.

Q #7) What is the thread delay in JMeter?

Answer: JMeter does not apply any difference of time for the execution of samplers in a thread which in turn overloads the server. Timers can be used to set the delay time between two consecutive requests to the server by adding any of the Timer to the thread group.

Q #8) What is a test fragment in JMeter?

Answer: Test fragment feature allows to write a script that can be multi used.

Q #9) What is the config element in JMeter?

Answer: Config element is the variables that are later used by samplers to modify the requests which were sent to the server.

Conclusion

JMeter Timers are very useful as they help the user to do load testing by creating realistic simulated scenarios. Key of using these timers is to have knowledge of when and how to apply the timers so that good results can be found while load testing.

The entire above discussed timers have their own behavior. Constant Timer is the basic timer that allows the requests to delay for provided constant time. BeanShell and JSR223 timers require a script to be written in any language JavaScript, groovy, or BeanShell script.

Gaussian Random Timer follows the Gaussian distribution method. Poission Random Timer has a random number generation based on Poission distribution.

<< PREV   |  NEXT >>

=> Click here for The Complete Free Training On JMeter (20+ Videos)

Was this helpful?

Thanks for your feedback!

Leave a Comment