JMeter Tutorial: How to use JMeter Timers

Which timer should you use in JMeter, and how to use them effectively

Timers are one of the simplest, yet most powerful tools in the arsenal 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 tutorial, 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.  Topics covered here:

  1. What is a JMeter Timer?
  2. Why user a JMeter Timer?
  3. Which JMeter Timer should I use?
  4. How to use a JMeter Timer?

1. What is a JMeter Timer?

A JMeter Timer is a built in plug in tool for JMeter that can help with spacing out your samplers requests.  Many testers call this gap in requests “think time”, simulating the time that real users spend in between each step in a real world scenario. By default, each request in JMeter is made immediately after the another if there isn't a Timer set. With a JMeter timer, users can use a static or random time to separate requests.  

2. 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 by using 100 users. We would use a Constant Throughput Timer so each user sends a request every 500 milliseconds or 120 RPM each thread. This will achieve the 200 requests per second target as long as the response time is less than 500 ms if the response time is higher than 500 ms we won't achieve that scope.

3. Which JMeter Timer Should I Use?

Built into JMeter, there are 9 different types of timers available:

Each timer has a different application, which we have outlined 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:

Uniform Random Timer:  One step above the basic timer, this 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 to it:

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 (essentially a target # of requests per minute/second) and the timing of the threads is set to most closely match that.  

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:

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:

JSR223 Timer: The JSR223 Timer is the most flexible, but requires coding in a language like bean shell, javascript, or groovy to create your custom function.  Essentially, the JSR223 timer will run whatever code you script in that language:


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:

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:

Bean shell Timer: The Bean shell Timer is similar to the JSR223 timer, however, is only supports scripts written in bean shell as a customer timer:

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

Conclusion: JMeter Timers are Simple, yet Powerful Tool

JMeter Timers are something that every load testing expert uses to create a realistic simulation of their scenario.  Knowing which timer to use and how to apply it will help you on the path to creating awesome load tests.  For more information on getting started with JMeter, make sure to check out our getting started guide for JMeter.

Start load testing now

It only takes 30 seconds to create an account, and get access to our free-tier to begin load testing without any risk.