JMeter Load Testing

Sang Shin, sang.shin@sun.com, www.javapassion.com/javaprogrammingadv


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:
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.


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.

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


Figure-1.21:  Add Thread Group

2. Configure the newly created Thread Group.

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.

Figure-1.31: Set HTTP Request Defaults

2. Configure HTTP Request Defaults.

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.

Figure-1.41: HTTP Cookie Manager

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.

Figure-1.51: HTTP Request

2. Create HTTP request.

Figure-1.52: Configure HTTP Request

3. Create another HTTP request.


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.

Figure-1.61: Graph Results

2. Configure Graph Results.

Figure-1.62: Configure Graph Results

                                                                                                              return to top of the exercise



(1.7)  Run the test


1. Run the test.

Figure-1.71: Run the test

Figure-1.72: Warning

Figure-1.73: Save the test plan

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.

Figure-1.81: Change the number of Loop

2. Run the test.

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.


Figure-2.11: Create Thread Group

Figure-2.12: Create HTTP Request Defaults

2. Set HTTP Request Default settings.

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.

Figure-2.21: Create HTTP Proxy server
2. Start the 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

Figure-2.32: Change Network settings

Figure-2.33: Set Manual Proxy configuration

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.

Figure-2.45: Acdess a few more pages

Figure-2.46: Access a page
 
3. Observe that the Thread Group now adds a few samplers.


Figure-2.47: Observe that the HTTP samplers are added


                                                                                                             return to top of the exercise

(2.5) Set up a listener


1. Add Aggregate Report.

Figure-2.51: Add Aggregate Report

Figure-2.52: Aggregate Report node is added

2. Configure Thread Group.

Figure-2.53: Configure Thread Group

3. Save the test plan.

Figure-2.54: Save the Test Plan

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

Figure-2.63: Observe the resuilt


Figure-2.64: End result
           

                                                                                                              return to top of the exercise

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



Figure-3.11: Add JMeter plug-in to the NetBeans

Figure-3.12: Install JMeter Kit plug-in

Figure-3.13: Click Next

Figure-3.14: Access the terms

Figure-3.15: Finish the installation

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. 

2. Build and run the helloworld NetBeans project.
                                                                                                                        return to top of the exercise

(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.


Figure-3.31: Select Other

Figure-3.32: Create New JMeter Plan

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.

Figure-3.34: Select External Edit

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.

Figure-3.41: Set up HTTP Proxy Server

2. Configure the HTTP Proxy Server.

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.

Figure-3.52: Change network settings

Figure-3.53: Change port number

3. Run the browser.


Figure-3.54: Access the application

Figure-3.55: Result

4. Observe that the HTTP Proxy Server captured the HTTP requests.


Figure-3.56: Observe that the samplers are added

                                                                                                                        return to top of the exercise

(3.6) Add Aggregate Report


1. Add Aggregate Report.

Figure-3.61: Add Aggregate report

Figure-3.62: Display Aggregate report

                                                                                                                        return to top of the exercise


(3.7) Change Thread Group configuration


1. Change the Loop Count.


Figure-3.71: Change the Loop count

Figure-3.72: Save

                                                                                                                        return to top of the exercise

(3.8) Start the testing


1. Select the Aggregate Report.


Figure-3.81: Display the aggregate report

2. Start the testing.

Figure-3.82: Start the test

Figure-3.83: Result

                                                                                                                        return to top of the exercise

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>