Timers in JMeter

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.

In this article, we will cover the main types of timers that are available on the market, and provide examples of when and how to use these timers to improve your testing.

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.

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.

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 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.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions