Using JMeter

JMeter is a Java-based tool for load testing client-server applications.
Stefano Mazzocchi originally wrote it to test the performance of Apache JServ
(the predecessor of Jakarta Tomcat). It has since become a subproject of
Jakarta.

Installing and Running JMeter

The most recent release of JMeter is version 1.8. You can download the latest stable version
from JMeter's site.
Downloads area available as either .gz or .zip files.
JMeter 1.8 requires a working JDK 1.4 environment.

Once you extract the binary distribution file, JMeter is ready for you. On
Linux/UNIX, run JMeter by invoking the jmeter shell script. On
Windows, call the jmeter.bat file. Both files can be found in the
bin/ directory of the JMeter installation directory. Figure 1 shows
JMeter's main window, which is a Swing application.

Figure 1: JMeter's main window.

The user interface has two panes. The left pane displays the elements used
in our testing. Initially, there are the Root and two sub-elements, Test Plan
and WorkBench. In this article we're only concerned with Test Plans. Add an
element to a node by right-clicking it and selecting Add. To remove an element,
select the element by clicking on it, then right-click on the element and
choose the Remove option.

The right pane of the user interface displays the details of each element.
You are now ready to use JMeter. There are two things to note:

You should not run JMeter on the same machine running the application to be
tested. JMeter may use extensive resources that might affect the other
application's performance if they are both run on the same machine.

Make sure that the testing is affected as little as possible by network traffic. The
best thing to do is to ask your network administrator to set up an isolated
sub-network for the machine running the Web application and the machine running
JMeter.

Using JMeter for a Simple Test

Let's start with a very simple test. In this test, we will set up a test
plan and stress test a Web application. You will be introduced with some common
concepts in JMeter. After understanding this basic test, you should be able to
use all of the capabilities of JMeter.

To conduct a test, you must have a test plan. A test plan describes the
steps that JMeter will take to perform the testing. A test plan includes
elements such as thread groups, logic controllers, sample generating
controllers, listeners, timers, assertions, and configuration elements. Don't
worry at this stage if you don't understand what these elements are.

A test plan must have at least one thread group. A thread group is the starting
point of a test plan, and it can contain all other JMeter elements. A thread
group controls the threads that will be created by JMeter to simulate
simultaneous users.

Now, let's start by creating a thread group. Right-click the Test Plan
element and select Add and then Thread Group. JMeter will create a thread group
element under Test Plan element. Click the Thread Group element, and you will
see a screen like the one in Figure 2.

Figure 2: Configuring a thread group.

In this page, you can set the following properties:

Name -- the name of this thread group. You can give a descriptive name to
this property.

Number of Threads -- the number of threads created. Each thread
represents a single user. Therefore, if you want to simulate a load test with
10 concurrent users, enter 10 as the value for this property.

Ramp-Up Period -- the number of seconds JMeter will take to accelerate to
create all of the threads needed. If the number of threads used is 10
and the ramp-up period is 20 seconds, JMeter will take 20 seconds to create
those 10 threads, creating one new thread every two seconds. If you want
all threads to be created at once, put 0 in this box.

Forever -- if clicked, this option tells JMeter to keep sending requests
to the tested application indefinitely. If disabled, JMeter will repeat the
test for the number of times entered in the Loop Count box.

Loop Count --this property value only has an effect if the Forever check
box is unchecked. It tells JMeter the number of times it has to repeat the
test.

For our simple test, fill the properties with the values found in Figure 2.
We will use two users and each test will be performed three times.
We use small numbers here so that we can easily explain the results later; in
real load testing, you might want to use higher numbers for these
properties.

Next, you need to add the element that represents HTTP requests. To do so,
right-click the Thread Group element, and select Add, Sampler, and then HTTP
Request. An HTTP Request element will be added to the Thread Group element.
Click the HTTP Request element to select it, and you should see a screen
similar to Figure 3.

Figure 3: Configuring an HTTP Request element.

On the HTTP Request screen, you configure the HTTP requests that will be used
to "hit" your application. Here, you can set the following properties.

Name -- the name of this HTTP request. The name should be descriptive; remember that it is common to have multiple HTTP Request elements in a
thread group.

Server Name or IP -- the server name or the IP address of the
machine running the application being tested.

Port Number -- the port number used by the application. Normally, a
Web application runs on port 80.

Protocol -- the protocol used, either HTTP or HTTPS.

Method -- the request method, either GET or POST.

Path -- the path to the resource that will handle this request.

Follow Redirects -- follows redirections sent by the Web
application, if any.

Use KeepAlive -- if checked, sends the Connection =
Keep-Alive request header. By default, an HTTP 1.1 browser uses
Keep-Alive as the value of the Connection header. Therefore, this checkbox
should be checked.

Parameters -- the list of parameters sent with this request. Use the
Add and Delete buttons to add and remove parameters.

Send a file with a request -- simulate a file upload to the Web
application.