JMeter Load Testing

Apache JMeter is a 100% pure Java desktop 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.
Apache JMeter may be used to test performance both on static and
dynamic resources (files, Servlets, Perl scripts, Java Objects, Data
Bases and Queries, FTP Servers and more). It can be used to simulate a
heavy
load on a server, network or object to test its strength or to analyze
overall performance under different load types. You can use it to make
a
graphical analysis of performance or to test your server/script/object
behavior under heavy concurrent load.
Apache JMeter features include:
- Can load and performance test HTTP and FTP servers as well as
arbitrary database queries (via JDBC)
- Complete portability and 100% Java purity .
- Full Swing and lightweight component support
(precompiled JAR uses packages
javax.swing.* ).
- Full multithreading framework allows concurrent
sampling by many threads and simultaneous sampling of different
functions by separate thread groups.
- Careful GUI design allows faster operation and more
precise timings.
- Caching and off-line analysis/replaying of test results.
- Highly Extensible:
- Pluggable Samplers allow unlimited testing capabilities.
- Several load statistics may be chosen with pluggable
timers .
- Data analysis and visualization plugins allow great
extendibility as well as personalization.
- Functions can be used to provide dynamic input to a test or
provide data manipulation.
- Scriptable Samplers (BeanShell is fully supported; and there
is a sampler which supports BSF-compatible languages)
In this lab, you are going to build a very simple JMeter test plan in
the first exercise. In the 2nd exercise, you are going to build
one using NetBeans.
Expected duration: 90 minutes (not including time
for homework)
Software
Needed
Before you begin, you need to install the following software on your
computer.
- Java Standard Development Kit (JDK™) version 5.0 (download) or
6.0 (download)
- Select JDK 6 Update x
from the download page
- NetBeans IDE 6.0 (download)
- Download either "Web &
Java EE" or "All"
bundles.
- JMeter (download)
- For your convenience, the JMeter is included in the
hands-on
lab zip file mentioned below under <LAB_UNZIPPED_DIRECTORY>/javatestjmeter/jakarta-jmeter-2.3.1
directory.
- 1077_javatestjmeter.zip (download)
- The zip file contains this document and the lab contents.
- Download it and unzip in a directory of your choice.
- It contains JMeter binary under <LAB_UNZIPPED_DIRECTORY>/javatestjmeter/jakarta-jmeter-2.3.1 directory.
- It also contains NetBeans 6.0 JMeter plug-in under <LAB_UNZIPPED_DIRECTORY>/javatestjmeter/netbeansplugin directory.
Change Log
Lab Exercises
Exercise 1: Building a simple Web Test
Plan (using standalone JMeter application)
This exercise is based on 5.
Building a Web Test Plan section of the JMeter document. In
this exercise, you are going to exercise basic features of JMeter using
JMeter standalone application UI.
(1.1)
Start JMeter in standalone mode
1. Run the standalone JMeter application.
- Browse down to <LAB_UNZIPPED_DIRECTORY>/javatestjmeter/jakarta-jmeter-2.3.1 directory and
double click jmeter.bat (for
Windows) and jmeter.sh (for
Solaris/Linux).
- Observe that the standalone JMeter application gets displayed.

Figure-1.11: Run jmeter standalone application
return to top
of
the exercise
(1.2)
Add a Thread Group
The first step you want to do with every JMeter Test Plan is to add a
Thread Group element. The Thread Group tells
JMeter the number of users you want to simulate, how often the users
should send
requests, and the how many requests they should send.
1. Add a Thread Group
- Right click Test Plan
and select Add->Thread Group.

Figure-1.21: Add Thread Group
2. Configure the newly created Thread Group.
- Observe that the Thread Group pane appears.
- For the Name field, enter whatever name you want to give to the
Thread Group, Sang Shin Thread Group in this example.
- For the Number of Threads (users) field, enter 5.
- For the Ramp-Up Period (in seconds) field, enter 0.
- For the Loop Count field, enter 2.

Figure-1.22: Set Thread Group Properties
return to top
of
the exercise
(1.3)
Add Default HTTP
Request Properties
Now that we have defined our users, it is time to define the tasks that
they
will be performing. In this section, you will specify the default
settings
for your HTTP requests. And then, in the next step, you will add HTTP
Request
elements which use some of the default settings you specified here.
1. Add a new HTTP Requests Defaults.
- Right click the newly created Thread Group, Sang Shin Thread Group in this
example, and select Add->Config
Element->HTTP Request Defaults.

