Timers in JMeter

A JMeter Timer is a built-in plugin tool for JMeter that can help with spacing out your sample requests.

Many testers call this gap in requests to think time, simulating the time that real users spend in between each step they perform in a real-world scenario.

By default, each request in JMeter is made immediately after the other. With a JMeter timer, users can use a static or variable time to separate requests.

Timers are one of the simplest, yet most powerful tools in the range of any JMeter user. There are many types of timers available to meet the various scenarios you may be trying to simulate with JMeter.

Why use a JMeter Timer:

  • Timers will be useful in most of the JMeter scripts that you build, especially those that simulate real user activity.
  • Testing without a JMeter timer can provide inaccurate test results because the simulated requests will come in a different pattern than what is seen in a real-world situation.

For example : you may be interested in ensuring every single user can execute a specific number of requests per second so that you can hit a target minute, hourly, or daily transaction count.

In this case, we might want to test an API with 200 requests per second using 100 users. We would use a timer so that each user sends a request every 500 milliseconds. This will achieve the 200 requests per second target as long as the response time is less than 500ms.

Recordring Test Scripts in JMeter

Different Types of JMeter Timers

There are 9 different types of built-in Timers are available in JMeter :

  • Each timer has a different application, which we have listed here:
  • Constant Timer : The most basic timer, this will simply add a delay to the threads before they are initiated. The thread delay is a constant in milliseconds.
    constant-timers-jmeter
  • Uniform Random Timer : One step above the basic timer will set a constant delay (base) for each thread and then a randomly created delay will be added to that so each request has a unique timing associated with it.
    uniform-random-timer-jmeter
  • Precise Throughput Timer : The Precise Throughput Timer and the Constant Throughput Timer both work in reverse of most of the other timers. In these timers, the user sets the number of samples per throughput period and the timing of the threads is set to most closely match that.
    precise-throughput-timer-jmeter
  • Constant Throughput Timer : The Constant Throughput Timer is like the Precise Throughput Timer, except that it has fewer settings. Essentially, it sticks with a target throughput very closely, and doesn’t allow for the flexible variance of the Precise Throughput Timer:
    constant-throughput-timer-jmeter
  • Gaussian Random Timer : The Gaussian Random Timer follows a normal or gaussian distribution and allocates the users to a delay based on a constant and standard deviation.
    gaussian-random-timer-jmeter
  • JSR223 Timer : The JSR223 Timer is the most flexible, but requires coding in a language like BeanShell, javascript, or groovy to create your custom function. Essentially, the JSR223 timer will run whatever code you script in that language.
    jsr223-timer-jmeter
  • Poisson Random Timer : The Poisson Random time is similar to the Gaussian random timer, but this time distributes users in accordance with the Poisson distribution.
    poisson-random-timer-jmeter
  • Synchronizing Timer : The Synchronizing Timer acts quite differently than the other timers on the list. Essentially, it will wait until a certain number of threads have accumulated, and then group and release all of those threads at once.
    synchronizing-timer-jmeter
  • Beanshell Timer : The Beanshell Timer is similar to the JSR223 timer, however, it only supports scripts written in Beanshell as a customer timer.
    beanshell-timer-jmeter

How to Use JMeter for Performance Testing

How to Use a JMeter Timer

To help you understand how to use a JMeter Timer, we have created a repository with an example script including a basic timer. In this example, we have added a Gaussian random timer that will be added before kicking off any recorded thread group.

This is quite a basic example, there are many more complex ways to implement a JMeter Timer. Like any other element in a test plan, a JMeter Timer has a scope which will determine which samplers are impacted by the timer.

Make sure that if a timer is meant to only be applied to a single sampler, that it is added as a child element of the sampler as shown, to restrict the scope to only that sampler.

It is also worth noting that Timers will always be executed before any sampler that is in scope. Additionally, multiple timers will be run consecutively meaning all of the timers in scope will be executed before the sampler.

Thread Group Elements in JMeter

The Following Example Demonstrates the Constant Timer

  • Launch the JMeter in your system and then Add the Thread group to the default Test Plan. And Keep the Number of Threads, Ramp-up Period, and Loop count to 1.
    new-thread-group-to-constant-timer-jmeter
  • Now Save the Test Plan as shown below.
    new-project-constant-timer-jmeter
  • Next, add Sampler's request that is HTTP Request under the Thread Group.
    add-http-request-to-the-timer-jmeter
  • Enter the Server Name or IP as gmail.com and the path as/ which is nothing but a root page. and also name the HTTP request as HTTP Request1
    http-request1-jmeter
  • Now, copy and paste the HTTP Request1 to two times and change the name of the remaining two HTTP Requests as shown below.
    three-http-requests-jmeter
  • So we have a thread group which is having three HTTP Requests.
  • Next, add View Results in Table Listener.
    add-view-result-table-jmeter
  • Once again save and run the Test Plan, you will see the immediate response in the View Result in Table as shown below.
    response-in-view-reault-table-jmeter
  • We got the response in almost four seconds but in the realistic scenario we need to send each request and sometimes we need to add some time in-between each request.
  • We need to add a timer in the Thread Group level which will send each request with a given time.
  • Right-click on the Thread Group and select the Add-->Timer-->Constant Timer.
    add-constant-timer-jmeter
  • By default, the timer is containing Thread Dealy as 300, I am going to set this for 5000 mili seconds.
    set-constant-timer-jmeter
  • If you run the Test Plan, for every 5 seconds each request will be executed.
    view-result-tree-delay-time-jmeter
  • If you observe, the requests have been executed in almost 18 seconds including delay time.
  • The delay time can be added either in the Test Plan level or at the Sampler level. I am adding the constant timer in between the first request and the second request.
  • That means the first request will be executed after five mili seconds.
  • We have two constant timers Constant TimerA and Constant TimerB. Where Constant TimerA is at the Sampler level, and the Constant TimerB is at the Thread Group level.
  • So TimerB will be applied to each request and the TimerA will be applied to the first request.
  • The first request will execute after 10 mili seconds.
  • But the request2 and request3 will be executed after the 5 seconds each.
  • This is how the constant timer will help us to execute the request in a given time.

Thread Group in JMeter

Uniform Random Timer

  • Uniform random timer is used when you want to put some fixed but also some random time delay between 2 requests in your software load test plan.
  • The Uniform Random Timer will go one step above the basic timer will set a constant delay (base) for each thread and then a randomly created delay will be added to that so each request has a unique timing associated with it.
The following example demonstrates the Uniform Random Timer:
  • To explain the Uniform random timer I am using the Test Plan with Thread Group and the Three HTTP Requests.
  • Right-click on the Thread Group and then add Uniform Random Timer.
    add-uniform-random-timer-jmeter
  • The Uniform Random Timer has two important fields such as Random Delay Maximum and constant Delay Offset.
    thread-group-properties-jmeter
  • The Formula to calculate uniform random time is as below
    - 0.X*Random Delay Max + Constant Delay Offset
    Where X: 0-9
    Example: 0.X * 100+0
                   0-99 Mili Sec​
  • I am going to set the Random Delay Maximum to 5000 Ms and Constant Delay Offset to 3000Ms as shown below.
    set-random-delay-and-constant-oofset-jmeter
  • Now, save and run the Test Plan. You can see all three results.
    view-result-in-table-for-uniform-random-timer-jmeter
  • Now I am going to change the constant Delay Offset to 300 and number of user to 3 and run the Test Plan, you will find the difference in the execution.
  • Where the delay time is Random and we have given3 users so the 9 requests have been executed.
    view-result-in-able-with-9-request-jmeter
  • This is how we are going to use the Uniform Random Timer.
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions