JMeter Tutorial
JMeter Tutorial
JMeter Tutorial
JMeter Tutorial
JMeter Tutorial
ii
Contents
Introduction
Technologies used
Installation
GUI overview
Available requests
7.1
ThreadGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2
Samplers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3
Logic controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.4
Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
7.5
Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7.6
Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7.7
Configuration nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.8
Pre processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.9
Post processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
14
15
18
25
30
34
14 JMeter Plugins
42
JMeter Tutorial
iii
43
16 Summary
44
17 Download
45
18 Resources
46
JMeter Tutorial
iv
JMeter Tutorial
Preface
This tutorial discusses JMeter, a Java based load and performance testing tool with several applications and uses.
These are the main points that we are going to cover:
We are going to explain what is JMeter used for.
How is JMeter implemented and with what technologies is designed.
How to install and configure it properly.
We are going to explain the basic features of its user interface.
We will detailed explain how to configure different test plans.
To show how to analyze its results.
Finally we will mention some important best practices.
All examples have been configured and implemented using Java 8 update 0.20, Eclipse Luna 4.4, JMeter 2.11 and MySQL
Community Server 5.6.21.
JMeter Tutorial
vi
JMeter Tutorial
1 / 46
Chapter 1
Introduction
JMeter is an application that offers several possibilities to configure and execute load, performance and stress tests using different
technologies and protocols.
It allows simulating different type of requests against all kind of databases, FTP, HTTP, HTTPS or other kind of servers.
It is probably good to explain briefly what all these concepts mean:
Load tests: These kind of tests take the systems or applications tested to the extremes that they were designed and required
for. They are used to measure systems and applications behavior under extreme conditions.
Performance tests: These tests are used to check how the system behaves in terms of performance, that is, how the system
responds and how is its stability for a specific workload.
Stress tests: These tests try to break or overwhelm the system by loading more resources and taking its modules outside the
limits that were designed.
Originally JMeter was designed to test web applications, but its functionality has expanded and nowadays allows testing against
almost any kind of program and can be used to perform functional tests in your applications.
JMeter Tutorial
2 / 46
Chapter 2
Technologies used
JMeter is a Java desktop application. Its UI is implemented using the Swing Java API. Due to these two points, JMeter is
multiplatform and runs in any kind of machine with a Java virtual machine installed: Windows, Linux, Mac.
Its framework allows concurrency and the execution of several Threads and Threads Groups. This is very useful when trying to
configure load and stress tests.
It is extensible and there is a very large list of plugins available.
JMeter is part of the Apache software foundation and is completely free and open source (http://www.apache.org/licenses/).
JMeter Tutorial
3 / 46
Chapter 3
JMeter Tutorial
4 / 46
Chapter 4
Installation
You need to do the following steps in order to get JMeter installed and running in your computer:
First of all you have to install Java. You need a JRE 1.6 or above installed in your machine. To do this, just go to the Oracle
download site and install the package suitable for your system: http://www.oracle.com/technetwork/java/javase/downloads/index.html.
Set the JAVA_HOME environment variable to point to the base directory location, where Java is installed on your machine. For
Windows users:
JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_20
JMeter Tutorial
5 / 46
apache-jmeter-2.9
apache-jmeter-2.9\\bin
apache-jmeter-2.9\\docs
apache-jmeter-2.9\\extras
apache-jmeter-2.9\\lib
apache-jmeter-2.9\\lib\\ext
apache-jmeter-2.9\\lib\\junit
apache-jmeter-2.9\\printable_docs
Then you can start JMeter by going to the folder C:jmeterapache-jmeter-2.11bin (Windows users) and starting the
program jmeter.bat.
You should see the start screen of the JMeter GUI:
JMeter Tutorial
6 / 46
Chapter 5
GUI overview
The JMeter GUI is very intuitive and easy to use, common menus for file handling like new, open, save, save as etc. and specific
menus for starting and stopping test plans and configuring them are available. Every test plan, thread group and test plan node
(we will see these more in detail in the next chapters) offer different context menu options by clicking the mouse right button.
It is also possible to change the language of the UI and a big bunch of languages are available.
As we said, the GUI is very intuitive and easy to use and offers for every menu and action very understandable tool tips. This is
one of the reasons, apart from its quality, why JMeter is so broadly used, because it is really easy to understand and learn how to
work with it.
JMeter Tutorial
7 / 46
Chapter 6
Available requests
JMeter offers test configurations for almost any kind of system, but in general, the following protocols are covered out of the
box:
Web: HTTP, HTTPS sites web 1.0 web 2.0 (ajax, flex and flex-ws-amf): we will see afterwards how to test a potential web
page and its behavior.
Web Services: SOAP / XML-RPC.
Database via JDBC drivers. Almost any kind of database is supported, what you need is just a proper driver and pack it in the
proper folder in the JMeter installation directory. We will make an example of a MySQL database test afterwards.
Directory: LDAP.
Messaging Oriented service via JMS
Mail Service using POP3, IMAP, SMTP.
FTP Service.
Functional test using JUnit and Java applications.
JMeter Tutorial
8 / 46
Chapter 7
7.1
ThreadGroup
A thread group is basically a combination of different test plan elements. It is the root of a test plan and it controls the basic
central parameters.
In order to create a test plan you may have to create at first a thread group and configure its number of threads, the ramp-up
period, the loop counts and the behavior in case or error:
Number of threads: The number of threads that are going to be used to execute the test plan, very important to configure load
and stress tests.
Ramp-up period: Time that JMeter will need to start all threads.
Loop count: Number of iterations, that is the amount of times that the test is going to be executed.
Error behavior: What to do in case of error: Stop current thread, stop the whole test, continue. . .
A Thread Group has also the start and end time configuration options. By clicking the checkbox "Scheduler" a new section with
the schedule parameters will appear and you can configure the start and end time of your test.
Once this is configured you can start adding other test plan elements to your Thread group like samplers, listener and timers. We
are going to explain all these in the next chapters.
7.2
Samplers
Samplers are used for sending requests to different kind of servers. They are the basic element of every test plan and everything works around them: they execute requests (based on the configuration provided) and these requests produce one or more
responses that are analyzed afterwards.
Here is a list of the Samplers available in JMeter (we are going to see some of them in this tutorial):
Access log sampler
JMeter Tutorial
9 / 46
AJP sampler
Bean shell sampler
BSF sampler
Debug sampler
FTP sampler
HTTP sampler
Java sampler
JDBC sampler
JMS (several) samplers
JSR223 sampler
JUnit sampler
LDAP (several) samplers
Mail Reader
MongoDB sampler
OS process sampler
SMTP sampler
SOAP
TCP samplers
Test action
As we can see in the list above, there are a lot of different types of samplers; this list is not complete since there are several others
implemented in different JMeter plugins. The configuration of each sampler depends on the request that it executes; that means
that some samplers have things in common but others are completely different because of the nature of their requests.
7.3
Logic controllers
Logic controllers are elements that allow you to configure the order of execution of different samplers inside a Thread group.
This list contains all available logic controllers in JMeter:
Simple Controller
Loop Controller
Once Only Controller
Interleave Controller
Random Controller
Random Order Controller
Throughput Controller
Runtime Controller
If Controller
JMeter Tutorial
10 / 46
While Controller
Switch Controller
ForEach Controller
Module Controller
Include Controller
Transaction Controller
Recording Controller
7.4
Listeners
Listeners provide different ways to view the results produced by a Sampler requests. Listeners parse results in form of tables,
trees or plain log files.
They can be added anywhere in a test plan, but they will only parse and collect result data from the samplers at their level or in
the levels bellow.
These are the available listeners in JMeter:
Sample Result Save Configuration
Graph Full Results
Graph Results
Spline Visualizer
Assertion Results
View Results Tree
Aggregate Report
View Results in Table
Simple Data Writer
Monitor Results
Distribution Graph (alpha)
Aggregate Graph
Mailer Visualizer
BeanShell Listener
Summary Report
JMeter Tutorial
7.5
11 / 46
Timers
You can define the time period that you want to wait between requests using timers. If you do not specify any, JMeter will execute
the next request immediately after the current one is finished, without any waiting time.
Following timers are available in JMeter:
Constant Timer
Gaussian Random Timer
Uniform Random Timer
Constant Throughput Timer
Synchronizing Timer
JSR223 Time
BeanShell Time
BSF Time
Poisson Random Time
7.6
Assertions
Assertions confirm the validity of the test plan by validating the response produced by a Sampler request. Basically assertions are
similar to unit test assertions and check the quality of the tested application response. You can configure what kind of assertions
is active for every test plan.
Here is a list of available assertions in JMeter:
Bean shell Assertion
BSF Assertion
Compare Assertion
JSR223 Assertion
Response Assertion
Duration Assertion
Size Assertion
XML Assertion
BeanShell Assertion
MD5Hex Assertion
HTML Assertion
XPath Assertion
XML Schema Assertion
JMeter Tutorial
7.7
12 / 46
Configuration nodes
You can pass different parameters to the sampler requests by using configuration elements. They provide a way to create variables
(different and dynamically) that can be used by the samplers afterwards. They are executed at the beginning of the node they
belong to, before the samplers are executed, that is why the samplers can rely on these variables.
Here is a list of all the configuration nodes that can be used in JMeter:
Counter
CSV Data Set Config
FTP Request Defaults
HTTP Authorization Manager
HTTP Cache Manager
HTTP Cookie Manager
HTTP Proxy Server
HTTP Request Defaults
HTTP Header Manager
Java Request Defaults
Keystore Configuration
JDBC Connection Configuration
Login Config Element
LDAP Request Defaults
LDAP Extended Request Defaults
TCP Sampler Config
User Defined Variables
Simple Config Element
Random Variable
7.8
Pre processors
Pre processors are elements (actions, assertions or basically whatever) that are going to happen before a sampler is executed.
They can be used to extract variables from a response that can be used in the sampler afterwards via configuration elements.
These are the elements that can be used as pre processors:
HTML Link Parser
HTTP URL Re-writing Modifier
HTTP User Parameter Modifier
User Parameters
JDBC PreProcessor
JSR223 PreProcessor
RegEx User Parameters
BeanShell PreProcessor
BSF PreProcessor
JMeter Tutorial
7.9
13 / 46
Post processors
A post processor is basically an element that is executed after a sampler execution finishes. It can be used to parse the response
data and extract values that can be used afterwards.
These elements can be used as post processors:
Regular Expression Extractor
XPath Extractor
Result Status Action Handler
JSR223 PostProcessor
JDBC PostProcessor
BSF PostProcessor
CSS/JQuery Extractor
BeanShell PostProcessor
Debug PostProcessor
JMeter Tutorial
14 / 46
Chapter 8
JMeter Tutorial
15 / 46
Chapter 9
JMeter Tutorial
16 / 46
JMeter Tutorial
17 / 46
JMeter Tutorial
18 / 46
Chapter 10
JMeter Tutorial
19 / 46
In this step you need to create a Thread group in charge of executing all the components of the test and configure its main
properties: number of threads, ramp up period in seconds and number of iterations.
Context Menu over Test Plan Add Thread ThreadGroup
JMeter Tutorial
20 / 46
JMeter Tutorial
21 / 46
JMeter Tutorial
22 / 46
JMeter Tutorial
23 / 46
On the test plan, right click and add a duration assertion, we configure it to assert false if the response takes longer than 100 ms,
and we configure it for the main sample only:
Add assertionDuration assertion
JMeter Tutorial
24 / 46
We assure that the response has a size larger than 5000 bytes:
JMeter Tutorial
25 / 46
Chapter 11
JMeter Tutorial
26 / 46
JDBC Sampler
Give a meaningful name to the Variable Bound to Pool and write some SQL statement:
select * from jmeter_stuff;
JMeter Tutorial
27 / 46
JMeter Tutorial
28 / 46
JMeter Tutorial
29 / 46
JMeter Tutorial
30 / 46
Chapter 12
This test mainly contains a couple of assertions in order to check how JMeter can use them, it is not the purpose of this tutorial
to explain unit testing or JUnit in detail.
JMeter Tutorial
31 / 46
Or you can export your project as JAR file including the bytecode and generated files directly in Eclipse or your favorite IDE.
Add a JUnit sampler request
JMeter Tutorial
32 / 46
JMeter Tutorial
33 / 46
JMeter Tutorial
34 / 46
Chapter 13
JMeter Tutorial
35 / 46
JMeter Tutorial
36 / 46
JMeter Tutorial
37 / 46
JMeter Tutorial
38 / 46
JMeter Tutorial
39 / 46
JMeter Tutorial
40 / 46
JMeter Tutorial
41 / 46
JMeter Tutorial
42 / 46
Chapter 14
JMeter Plugins
Different plugins are available for advanced users and use cases, some of them need extra installation, some not.
There are very useful plugins that allow to parse results using advanced options and analyze them using graphs and charts like
http://jmeter-plugins.org/wiki/GraphsGeneratorListener/.
There are also available plugins in order to connect JMeter with your continuous integration tool and run JMeter test plans
directly from the CI software like "https://wiki.jenkins-ci.org/display/JENKINS/Performance+Plugin" for Jenkins.
As i said the number of plugins is elevated and it is not possible to enumerate all of them, it is probably worth it to check if there
is some plugins available in the internet before trying to implement yourself one on your own.
You can also create your own plugin for JMeter, but this is out of the scope of this article.
JMeter Tutorial
43 / 46
Chapter 15
JMeter Tutorial
44 / 46
Chapter 16
Summary
So that is all. We saw how to install JMeter and how to configure it for executing different kind of tests like HTTP requests,
tests against databases and functional tests against Junit ones. There are many others kind of tests and possibilities offered with
JMeter that are not covered in this tutorial. The objective of this tutorial is to give a whole description of the application and to
show how to configure your first test plans.
We also explained the main parts of the JMeter UI and how to use it and also the test plan elements that come with JMeter out of
the box. In the last chapter we mentioned the possibility to expand JMeter with different Plugins; this is a very interesting point
for experience users with advanced needs.
JMeter Tutorial
45 / 46
Chapter 17
Download
All JMeter templates, SQL scripts and Java code used in this article can be downloaded in the following link: jmeter-tutorial.
JMeter Tutorial
Chapter 18
Resources
http://jmeter.apache.org/
http://jmeter-plugins.org/
href="http://en.wikipedia.org/wiki/Software_performance_testing
http://www.tutorialspoint.com/jmeter/
http://jmeter.apache.org/usermanual/get-started.html (section 2.4.3 Non-Guide Mode)
https://wiki.apache.org/jmeter/FrontPage
46 / 46