JMeter can be
used to load test web application and Web services (SOAP/REST). Following steps
and screenshots will help you configure JMeter (assuming you have JRE installed
and class path set)
For Website with a typical scenario of
opening a homepage and logging in using username/pwd, the following steps needs
to be done.
a) Add the “Thread group” (virtual
users). Ramp up time is – It will take that amount of time to load specified
max. number of the threads (users). Example – 100 users in 5 seconds.
b) Add “Http Request Default” to set the
server name and port etc (information which is independent of the other steps)
c)
Add
“Http Cookie Manager” if your site uses cookies.
d) Add the step to open the homepage.
(HTTP Request)
e) For a site which uses anti-forgery
token, we need to retrieve the token from the hidden field. This can be done
using the Regular Expression Extractor on the response of the step-d.
f)
Add
the step to login. (HTTP Request) with the form fields. The form fields could
be found using fiddler, (if not already known).
g) For results, add “View Result Tree”
and “Aggregate graph”.
h) Press Ctrl + E to clear the results.
For web
services, similar setup needs to be done (no need of “HTTP cookie manager”).
Instead of “HTTP Request”, we add the “SOAP/XML-RPC Request” where we specify
the full request body (SOAP) .
Then we add
the “HTTP Header Manager” (to pass soap action and content type) and “Response Assertion” to check the response
value and compare.
Below are the links to JMeter files (jmx files) for load testing web sites and webservices
JMeter file for Webservice loadtesting
--------------------------------------------------------------------------------------------------
Example of simple regular expression extractor –
--------------------------------------------------------------------------------------------------
Example of simple regular expression extractor –
Case – when you need different input for each request.
You can use
CSV data config element as shown below –
Jmeter
when asked to run more than 500 threads can crash because the default heap size
can be exceeded. This can be fixed by starting jMeter (inside jMeter.bat) with a
high heap size (upto 80 % of system’s RAM).
Below,
I have commemted default settings and added new (for a 32GB RAM machine) –
rem
set HEAP=-Xms512m -Xmx512m
set HEAP=-Xms22528m -Xmx22528m
jMeter
when used in GUI mode can take lot of resources. You can use the following
command line to run jMeter in non-GUI mode.
C:\Apache-Jmeter-2.13\bin>jmeter
-n -t "C:\MyDir\MyJMX.jmx" –l "C:\MyDir\Results\resultsfile.jtl"
To
jMeter running in non-GUI mode, run stoptest/shutdown.cmd in a separate command prompt.
The
resulting jtl can be opened in jMeter by adding listeners like “View Results
tree”, “Aggregate graph” and clicking on “browse” button to load the jtl file.
By
default in the non-GUI mode, the request and response are not logged. To enable
this, you have add a few options to the jMeter command line.
C:\Apache-Jmeter-2.13\bin>jmeter
-Jjmeter.save.saveservice.samplerData=true
-Jjmeter.save.saveservice.response_data=true
-Jjmeter.save.saveservice.output_format=xml -n -t " C:\MyDir\MyJMX.jmx " -l
" C:\MyDir\Results\resultsfile.jtl "
Using
jMeter for a flat load of (say 20 users) for 20 mins can be done using
scheduler as shown below.
This
is needed for soak test.
Remember – A system can touch a peak load of 1000 users without any errors but
when subjected to a low load (of 20 users) but for several minutes can take the
system down.