You are on page 1of 11

A guide to Performance Testing with JMeter

This article will give a great understanding on Jmeter Framework needed to test
an enterprise level application to deliver it with robustness and reliability. It will
provide simple and easy steps for Jmeter installation. In this article we will also
see step by step method to test single web page in Apache JMeter.
Before digging into the JMeter, let us first understand few jargons mostly
associated with the testing of any application.

Performance Test
In software engineering, performance testing is a non-functional testing that is
performed, to determine how fast some aspect of a system performs under a
particular workload. It can also serve to validate and verify other quality
attributes of the system, such as scalability, reliability and resource usage. It can
compare two systems to find which performs better. Or it can measure what part
of the system or workload causes the system to perform badly. It also highlights
early in the testing process if changes need to be made before application goes
into production.

Load Test
This test is basically used for exercising\discovering the system under the top
load it was designed to operate under.

Stress Test
This test is an attempt to break the system by overwhelming its resources.

INTRODUCTION
Jmeter
JMeter is an application that allows to load test or performance oriented business
(functional) test on different protocols or technologies. Stefano Mazzocchi of
the Apache Software Foundation was the original developer of JMeter. He wrote it
primarily to test the performance of Apache JServ (Now called as Apache Tomcat
project). Apache later redesigned JMeter to enhance the GUI and to add
functional-testing capabilities.
Jmeter is a Java desktop application with a graphical interface using the Swing
graphical API, can therefore run on any environment / workstation accepting a
Java virtual machine, for example: Windows, Linux, Mac, etc.

Apache JMeter may be used to test performance both on static and


dynamic resources (Files, Web dynamic languages - PHP, Java, ASP.NET,
etc. -, Java Objects, Data Bases and Queries, FTP Servers and more). It can
be used to simulate a heavy load on a server, group of servers, network or
object to test its strength or to analyze overall performance under
different load types.

How Jmeter Works?


JMeter simulates a group of users sending requests to a target server, and
returns statistics that show the performance/functionality of the target
server/application via tables, graphs, etc.

DOWNLOADING AND INSTALLING


Jmeter is a Java application, so a JRE or SDK first needs to be installed with a
JAVA_HOME environment variable.

Step 1: Download Jmeter

Jmeter can be downloaded in the below link:


http://jmeter.apache.org/download_jmeter.cgi

Choose the Binaries file (either zip or tgz) to download.

Step 2: Installation

Unzip the zip/tar file into the directory where you want JMeter to be
installed.

Step 3: Launch Jmeter

GUI Mode

Server Mode

Command Line Mode

Start JMeter in GUI Mode

Run the file /bin/jmeter.bat or /bin/ApacheJMeter.jar to start JMeter in


GUI mode (for Windows).

Start JMeter in Server Mode

Run the bat file bin\jmeter-server.bat as below figure

Figure 1: Jmeter in Server Mode

Start JMeter in command line mode

JMeter in GUI mode consumes much computer memory.


For saving resource, you may choose to run JMeter without the GUI.
Use the following command options to run Jmeter in command line mode:

Figure 2: Jmeter in Command Line Mode

BASIC ELEMENTS IN JMETER


1. Thread Group
Thread Group elements are the beginning points of your test plan.
As the name suggests, the thread group elements control the
number of threads JMeter will use during the test. We can also
control the following via the Thread Group
Setting the number of threads
Setting the ramp-up time
Setting the number of test iterations
2. Samplers
Samplers allow JMeter to send specific types of requests to a server.
They simulate a user request for a page from the target server. For
example, you can add a HTTP Request sampler if you need to
perform a POST, GET, or DELETE on a HTTP service.
Some useful samplers are
HTTP Request
FTP Request
JDBC Request
Java Request
SOAP/XML Request
RPC Requests
3. Logic Controllers
Logic Controllers let you control the order of processing of Samplers
in a Thread. Logic controllers can change the order of a request
coming from any of their child elements. Some examples are:
Simple Controller, Loop Controller, etc.
4. Listeners
Listeners let you view the results of Samplers in the form of tables, graphs,
trees, or simple text in some log files. They provide visual access to the
data gathered by JMeter about the test cases as a Sampler component of
JMeter is executed.
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.

5. Timers
By default, a JMeter thread sends requests without pausing between each
sampler. This may not be what you want. You can add a timer element
which allows you to define a period to wait between each request.
6. Assertions
Assertions allow you to include some validation test on the response of
your request made using a Sampler. Using assertions you can prove that
your application is returning the correct data. JMeter highlights when an
assertion fails.
7. Configuration Elements
Configuration Elements allow you to create defaults and variables to be
used by Samplers. They are used to add or modify requests made by
Samplers.
They are executed at the start of the scope of which they are part, before
any Samplers that are located in the same scope. Therefore, a
Configuration Element is accessed only from inside the branch where it is
placed.