Figure-1.31: Set HTTP Request Defaults
2. Configure HTTP Request Defaults.
- For the Server Name or IP field, enter jakarta.apache.org.

Figure-1.32: Set Server Name or IP field
return to top
of
the exercise
(1.4)
Add Cookie support
Nearly all web testing should use cookie support, unless your
application
specifically doesn't use cookies. To add cookie support, simply add an
HTTP
Cookie Manager to each
Thread
Group in your test plan. This will ensure that each thread gets
its own
cookies, but shared across all
HTTP
Request objects.
1. Add HTTP Cookie Manager.
- Right click the Thread Group and select Add->Config Element->HTTP Cookie
Manager.

Figure-1.41: HTTP Cookie Manager
- Observe that the HTTP Cookie Manager node is added.

Figure-1.42: HTTP Cookie Manager
return to top
of
the exercise
(1.5)
Add HTTP requests
In our Test Plan, we need to make two HTTP requests. The first one is
for the
Jakarta home page (http://jakarta.apache.org/), and the second one is
for the
Project Guidelines page
(http://jakarta.apache.org/site/guidelines.html).
1. Add a new HTTP request.
- Right click the thread group and select Add->Sampler->HTTP
Request.

Figure-1.51: HTTP Request
2. Create HTTP request.
- For the Name field, enter Home Page.
- For the Path field, enter /.

Figure-1.52: Configure HTTP Request
3. Create another HTTP request.
- Right click the thread group and select Add->Sampler->HTTP
Request.
- For the Name field, enter Project
Guidelines.
- For the Path field, enter /site/guidelines.html.

Figure-1.53: Create 2nd HTTP request
return to top
of
the exercise
(1.6)
Add a Listener to
View Store the Test Results
The final element you need to add to your Test Plan is a
Listener . This element is
responsible for storing all of the results of your HTTP requests in a
file and presenting
a visual model of the data.
1. Add Graph Results.
- Right click the newly created Thread Group and select Add->Listener->Graph Results.

Figure-1.61: Graph Results
2. Configure Graph Results.
- For the Name field, enter My Graph Results.
- For the Filename field, enter a directory of your choice.

Figure-1.62: Configure Graph Results
return to top
of
the exercise
(1.7)
Run the test
1. Run the test.
- Select Run from top-level menu and then select Start.

Figure-1.71: Run the test
- If you a warning message as shown below, select Yes.

Figure-1.72: Warning
- Observe that the Save dialog box appears.
- Click Save.

Figure-1.73: Save the test plan
- Observe that the graph is displayed.

Figure-1.74: Result
return to top
of
the exercise
(1.8)
Modify and run the test plan
1. Modify the Loop Count from 2 to 100.
- For the Loop Count field, enter 100.

Figure-1.81: Change the number of Loop
2. Run the test.
- Select Run and select Start.
- Observe the graph is being displayed.

Figure-1.82: Rest result
return to top
of
the exercise
Summary
In this exercise, you learned how to
start JMeter at the command line.
return to the
top
Exercise 2: JMeter Proxy
In this exercise, you are going to set
up a JMeter proxy. Setting up a JMeter proxy is one easy way to
create a test plan. What the proxy does is it records the
requests sent to the server.
(2.1)
Create a test plan
1. Create a test plan.
- Right click Test Plan and select Add->Thread
Group.

Figure-2.11: Create Thread Group
- Observe that the Thread Group
node is now added under Test Plan
node.
- Right click Test Group
and select Add->Config
Element->HTTP
Requests Defaults.

Figure-2.12: Create HTTP Request Defaults
2. Set HTTP Request Default settings.
- For the Server Name or IP field, enter jakarta.apache.org.
- For the Port Number field, enter 80.
- For the Protocol (default http) field, enter http.
(Actually this is not necessary since http is default.)

Figure-2.13: Configure HTTP Request Defaults
return to top
of
the exercise
(2.2)
Set up a JMeter proxy server
1. Add HTTP Proxy server.
- Right click WorkBench and select Add->Non-Test
Elements->HTTP Proxy Server.

Figure-2.21: Create HTTP Proxy server
- Observe that the HTTP Proxy Server node is added under WorkBench
node.
- For the Port field, enter 9090.
- For the Test Controller field, select Test Plan->Thread Group
from the drop-down menu.
- Click Add button under URL Patterns to include section.
- Enter .*\.html.
- Click Add button under URL Patterns to exclude section.
- Enter .*\.gif.
2. Start the JMeter
proxy server.
- Click Start
button. This will start JMeter proxy server.

Figure-2.22: Configure HTTP Proxy server
return to top
of
the exercise
(2.3)
Configure the browser
1. Open Firefox browser and configure the proxy setting.

Figure-2.31: Select Options
- Observe that the Options dialog box appears.
- Select Advanced.
- Select Network tab.
- Select Settings.

Figure-2.32: Change Network settings
- Select Manual Proxy configuration.
- For HTTP Proxy field, enter localhost.
- For the Port field, enter 9090.
- Click OK.

Figure-2.33: Set Manual Proxy configuration
- Click OK to close the Options dialog box.

Figure-2.34 Close Options dialog box
return to top
of
the exercise
(2.4)
Access the website
1. In the Firefox browser, enter
http://jakarta.apache.org/jmeter/index.html in the URL field.

Figure-2.41: Access the server
Trouble-shooting: If
you encounter the following problem, it is because you have not started
the JMeter proxy server as described
above.

Figure-2.42: Error case when you have not started the JMeter proxy
server
2. Access a few links.
- Click 5. Building a Web Test
Plan link.

Figure-2.45: Acdess a few more pages
- Observe that a new page is displayed.
- Feel free to view a few other pages.

Figure-2.46: Access a page
(2.5)
Set up a listener
1. Add Aggregate Report.
- Right click Thread Group and select Add->Listener->Aggregate
Report.

Figure-2.51: Add Aggregate Report
- Observe that the Aggregate report is added.

Figure-2.52: Aggregate Report node is added
2. Configure Thread Group.
- Select Thread Group.
- For the Number of Threads (users) field, enter 5.
- For the Loop Count, enter 100.

Figure-2.53: Configure Thread Group
3. Save the test plan.
- Select File->Save Test Plan
as.

Figure-2.54: Save the Test Plan
- THe Save dialog box appears.
- Browse down to the directory in which you want to save the test
plan.
- Give the name to Proxy.jmx
(or whatever name you want).
- Click Save.

Figure-2.55: Save the test plan
return to top
of
the exercise
(2.6)
Run the test
1. Select Aggregate Report to display it.

Figure-2.61: Display Aggregate Report
2. Run the test.

Figure-2.62: Run the test
- Observe that the statistics are being displayed.
- Observe the green box on the upper right corner, which indicates
that the test is in progress.

Figure-2.63: Observe the resuilt
- Wait until the test is done.
- Observe that the each page is accessed 500 times.
- Observe that the color of the box in the upper right corner is
changed to gray, which indicates that test is done.

Figure-2.64: End result
Exercise 3: Use JMeter with NetBeans
In this exercise, you are going to run
JMeter within the NetBeans IDE.
Support for the JMeter plugins is closely
integrated with the IDE's profiling tool. The JMeter plugins enable you
to easily create and run JMeter load testing scripts from within the
IDE.
To use a load generator script, you
create a script for a specific project and modify the script according
to the type of project load that would be placed on a server running
the application. When you run the script, the script places a load on
the server that emulates the behavior of the application under typical
running conditions. You can then test the performance of the
application and the test results you achieve would more closely
approximate the performance of the application under typical conditions.
(3.1)
Install JMeter plug-in to the NetBeans IDE
- Select Tools from
top-level menu and select Plugins.

Figure-3.11: Add JMeter plug-in to the NetBeans
- Select Available Plugins tab.
- Check JMeter Kit.
- Click Install button.

Figure-3.12: Install JMeter Kit plug-in

Figure-3.13: Click Next
- Check I accept the terms...
radio button.

Figure-3.14: Access the terms

Figure-3.15: Finish the installation
- Click Close to close the Plugins dialog box.

Figure-3.16: Close the Plugins dialog box
return to top of
the exercise
(3.2)
Open a sample Web application
1. Open helloworld
NetBeans project.
- Select File->Open Project (Ctrl+Shift+O). The Open Project dialog box appears.
- Browse down to <LAB_UNZIPPED_DIRECTORY>/javatestjmeter/samples
directory.
- Windows: If you unzipped the 1077_javatestjmeter.zip
file under
C:\handsonlabs
directory, the directory to which you want
to browse down should be C:\handsonlabs\javatestjmeter\samples.
- Solaris/Linux: If you unzipped the 1077_javatestjmeter.zip
file under $HOME/handsonlabs
directory, the directory to which you want
to browse down should be $HOME/handsonlabs/javatestjmeter/samples.
- Select helloworld.
- Click Open Project Folder.
(3.3)
Create a new JMeter script
After you download and install the
plugins, a new category is created in the New File wizard. You use the
New File wizard to create a load script file in your project.
1. Create a new JMeter script.
- Right click helloworld project node and select New->Other.

Figure-3.31: Select Other
- Select Load Testing Script->JMeter Plans under Categories and
select New JMeter Plan under File Types.
- Click Next.

Figure-3.32: Create New JMeter Plan
- For the Script Name field, enter helloWorldJMeter.
- Click Finish.

Figure-3.33: Give a name to the JMeter script
When you create a new script, the IDE places the script under the Load
Generator Scripts node in the Projects window. In the Files window, you
can see that the IDE saves the script in the
jmeter
directory. If you already have a load testing script created outside of
the IDE, you can create a
jmeter directory and add the script
to the directory to run the script from within the IDE.
The JMeter external editor enables you to modify the script according
to the needs of your application. After you have created a load testing
script or added a script to your project, you can invoke the external
editor by right-clicking the script in the Projects window and choosing
External Edit.
2. Edit the JMeter script.
- Right click helloWorldJMeter.jmx
and select External Edit.

Figure-3.34: Select External Edit
- For the Name field on the right, enter My JMeter Plan.
- Click Test Plan node and observe that it changes to My JMeter
Plan.

Figure-3.35: Give a name to the Test Plan
return to top of
the exercise
(3.4)
Add and Configure HTTP Proxy Server
1. Add HTTP Proxy Server.
- Right click WorkBench and
select Add->Non-Test
Elements->HTTP Proxy Server.

Figure-3.41: Set up HTTP Proxy Server
2. Configure the HTTP Proxy Server.
- For the Port field, enter 9090.
- For the Target Controller field, select My JMeter Plan->Thread Group from
the drop-down menu.
- Click Start. Now
the HTTP Proxy Server is waiting for HTTP request on port 9090.

Figure-3.42: Start the JMeter proxy server
return to top of
the exercise
(3.5)
Reconfigure the browser's proxy setting
If you already set this as part of the previous step, you can skip this.
1. Select Tools->Options.

Figure-3.51: Configure the browser
2. Set the Proxy setting.
- Click Advanced.
- Select Network tab,
- Click Settings button.

Figure-3.52: Change network settings
- Select Manual proxy configuration.
- For the HTTP Proxy field, enter localhost.
- For the Port field, enter 9090.
- Make sure the No Proxy for field is blank.
- Click OK.

Figure-3.53: Change port number
3. Run the browser.
- Enter http://localhost:8080/helloworld/ in the URL of the browser
and press Enter.
- Enter your name in the text field and click Submit button.

Figure-3.54: Access the application
- Observe that the response page is displayed,

Figure-3.55: Result
4. Observe that the HTTP Proxy Server
captured the HTTP requests.
(3.6)
Add Aggregate Report
- Right click My JMeter Plan and select Add->Listener->Aggregate Report.

Figure-3.61: Add Aggregate report
- Observe that the Aggregate Report node is added under My JMeter
Plan.

Figure-3.62: Display Aggregate report
return to top of
the exercise
(3.7)
Change Thread Group configuration
1. Change the Loop Count.
- Select Thread Group on the left.
- Change the Loop Count to
100.
(3.8)
Start the testing
1. Select the Aggregate Report.
Summary
In this exercise, you learned how to
install and use JMeter plug-in in NetBeans.
return to the top
Homework
exercise (for people who
are taking Sang Shin's "Advanced Java Programming online course")
<tbd>