Using Apache JMeter Load Testing Tool
Running JMeter
Running Remotely – Server Mode
Configuring JMeter
Building a Test Plan
Test Plan Elements – Thread Group
Test Plan Elements – Controllers
Test Plan Elements – Listeners
Test Plan Elements – Timers
Test Plan Elements – Assertions
Test Plan Elements – Configuration Elements
Pre and Post Processors
Execution Order
Element Scope
Web Test
Running JMeter
The scripts used to run JMeter can be found in the JMeter/bin install directory:
windows: jmeter.bat
unix: jmeter
There are JVM HEAP settings in the scripts that can be overridden by the JVM_ARGS environment variable, or alternatively edit the scripts themselves.
Running behind a firewall/proxy server
run the jmeter.bat/jmeter file from a command line with the following parameters:
-H [proxy server hostname or ip address]
-P [proxy server port]
-N [nonproxy hosts] (e.g. *.apache.org|localhost)
-u [username for proxy authentication - if required]
-a [password for proxy authentication - if required]
Example : jmeter -H proxyServer -P 8000 -u username -a password -N localhost
Example : jmeter -H 172.16.15.43 -P 8080
Example : jmeter –proxyHost proxyServer –proxyPort 8000 –username username –password password -N localhost
Running Remotely – Server Mode
You can run JMeter on a remote server and also choose to control the server using the GUI. To start the server, run jmeter-server/jmeter-server.bat on the server host.
This option is for when you wish to run JMeter from 1 or more remote machines, generally because you dont have a single machine that can simulate the size of the load you need. One instance of the JMeter GUI client can control any number of remote JMeter instances and collect all their data.
Configuring JMeter
If you wish to modify the properties with which JMeter runs you need to either modify the jmeter.properties in the /bin directory or create your own copy of the jmeter.properties and specify it in the command line
Building a Test Plan
A test plan is a series of steps that JMeter executes when run and will consist of 1 or more:
- Thread Groups
- Logic Controllers
- Sample Generating Controllers
- Listeners
- Timers
- Assertions
- Configuration Elements
You can add elements to a test plan by right-clicking (windows) on tree-element in the GUI and choosing “add” or loading from a file. Elements can also be removed by right-clicking.
You can also save elements in the tree by right-clicking on them and then either choosing “save” or “Save As” from the Edit menu. the elements is saved along with any of its child elements. This allows you to save individual tree elements, the whole tree, or even the whole test plan.
Running a Test Plan
Choose “start” from the “Run” menu – a small green box will be shown top right of the GUI when JMeter is running, along with the number of active/total threads.
Stopping a Test Plan
There are 2 stop commands in the GUI:
- Control + ‘.’ – stops threads immediately if possible and can interrupt samplers
- Contol + ‘,’ – requests threads stop at the end of any current work but does not interrupt samplers and the modal shutdown dialog remains active until all threads have stopped
In non-GUI mode JMeter listens for commands on a specific port (default 4445 – see property jmeterengine.nongui.port):
- Shutdown – graceful shitdown
- StopTestNow – immediate shutdown
These commands are sent using the shutdown[.cmd|.sh] or stoptest[.cmd|.sh] scripts respectively (bin directory)
Test Plan Elements - ThreadGroup
ThreadGroup
The start of any test plan, these control the number of threads JMeter uses to execute your test. All controllers and samplers must be under a thread group but some elements eg. Listeners, may be placed directly under the test plan, in which case they apply to all thread groups.
Each thread is used to simulate concurrent connections to your application, and each executes the test plan in its entirety and independently of other test threads.
There are 3 controls:
- no of threads
- ramp-up period – time taken to start all test threads – nneds to be long enough so that the work-load is not too large at the start but that the last threads begin before the first ones have finished
- no of times to execute the test -
start with Ramp-up = no of threads and then adjust if necessary
Test Plan Elements - Controllers
Controllers
These drive the processing and there are 2 types:
- Samplers – tell JMeter to send requests to the server and wait for the response eg. you use a HTTP Request Sampler to send HTTP request. Other samplers – FTP, JDBC, LDAP, SOAP. If you wish to validate the response then you can add an Assertion to the sampler eg. the server may return a successful HTTP Response code but the page might have errors so you can assert for things like certain HTML elements or error strings.Remember to add a listener to your test plan to view and/or store the results
- Logical Controllers – allow you to customize the logic JMeter uses to decide when to send requests eg.example:
- you can specify a One Only Controller to make a Login Request that is only executed on the first iteration
- rather than having several individual HTTP request elements (eg. load search page, run search A, load search again, run search B), we can use the Interleave Controller which knows the ordering of its children and passes requests from one to the next
HTTP Request Defaults
This element can be configured for many test plan elements and are useful for abstracting default information that each request may use ie. if several (or all) of the requests under the controller use the same PATH information (domain, port, action, protocol etc) then we can leave these blank for each request element and the Interleave Controller fills in the blanks for each of those requests from the Configuration Element. If we setup a HTTP Request Defaults at the Thread Group level then these defaults will be used by all child HTTP Request elements in the test. This is very useful in web testing, for example, by leaving the DOMAIN field blank in all your HTTP Sampler elements and configuring this is the defaults, you can easily switch your test to a different server by changing the single field in the defaults.
Cookie Manager
Add to all web tests – otherwise JMeter ignores cookies. Add it at the Thread Group level to ensure all HTTP requests use the same cookies.
Test Plan Elements - Listeners
Listeners
These provide access to the data while JMeter runs. The Graph Results listener, for example, plots response times on a graph and the View Results Tree listener shows details of sampler requests and responses. Other listeners provide summary/aggregated information.
They can also direct data to a file for later use.
Listeners can be added anywhere in the test, including directly beneath the test plan. They collect data from elements at and below their level.
Test Plan Elements - Timers
Timers
By default, JMeter sends requests without pausing in-between -
? Thought – this seems a bit odd since you would surely want JMeter to wait after making a login request wouldnt you?
You can use a timer to instruct JMeter to wait before making each new request. It is recommended to specify a delay by adding a timer to the Thread Group or else you can overwhelm the server. You can add more than 1 timer in which case the sum of the timers is waited.
Timers can also be added at Sampler or Controller levl to restrict which components they are applied to.
Ramp-up – this controls how long JMeter waits before starting each thread, not how long each thread waits between each request.
Test Plan Elements - Assertions
Assertions
Allow you to test the results returned by the application and can use Perl-style regular expressions for the matches.
You can add an assertion to any Sampler eg. add one to an HTTP Request to check for markup or text in the response. You can view assertion results by adding an Assertion Listener to the Thread Group – failed assertions show up in the Tree View and Table Listners and count towards the percentage errors in the Aggregate and Summary reports.
Test Plan Elements - Configuration Elements
Configuration Elements
These work closely with Samplers and can add to, or modify, requests. They are only available to the elements at the same level and below the tree branch where you attach them.
User Defined Variables Element – this is different and is procesed at the start of a test no matter where it is placed – hence for simplicity it recommended to place it at the start of a Thread Group.
Pre and Post Processors
Pre-Processors
Executes some action prior to a Sample Request and most-used to modify the settings of the request before it runs, or to update variables not extracted from the response text
Post-Processors
same as above except after the sample runs, usually to extract some data from the response.
For both of the above – they are executed either before or after the Sampler element to which theyare attached.
Execution Order
- Configuration Elements
- Pre-Processors
- Timers
- Sampler
- Post-Processors (unless sample result is null)
- Assertions (unless sample result is null)
- Listeners (unless sample result is null)
Rules for execution order:
- Timers, Assertions and Pre and Post-Processors are only processed if there is a sampler to which they apply
- Controllers and Samplers are processed in the order in whic they appear in the tree
- Other test elements are processed according to the scope in which they are found, and the type of test element they are within
Examples – see documentation http://jakarta.apache.org/jmeter/usermanual/test_plan.html
Element Scope
Test tree elements are either ordered or hierarchical.
Ordered
eg. Controllers, Samplers
When you create a test plan you create an ordered list of sample requests (via Samplers) that represent the steps to be executed. Often, these requests are organized within Controllers.
Hierarchical
eg. Listeners, Config Elements, Processors, Assertions, Timers
These elements are all affected by the hierarchy of the branch they exist in. An assertion, for example, if its parent is a request is applied to justthat request, whereas if its parent is a Controller it affects all the requests that are a descendant of that Controller.
Order is irrelevant for hierarchical elements. For example, in the following, Timer #1 is applied to Requests One and Two, but Assertion #1 is only applied to Request Two. Timer #2 is applied to all requests.
Thread Group
|
|—-Simple Controller
| |
| |—-Request One
| |—-Timer #1
| |—-Request Two
| |
| |—-Assertion #1
|
|—-Timer #2
Web Test Setup
Example of a basic web application test plan:
- create Thread Group under the test plan
- maybe give it a descriptive name
- configure the number of threads (essentially the number of users we wish to simulate)
- start with a Ramp-up period = No. on threads - add a HTTP Request Defaults element under Thread Group
- fill in any default HTTP fields eg. Hostname/IP - add a HTTP Cookie Manager if your application uses cookies
- add a HTTP Cookie Manager to the Thread Group, this ensures each thread gets its own cookie but shared across requests - add the HTTP Requests that you need for your test plan
- give each a descriptive name
- set the path for the request (no need to set the server since this was declared in the defaults) - finally, add a Listener to store the results