Professional Documents
Culture Documents
JMeter - Self Training For Novice Users
JMeter - Self Training For Novice Users
JMeter - Self Training For Novice Users
Testing Tool
Environment Setup, Record/Enhance Script, Execution & Analysis
Contents
1. Setup and Launch JMeter Tool................................................................................................................................4
1.1 Introduction – Apache JMeter™......................................................................................................................4
1.2 Install JAVA......................................................................................................................................................4
1.3 Install Jmeter...................................................................................................................................................5
1.4 Start Jmeter – GUI Mode.................................................................................................................................5
1.5 Using JMeter behind a proxy...........................................................................................................................6
1.6 Start JMeter - Non-GUI Mode (Command Line Mode)....................................................................................6
1.7 Install JMeter Plugins.......................................................................................................................................7
2. Record, Enhance, Replay & Debug..........................................................................................................................8
2.1 Recording Script – jmeter_proxy_step_by_step..............................................................................................8
2.2 Enhance Script with Test Plan Elements..........................................................................................................8
ThreadGroup...........................................................................................................................................................8
Controllers...............................................................................................................................................................8
Listeners.................................................................................................................................................................. 9
Timers...................................................................................................................................................................... 9
Assertions................................................................................................................................................................9
Configuration Elements.........................................................................................................................................10
Pre-Processor Elements.........................................................................................................................................10
Post-Processor Elements.......................................................................................................................................10
Execution order.....................................................................................................................................................10
Properties and Variables.......................................................................................................................................10
Using Variables to parameterise tests...................................................................................................................11
Regular Expressions...............................................................................................................................................11
Correlation in JMeter (handling dynamic values)..................................................................................................12
2.3 Script – Replay, Debug, Load Test Execution & Analysis................................................................................12
3. JMeter Distributed Testing....................................................................................................................................14
3.1 Prerequisites..................................................................................................................................................14
3.2 Details............................................................................................................................................................14
3.3 Terminology...................................................................................................................................................14
3.4 Step-by-Step..................................................................................................................................................15
3.5 Starting the Test............................................................................................................................................16
Start a single client................................................................................................................................................16
Start all clients.......................................................................................................................................................17
References–.................................................................................................................................................................. 19
Page No. 2
Page No. 3
1. Setup and Launch JMeter Tool
1.1 Introduction – Apache JMeter™
The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test
functional behavior and measure performance. It was originally designed for testing Web Applications but has
since expanded to other test functions.
Page No. 4
1.3 Install Jmeter
If you are testing from behind a firewall/proxy server, you may need to provide JMeter with the
firewall/proxy server hostname and port number. To do so, run the jmeter[.bat] file from a command line
with the following parameters:
Example:
jmeter -H my.proxy.server -P 8000 -u username -a password -N localhost
For load testing, you must run JMeter in this mode (Without the GUI) to get the optimal results from it. To
do so, use the following command options:
The script also lets you specify the optional firewall/proxy server information:
Example
jmeter -n -t my_test.jmx -l log.jtl -H my.proxy.server -P 8000
JVM_ARGS="-Dhttps.proxyHost=myproxy.com -Dhttps.proxyPort=8080"
Page No. 7
2. Record, Enhance, Replay & Debug
2.1 Recording Script – jmeter_proxy_step_by_step
The Test Plan is where the overall settings for a test are specified and explains sequence of steps execute at run time.
A final test plan made up of one or more Thread Groups, Sampler, logic controllers, listeners, timers, assertions, and
configuration elements. Each Sampler can be preceded by one or more Pre-processor element, followed by Post-
processor element, and/or Assertion element. It saves in Java Management Extensions (JMX) format.
The Test Plan object has a checkbox called "Functional Testing". If selected, it will cause JMeter to record the data
returned from the server for each sample. If you have selected a file in your test listeners, this data will be written to
file. This can be useful if you are doing a small run to ensure that JMeter is configured correctly, and that your server
is returning the expected results. The consequence is that the file will grow huge quickly, and JMeter's performance
will suffer. This option should be off if you are doing stress-testing (it is off by default).
If you are not recording the data to file, this option makes no difference.
You can also use the Configuration button on a listener to decide what fields to save.
List of Basic Test Plan Elements and General Description – Refer Apache Documentation for more details –
http://jmeter.apache.org/usermanual/index.html
ThreadGroup
Thread group elements are the beginning points of any test plan. All controllers and samplers must be under
a thread group. Other elements, e.g. Listeners, may be placed directly under the test plan, in which case they
will apply to all the thread groups. As the name implies, the thread group element controls the number of
threads JMeter will use to execute your test.
Controllers
JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test.
Samplers tell JMeter to send requests to a server.
1) Samplers
Samplers facilitate JMeter to deliver explicit types of requests to the server. It simulates
a user’s request for a page from the target server. So that, to avail POST, GET, DELETE
functions on a HTTP service, user can add HTTP Request sampler. Apart from HTTP
Request sampler, there are other simpler too,
HTTP Request
FTP Request
Page No. 8
JDBC Request
Java Request
SOAP/XML Request
RPC Requests
2) Logical Controllers
Runtime Controller
IFController
Transaction Controller
Recording Controller
Simple Controller
While Controller
Switch Controller
ForEach Controller
Module Controller
Include Controller
Loop Controller
Once Only Controller
Interleave Controller
Random Controller
Random Order Controller
Throughput Controller
Listeners
Listeners provide access to the information JMeter gathers about the test cases while JMeter runs. The
Graph Results listener plots the response times on a graph. The "View Results Tree" Listener shows details of
sampler requests and responses, and can display basic HTML and XML representations of the response.
Other listeners provide summary or aggregation information.
Additionally, listeners can direct the data to a file for later use. Every listener in JMeter provides a field to
indicate the file to store data to. There is also a Configuration button which can be used to choose which
fields to save, and whether to use CSV or XML format. Note that all Listeners save the same data; the only
difference is in the way the data is presented on the screen.
Listeners can be added anywhere in the test, including directly under the test plan. They will collect data
only from elements at or below their level.
Timers
The timer will cause JMeter to delay a certain amount of time before each sampler which is in its scope; by
default, a JMeter thread sends requests without pausing between each request
Page No. 9
Assertions
Assertions allow you to assert facts about responses received from the server being tested
Configuration Elements
A configuration element works closely with a Sampler. Although it does not send requests (except for
HTTP(S) Test Script Recorder), it can add to or modify requests.
A configuration element is accessible from only inside the tree branch where you place the element
The “User Defined Variables” Configuration element is different. It is processed at the start of a test, no
matter where it is placed. For simplicity, it is suggested that the element is placed only at the start of a
Thread Group.
Pre-Processor Elements
Post-Processor Elements
A Post-Processor executes some action after a Sampler Request has been made
Execution order
1. Configuration elements
2. Pre-Processors
3. Timers
4. Sampler
5. Post-Processors (unless SampleResult is null)
6. Assertions (unless SampleResult is null)
7. Listeners (unless SampleResult is null)
Please note that Timers, Assertions, Pre- and Post-Processors are only processed if there is a sampler to
which they apply. Logic Controllers and Samplers are processed in the order in which 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. [Within a type, elements are processed in the order in which they appear in the tree].
Properties are global to jmeter, and are mostly used to define some of the defaults JMeter uses (JMeter
properties are defined in jmeter.properties)
JMeter variables are local to each thread. The values may be the same for each thread, or they may be
different.
Note that the values defined by the Test Plan and the User Defined Variables configuration element are
made available to the whole test plan at startup. If the same variable is defined by multiple UDV elements,
then the last one takes effect. Once a thread has started, the initial set of variables is copied to each thread.
Other elements such as the User Parameters Pre-Processor or Regular Expression Extractor Post-Processor
may be used to redefine the same variables (or create new ones). These redefinitions only apply to the
current thread.
Page No. 10
The setProperty function can be used to define a JMeter property. These are global to the test plan, so can
be used to pass information between threads - should that be needed.
Variables don't have to vary - they can be defined once, and if left alone, will not change value. So you can
use them as short-hand for expressions that appear frequently in a test plan. Or for items which are constant
during a run, but which may vary between runs. For example, the name of a host, or the number of threads
in a thread group.
For example, you might define the following on the Test Plan:
HOST www.example.com
THREADS 10
LOOPS 20
Regular Expressions
Regular Expression is used to extract string/value from response by giving contains and matching values as
expression; JMeter includes the pattern matching software Apache Jakarta ORO.
EXAMPLES
Note: without the ?, the .+ would continue past the first ">until it found the last possible "> - which is
probably not what was intended.
Note: although the above expression works, it's more efficient to use the following expression:
name="file" value="([^"]+)">where
[^"] - means match anything except "
In this case, the matching engine can stop looking as soon as it sees the first ", whereas in the previous case
the engine has to check that it has found "> rather than say " >.
Page No. 11
This would create 2 groups, which could be used in the JMeter Regular Expression Extractor template as $1$
and $2$.
The JMeter Regex Extractor saves the values of the groups in additional variables.
MYREF: file.namereadme.txt
MYREF_g0: name="file.name" value="readme.txt"
MYREF_g1: file.name
MYREF_g2: readme.txt
These variables can be referred to later on in the JMeter test plan, as ${MYREF}, ${MYREF_g1} etc
Regular expressions use certain characters as meta characters - these characters have a special meaning to
the RE engine. Such characters must be escaped by preceeding them with \ (backslash) in order to treat
them as ordinary characters. Here is a list of the meta characters and their meaning (please check the ORO
documentation if in doubt).
() - grouping
[] - character classes
{} - repetition
*+? - repetition
. - wild-card character
\ - escape character
| - alternatives
^$ - start and end of string or line
Most web applications generate session id for first access by user and then pass the same session id to sub-
sequent requests to maintain workflow and security; to automate the application workflow we required to
identify and extract such value to variable and then pass this variable as parameter to sub-sequent requests
Regular Expression Extractor allows the user to extract values from a server response using a Perl-type
regular expression; as a post-processor, this element will execute after each Sample request in its scope,
applying the regular expression, extracting the requested values, generate the template string, and store the
result into the given variable name.
Refer JMeter Documentation link for Regular Expression Extractor or add Regular Expression Extractor in
Test Plan and Help from menu bar to see the usage instructions.
Page No. 12
2.3 Script – Replay, Debug, Load Test Execution & Analysis
a. Keep number of Thread = 1 and Loop=1 in Thread Group Properties (these are the default and one
can see by selecting Thread Group in Test Plan Tree at left pane)
b. Add below Listener to Test Plan
i. View Results Tree
ii. Aggregate Report
c. Click on Start Button (Play button of Green colour) or Ctrl+R
d. Test will replay and results can be verified in above added Listeners
Analysis/Extract Results
a. Aggregate Report results can be copied to excel/csv for further customization if required
b. Aggregate Report result will give good idea of average response time, throughput and error rates;
refer other graphs/results from various listeners to analyse results as needed.
c. Sample Load Test Results which one can prepare for post execution analysis
Page No. 13
3. JMeter Distributed Testing
Note – The same test plan is run by all the servers. JMeter does not distribute the load between servers, each runs
the full test plan
3.1 Prerequisites
3.2 Details
Once you've made sure the systems are ready, it's time to setup remote testing. The tutorial assumes you already
have JMeter installed on all the systems. The way JMeter works is 1 master controller initiates the test on multiple
slave systems.
3.3 Terminology
Before we dive into the step-by-step instructions, it's a good idea to define the terms and make sure the definition is
clear.
Master – the system running JMeter GUI, which controls the test.
Page No. 14
Slave – the system running JMeter-server, which takes commands from the GUI and send requests to the
target system(s).
Target – the webserver we plan to stress test.
3.4 Step-by-Step
1) On the slave systems, go to JMeter/bin directory and execute JMeter-server.bat (JMeterserver on unix). On
windows, you should see a dos window appear with “jre\[version]\bin\rmiregistry.exe”. If this doesn't
happen, it means either the environment settings are not right, or there are multiple JRE installed on the
system.
2) On master system acting as the console, open windows explorer and go to JMeter/bin directory.
Page No. 15
4) Edit the line “remote_hosts=127.0.0.1”.
5) Add the IP address. For example, if I have JMeter server running on 192.168.0.10, 11, 12,13, and 14, the
entry would like this:
remote_hosts=192.168.0.10, 192.168.0.11, 192.168.0.12, 192.168.0.13, 192.168.0.14.
6) Start JMeter.
At this point, you are ready to start load testing. If you want to double check the slavesystems are working,
open JMeter.log in notepad. You should see the following in the log.JMeter.engine.RemoteJMeterEngineImpl:
Starting backing engine. If you do not see this message, it means jmeter-server did not start correctly. For tips on
debugging the issue, go to the tips section. There are two ways to initiate the test: a single system and all systems.
Page No. 16
1) Click Run at the top.
2) Select Remote start.
3) Select the IP address.
Known Limitations:
There are some basic limitations for distributed testing. Here's the list of the known items in no specific order.
1. RMI cannot communicate across subnets without a proxy; therefore neither can JMeter without a proxy.
Page No. 17
2. Since JMeter sends all the test results to the controlling console, it is easy to saturate the network IO. It is a
good idea to use the simple data writer to save the results and view the file later with one of the graph
listeners.
3. Unless the server is a large multi-processor system, in most cases 1-2 clients is sufficient to overwhelm the
server.
4. A single JMeter client running on a 1.4-3 GHz CPU can handle 100-300 threads depending on the type of test.
The exception to the is web services. XML processing is CPU intensive and will rapidly consume all the CPU
cycles. As a general rule, the performance of XML centric applications will perform 4-10 slower than
applications using binary protocols.
Page No. 18
References–
http://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.pdf
http://jmeter.apache.org/usermanual/
Page No. 19