How to use Timers in JMeter? Types of Timers, When to use, Practical Hands On Exercise

JMeter sends the requests to the server without any delay between them, by default. However, when a user is using an application in real life, this never happens. When a user visits a website, they take some time to think and look around before clicking on links. This is actual user behavior.

Timers in JMeter are a group of elements, which can simulate the actual user behavior in such cases by adding time delay between user requests to server.

If you create too many requests to a web server without any delay between them, it will be similar to a Denial of Service attack and the server will go down (crash). JMeter timers can be used to avoid such scenarios and create performance tests that more realistic.

Some of the Timer in JMeter are listed below.JMeter_Timers_Tutorial_Windows

You can apply a timer to a single sampler by adding the timer as a child element of the sampler. Before a sampler is processed, any timers which are in the same scope are processed.

Constant Timer

Constant timer is used to pause the same amount of time between requests in a thread.

For example, you can set constant timer to 300ms as shown below.JMeter_Constant_Timer_tutorial

JMeter will now add a 300ms delay between each request to the server.JMeter_Constant_Timer_Tutorial_Windows

Uniform Random Timer

Uniform Random Timer delays each request thread for a random amount of time. The chances of occurrence of the amount of delay is the same. The sum of the random value and the constant delay offset is the total delay applied by the Uniform Random Timer.JMeter_Uniform_Random_Timers_Tutorial

For example, in above setting JMeter creates a random value within 100 milliseconds and adds a constant delay offset (minimum delay) value of 2 milliseconds.

BeanShell Timer

JMeter can generate a delay using BeanShell Timer. BeanShell is a Java Source Interpreter, which executes standard Java syntax. This means you can write a script code to generate the delay as per your needs.

The below figure shows a sample BeanShell Timer script.JMeter_BeanShell_Timers_Tutorial

Gaussian Random Timer

Gaussian random timer delays each user request for a random amount of time. It uses the Gaussian distribution function to generate the timer value.


Some parameters you should know about

Property Description
Deviation Deviation in milliseconds
Constant Delay Offset Number of milliseconds to pause in addition to the random delay

BSF Timer

It is the same as BeanShell Timer. JMeter generates the time delay using BSF scripting language.JMeter_BSF_Timer_tutorial

Practical hands on exercise with Timers in JMeter

In this example, you will use Uniform Random Timer to set random delay between user requests to

Let start with a simple test scenario

  • JMeter creates one user request to 50 times
  • Delay between each user request is a random value within 100 milliseconds

Step 1. Create HTTP Request

Create a Thread Group. Configure the Thread Group as shown below, we will simulate one user sending a request to Google’s server 50 times.JMeter_Uniform_Random_Timers_Tutorial_Step2

Create a HTTP Request sampler as explained in previous topics.JMeter_Uniform_Random_Timers_Tutorial_Step1

Step 2. Create Uniform Random Timer

Right click on Thread Group and choose Add > Timer > Uniform Random TimerJMeter_Uniform_Random_Timers_Tutorial_Step3

Configure the setting in the Uniform Random Timer as shown below.JMeter_Uniform_Random_Timers_Tutorial_Step4

This means that we are setting the timer delay to a random value within 100 milliseconds with 0 delay offset, in this exercise. In case you want at least a minimum of 2 seconds delay (for example) between each request, you can set the constant delay offset to 2000.

Step 3. Add Listener

Right click Thread Group and choose Add > Listener > View Results in TableJMeter_Uniform_Random_Timers_Tutorial_Step5

The View Results in Table listener will displays the details as shown in the figure below.JMeter_Uniform_Random_Timers_Tutorial_Step6

Some of the parameters from the listener are explained below.

Name Description
Sample # Sample Number
Start Time The time when request is sent
Thread Name Name of the thread
Label User request type
Sample Time Time to finish a request
Status Request’s status (success or fail)
Byte Request’s size
Latency Measure of time delay

Step 4. Run The Test Plan

Now click the Run button on menu bar to run see the test. JMeter_Uniform_Random_Timers_Tutorial_Step7

Let us analyze the result of test, check the sample #1 to #12

Sample 1

  • Start time is 11:19:55.195
  • Sample Time is 134 (ms)

Sample 2

  • Start time is

The Time delay between samples 1, 2 is

  • The Time delay (1): 422 – 134 – 195 = 93

Do similar above formula with remain samples we have

  • The Time delay (2): 625 – 105 – 422 = 98
  • The Time delay (3): 793 – 117 – 625 = 51
  • The Time delay (4): 897 – 100 – 793 = 4

As you see, the Time Delay between each samples is random value within 100 as we set it.

Now you have learnt how to use Timers in JMeter, you can download and experiment with the sample JMeter Timer Test Plan with all the setting used in this practice exercise.

In the next topic you will learn how to use Assertions in JMeter.