Jmeter - Counter Config Element With Example

Apache JMeter has many different configuration elements and counter is one of the configuration element of JMeter. Counter config element allows you to set a counter and then you can use it's reference anywhere in your thread group of your software load test plan. Let's understand how to add and configure counter in your software load test plan.

Add Counter In Test Plan
You can add counter under Thread Group, Controller or Request as per your requirement. Let's add it under Simple Controller. To add counter under simple controller of your software load test plan,
  • Right click on Simple Controller.
  • Select Add -> Config Element -> Counter. as shown in bellow image.

It will add counter under simple controller.

Parameters of Counter Config Element
Counter config element has many different parameters as shown in bellow image. You can set them as per your requirement.

  • Start : It represents the starting number of counter during first iteration.
  • Increment : It represents how much you wants to increment counter after iteration. 
  • Maximum : Maximum how much counter can increase. Once reach on maximum, It will be reset.
  • Format : This is optional field. i.e. 0000 will format as 0001, 0002 etc.
  • Reference Name : Reference name of this counter to use it in other elements. If set Count as reference name then you can use it as ${Count} in other elements.
  • Track Counter Independently for each User : If check this checkbox then each thread get its own counter during iterations. Means each thread gets independent count.
  • Reset counter on each Thread Group Iteration : If you wants to reset count of counter at the end of iteration then you can set it true.
Using Counter In Software Load Test
To see how counter config element actually works, Let's see practical example.

Scenario : I have prepared test plan with one request "News Page" as shown in bellow image. I wants to set delay of 1 second and it should increase by 1 second on every iteration. Max delay should increase till 5 seconds.

We will use counter to increase delay time count on each iteration and use Constant Timer to set delay. Constant Timer use use Reference Name of counter as Thread delay.
  • Thread Group Config

Thread group properties are as shown in above image. I have set Number of Threads = 1 and Loop Count = 6 iterations.

Counter and Constant Timer config are as bellow.
  • Counter Config

You can see that i have set Start = 1000, Increment = 1000 and Maximum = 5000. So counter will start with 1000 and it will increment 1000 on each iteration. We will use Count reference name in constant timer's thread delay textbox as shown in bellow image.
  • Constant Timer Config

During 1st iteration thread delay will be 1000 millisecond, During 2nd iteration thread delay will be 2000 millisecond, and so on. So at the end of each iteration, thread delay will increase by 1 second till max 5 seconds.

When you run test, result will looks like bellow.


You can see that Start Time difference between 1st and 2nd sample request is nearest 1 second(Exclude Sample time of 1st request in time difference calculation. i.e. Delay = 09:35:34.341 - 09:35:32.631 - 0.709 = 1 second.).

This is just example of counter config element to show you how it works. You can use it with any other elements of your software load test plan.

2 comments:

  1. Thank you for sharing this valuable information. One of my friend doing jmter testing, training through "Seleniumlabs" online training course provider. Your information will help him to improve knowledge.

    ReplyDelete
  2. your blog with simple but accurate example is easy to operate and understand for others.
    I am looking forward to your upcoming tutorials about Jmeter. Hopefully, there will be an example to test login with different users(I have a problem that everytime I login with a new user, the tocken is changing accordingly)

    ReplyDelete