JMeter – JSR223 Timer

JSR223 Timer is a scripting-based timer of JMeter. JSR stands for Java Specification Requests. As same as BeanShell timer which we discussed earlier; when you need to implement the thread delay logic by yourself using one of the supported scripting languages like Groovy, BeanShell, java, javascript, jexl etc. then you can use the JSR22 timer. Usually, it is helpful when you need to define think times based on some unique algorithm which is not currently provided by JMeter. You can create your own implementation of the algorithm using the JSR223 timer. The simplest groovy code that could be written in the JSR timer is “return <delay time>” where the delay time is in milliseconds.

Example: return 5000

How to add ‘JSR223 Timer’?

Follow the below steps to add JSR223 Timer:

  1. Select the appropriate element where you want to add the timer
    1. Test Plan
    2. Thread Group
    3. Controller
    4. Sampler
  2. Right-click on the element
  3. Hover the mouse over ‘Add’
  4. Hover the mouse over ‘Timers’
  5. Click ‘JSR223 Timer’
Figure 01

What are the inputs of the ‘JSR223 Timer’?

‘JSR Timer’ has the following input fields:

  1. Name: To provide the name of the timer
  2. Comments: To provide arbitrary comments (if any)
  3. Language: To choose a scripting language.
  4. Parameters: Parameters to pass to the script. This is an optional attribute.  
  5. Script file: A file containing the script to run. The return value is used as the number of milliseconds to wait.
  6. Script compilation caching: Unique String across Test Plan that JMeter will use to cache the result of script compilation if the language used supports a Compilable interface (Groovy is one of these, Java, BeanShell and javascript are not)
  7. Script: The manual script which contains the logic to generate think (delay) time. The return value is used as the number of milliseconds to wait.

Recommendation: It is recommended to use JSR223 timer elements and Groovy as a language for any scripting. Groovy scripting is as fast as Java while BeanShell and JavaScript need to be interpreted, which causes some performance overhead.

Additional Information:

  • JSR223 timer is processed before each sampler in the scope in which it is found; if there are several timers in the same scope, all the timers will be processed before each sampler.
  • Timers are only processed in conjunction with a sampler. A timer which is not in the same scope as a sampler will not be processed at all.
  • To apply the timer to a single sampler, add the JSR223 Timer as a child element of the sampler.
  • To apply the timer after a sampler, either add the JSR223 Timer as a child element of the next sampler or as a child element of Flow Control Action.

You may be interested:


Leave a Comment