Counter

JMeter – Counter

This article will give you a brief introduction to the crucial element of JMeter Config known as “Counter” and show you how to use it in different situations. In JMeter, the counter element allows users to create incrementing numbers that can be used anywhere in the thread pool. For example, if you need to pass a separate number for each iteration, you can use a counter to generate an incrementing number for each individual user (thread) during each iteration.

A performance tester can configure a baseline, maximum, and increment value using the counter configuration element. It repeats this process until the specified initial number reaches the maximum before starting again.JMeter - Counter

What applications do ‘Counter’ elements have?

You can use the “Counter” config element to:

  • to create a special number for the test
  • To determine the number of successfully submitted orders
  • You may also supply $__time(ddhhmmssSSS) in Start as a loop incrementer to create a unique value in time format for each iteration.

How to add ‘Counter’ in the JMeter script?

Follow the below steps:

  1. Select the ‘Test Plan’ node
  2. Right-click on the ‘Test Plan’ node
  3. Hover the mouse on ‘Add’
  4. Hover the mouse on ‘Config Element’
  5. Click ‘Counter’
JMeter - Counter - Adding

input fields of ‘Counter’

  1. Name: To provide the Counter name
  2. Comments: To provide comments (if any)
  3. Start : The starting number for the counter. The counter will equal this number during the first iteration.
  4. Increment: How much to increment the counter after each iteration
  5. Maximum: This is the maximum number till that if the counter reaches, then it is reset to the Start value.
  6. FormatThis is an optional field. It denotes the format of the counter e.g. 000 will format as 001, 002, etc. This is passed to decimal format so any valid formats can be used. If there is a problem interpreting the format, then it is ignored.
  7. Reference NameThis controls how you refer to counter values in other elements. The syntax is as in user-defined values: $(reference_name}. Example: ${testCounter}
  8. Track Counter Independently for each User: If you checked this option (when a counter is global) then each thread (user) will have an independent counter starting from the Start value. If it is unchecked then the unique value will be assigned to each user (i.e., user #1 will get the value ” 1 “, and user #2 will get the value ” 2 ” on the first iteration).
  9. Reset counter on each Thread Group Iteration: This option is only available when the counter is tracked per User, if checked, the counter will be reset to the Start value on each Thread Group iteration. This can be useful when the Counter is inside a Loop Controller.

JMeter’s counter() function returns a number that increases by 1 each time it is called, and it is also available in Apache JMeter. 

__counter(argument 1, argument 2) is the syntax.

Argument 1: There are two potential inputs.

When each thread (user) has a separate counter, it is true.

False: The same counter is shared by all threads.

Argument 2: The name of the variable to be used to hold the outcome.

__counter(True,myCounter) is an example.

The function should not be placed under any iteration provider, such as a Loop, While, or ForEach Controller, as this will cause numerous hits and unreliable results.

It should be noted that the counter uses an integer variable to store the count, giving it a maximum value of 2,147,483,647.

Scroll to Top