Showing posts with label jmeter. Show all posts
Showing posts with label jmeter. Show all posts

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

Wednesday, November 12, 2014

Run JMeter in command line

There are use-cases where you can't use JMeter GUI to run the script.

Eg :- during distributed JMeter load testing, run jmx from a remote machine (just using command line)

Following are the steps which I followed to run JMeter script in command line.

1. Create JMeter script in your local machine.(yes, using the GUI ;) )
2. Setup JMeter in the remote machine.
  •  SCP apache-jmeter-X.XX.zip and created jmx in step 1.
3. Access remote machine using command line. (ssh ;))
4. Move and setup apache-jmeter-X.XX.zip and jmx according to your preference.

I have extracted  apache-jmeter-X.XX.zip inside my home directory(remote machine) and able to move to bin directory using,
cd /home/udara-aws/apache-jmeter-2.11/bin
Copied test.jmx script in to the same location.

Lets run this script in command line now.
sh jmeter.sh -n -t test.jmx -l log.jtl
Here we have used -n -t and -l arguments.

-n denotes –nongui run JMeter in nongui mode
-t denotes –testfile  jmx file which needs to run
-l denotes  –logfile file to put sampler logs (jtl)

Following is the output I got, If you are not getting summery results make sure to attach "Generate Summary Results" listener to relevant samplers.

udara@udara-aws:~/apache-jmeter-2.11/bin$ sh jmeter.sh -n -t test.jmx -l log.jtl
Creating summariser <summary>
Created the tree successfully using test.jmx
Starting the test @ Tue Nov 11 19:29:28 UTC 2014 (1415734168842)
Waiting for possible shutdown message on port 4445
summary +      1 in   3.3s =    0.3/s Avg:  3324 Min:  3324 Max:  3324 Err:     0 (0.00%) Active: 1 Started: 1 Finished: 0
summary +      6 in   4.1s =    1.5/s Avg:   676 Min:   124 Max:  1756 Err:     0 (0.00%) Active: 0 Started: 1 Finished: 1
summary =      7 in     8s =    0.9/s Avg:  1054 Min:   124 Max:  3324 Err:     0 (0.00%)
Generate Summary Results for list APIs =      1 in   1.1s =    0.9/s Avg:  1065 Min:  1065 Max:  1065 Err:     0 (0.00%)
Generate Summary Results for List Subscriptions =      1 in     1s =    1.6/s Avg:   637 Min:   637 Max:   637 Err:     0 (0.00%)
Tidying up ...    @ Tue Nov 11 19:29:36 UTC 2014 (1415734176890)
... end of run