Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set counter of loop inside loop correctly inside jmeter?

I have jmeter flow like this:

ThreadGroup
--Sampler to get the number of items and store to vars("numItem",XYZ)
--LoopController on $numItem
-----Sampler to get number of subItem and store to vars("numSubitem", ABC)
-----LoopController on $numSubitem
-----LoopCounter
-----Sampler: print out the current counter from loopCounter

For example, the number of item = 2 and subItem = 10, my loopCounter print out will be 0 - 19. I have checked the checkbout "Track counter independently for each user" but it doesn't affect because this is the same thread. Is there a way to make the counter count 0 - 9 and then 0 - 9.

Thanks,

like image 490
Sean Nguyen Avatar asked Mar 30 '12 19:03

Sean Nguyen


People also ask

What is loop count =- 1 in JMeter?

Definition of JMeter Loop Count. JMeter provides different types of functions to the user, in which that loop count is one of the functions that is provided by the JMeter. Basically, loop count means we can set the number of iterations for every user as per our requirement.

How do you use a counter loop?

You just need to a) initialize the counter before the loop, b) use & instead of and in your if condition, c) actually add 1 to the counter. Since adding 0 is the same as doing nothing, you don't have to worry about the "else".

What is loop count in thread group JMeter?

Loop Count: You can set the number of iterations for each user in the group using Loop Count. For example, the above configurations with: Number of threads: 10, Ramp-Up period: 10 seconds and Loop Count: 1 means that JMeter will take 10 seconds to get all the 10 threads up and running.


1 Answers

In your example you can define additional var maxCount = subItem - 1 and set it as value of "Maximum" field for "Counter" instance, as shown below:

In sampler where numSubitem is set (before 2nd loop):

int numSubitem = 10;
int maxCounter = numSubitem - 1;
vars.put("numSubitem",Integer.toString(numSubitem));
vars.put("maxCounter",Integer.toString(maxCounter));

I've used Beanshell Sampler for test, you can use Beanshell Postprocessor, e.g.

In Counter instance:

enter image description here

So counter will iterate as in your description.

like image 78
Aliaksandr Belik Avatar answered Sep 21 '22 23:09

Aliaksandr Belik