8. Pre-Processor Elements
A pre-processor element is something that runs just before a
sampler executes. They are often used to modify the settings of a
Sample Request just before it runs, or to update variables that are
not extracted from response text.
9. Post-Processor Elements
A post-processor executes after a sampler finishes its execution. This
element is most often used to process the response data, for example, to
retrieve a particular value for later use.

BUILD A SIMPLE TEST PLAN


1. Start Jmeter

Open the JMeter window by clicking on /bin/jmeter.bat or


/bin/ApacheJMeter.jar. The JMeter window will appear as below:

Figure 3: Jmeter Window

Test Plan node is where the real test plan is kept.

Workbench node is where the temporary stuff is kept.

2. Rename the Test Plan

Change the name of test plan node to Sample Test in the Name text box.
You have to change focus to workbench node and back to Test Plan node
to see the name getting reflected.
Save the test plan.

3. Add Thread Group

Right click on Sample Test (our Test Plan)> Add> Threads (Users)> Thread
Group. Thread Group will get added under the Test Plan (Sample Test)
node.
Number of threads indicates the number of users to be simulated.
Ramp up period is the time over which all the sessions will start uniformly
one by one.

Figure 4: Add Thread Group

4. Add the HTTP Cookie Manager

Right click anywhere in the Test Plan hierarchy


Add -> Config Element -> HTTP Cookie Manager

5. Add the HTTP Cache Manager

Right click anywhere in the Test Plan hierarchy


Add -> Config Element -> HTTP Cache Manager

6. Add HTTP Proxy Server

Right click on workbench and add the Http proxy Server: Add -> Non- Test
Elements -> Http Proxy Server. Port field - Enter "8080" (Any other value
would do).
Go to Target Controller click on the drop down and Sample Test (our test
plan) < Thread Group.

Figure 5: Add HTTP Proxy Server

7. Add Gaussian Random Timer under Http Proxy Server

Right click on the Http Proxy Server,


Add -> Timer -> Gaussian Random Timer.
Put the following values:
o Deviation (in milliseconds) -> 500.0
o Constant Delay Offset (in milliseconds) -> {$T}

Gaussian random timer should be used if you want JMeter to record the time
taken by the human user between clicking different links across the GUI. While
executing the test case, the HTTP requests would be sent one after another
maintaining the same time gap (as taken by the user). If Gaussian random timer
is not used, all the requests would be pumped to the server at once. I am sure
that nobody wants to test such an unrealistic scenario.

8. Add Listeners

Right-click on Thread Group -> Add -> Listener -> View Results in Table &
View Results Tree & Aggregate Report & Summary Report.
Listeners let you view the results of Samplers in the form of tables, graphs,
trees or simple text in some log files.

Figure 6: Add Summary Report

9. Start proxy server

HTTP Proxy Server -> Start

10. Configure the browser with default Proxy value.

Open the browser and configure proxy settings to point to JMeter's proxy
server.
For Mozilla browser, click on Firefox tab seen in top left of the menu bar.
Click Options tab.
Select advanced options ->Network->Settings-> Check Manual proxy
configuration -> Input "localhost" in Http Proxy and "8080" in Port.
Check Use this proxy server for all protocols

Figure 7: Proxy Settings

11.Test the application

In the address bar type the URL of the application you want to test.
Browse the application.

12.Stop the Proxy.

Click on the Stop button from the Proxy Server once the recording is
finished.

13.Run the Test Plan.

Click Start icon on the top of Jmeter application


View test results in the listeners under Thread Group

Difference in response time in Jmeter and Browser for the


same application
I did research regarding deviation in the manual browsing VS the JMeter result for
some pages. Here is what I have found and got to know about it:
Sometimes the two concepts, load testing and page load speed, get mixed up.
Really though they are completely different and should be approached in
different ways with different tools. JMeter is not a browser so it will never give us
the exact same response times for rendering a page as we see in our browser.
The best tool to record how long it takes to load a page is a browser. If we
combine this with a stopwatch and a suitable sample size we will get some useful
data. This is a good method, we not only get real results but we also stop the
clock when the page is perceived to be loaded, which is really what matters. If
we want to automate this process to generate repeatability or we just want finer
grain then we should look at functional automation tools (like Seleneum). But if
we want to conduct load testing then something like JMeter is very effective.

You might also like