Wednesday, November 19, 2014

JMeter Loop Controller & Counter


Why we need loop controller[1] in JMeter?
Assume you need to run the same HTTP request(sampler) multiple times, rather than creating duplicate samplers we can use this handy logic controller available in JMeter.

Eg:- Publish 1000 APIs to WSO2 API Manager, Benchmark web-server concurrent requests handle

Lets take the first sample scenario, We can create a HTTP request sampler which publishes API. (before that we need to create a HTTP request to login which is out of loop controller scope)

1. Create a Loop Controller using Add> Logic Controllers> Loop Controller,


2. Add a Counter to above Controller using, Add> Config Element> Counter,


 3. Create sampler(s) according to your requirement, here I'm creating Add API HTTP Request Sampler, (Add> Sampler> HTTP Request),



You can see I'm appending ${api_id} for some request parameter values. This value will be initialized and incremented within our Counter(step 2). In my scenario I can't publish multiple APIs with the same name & context.

I tried this loop 20 times by updating Loop Count and Maximum values to 20. You can see multiple "Add API HTTP Request" & "Publish API HTTP Request" sampler requests,


[1] http://jmeter.apache.org/usermanual/component_reference.html#Loop_Controller

No comments:

Post a Comment