In this topic, you will learn how to test the performance of a web application and learn how to create a Test Plan in JMeter to achieve this. For this step by step tutorial, we will use the site www.google.com In the last topic, we learnt how to work with the JMeter and how to add elements to it, this knowledge will be useful when creating the test plan.
The most popular testing in JMeter is load testing and stress testing. The topic show you how to use JMeter GUI to build a simple performance test plan to run tests against a web server
What is load testing?
Load testing is performed on an application to find out the response and behavior of the application under normal circumstances and under peak load conditions.
What is stress testing?
Stress testing involves testing the system beyond its normal capacity, often beyond its breaking point to determine the behavior of the system. Stress testing can be used to find the limits of the application.
Performance testing with JMeter
As discuss in the previous topics, JMeter is designed to measure performance of web server. JMeter can simulate many concurrent users connecting to a web server and record performance data in various format such as XML, CSV and graphs.
Let us simulate the following scenarios.
- We need to simulate 50 users connecting to a web server (ex: www.google.com) concurrently
- The performance data is to be displayed in a graph to analyze the result
For the above scenarios, JMeter will create 50 samplers. Each sampler is a http request to the server, it represents one user connecting to the web server. JMeter will run them in 50 separate threads.
The following figure shows you the steps involved in practicing this test.
Step 1. Add Thread Group
First, start JMeter by running jmeter.bat or double clicking the ApacheJMeter.jar file.
Select the Test Plan and right click on it. Add a Thread Group to your selected Test Plan by choosing Add > Threads (Users) > Thread Group from the pop up menu.
The newly created Thread Group is displayed in the left hand pane. You can configure the Thread Group’s properties in the right hand pane as shown in the screenshot below.
You can give the Thread Group an appropriate name using the Name field.
The table below describes what JMeter does when a sampler error occurs.
|Continue||Continue the test|
|Start Next Thread Loop||Ignore the sampler error and start next thread loop|
|Stop Thread||Stop the error thread|
|Stop Test||Stop the whole Test Plan|
|Stop Test Now||Stop the test execution immediately|
The Thread Properties section controls load simulated by JMeter using the parameters below.
Number of Threads (users): This represents the number of users being simulated, who connect to the web server. In our example, we are simulating 50 users.
Loop Count: This is the number of times JMeter executes the test for each user. You can set a specified number or set it forever. For example:
- If the loop count is 50: The test will execute 50 times for each user
- If number of loop count is forever: The test will loop forever for each user
Difference between Number of Threads and Loop Count
|Number of Threads||Loop Count|
|It represent number of users who are connecting to the server.||It represents the number of times each user is connecting to the server. In other words, it is the number of times the Thread Group will repeat.|
|Example: If Number of Threads is 50, it simulates the load of 50 users connecting to the server.||Example: If Loop Count is 4, it represents each user / thread connecting to the server 4 times.|
Ramp-up Period: This is the time duration within which all threads have to run. In this case, there are 50 threads and ramp-up period is 10 seconds. Therefore, the delay between each thread would be 10/50 = 0.2 seconds.
Step 2. Add Sampler
Now that we have created a Thread Group, we need a way to send a request to the server. We can achieve this using Samplers. You need to add a Sampler to the Thread Group now.
Right click and select the Thread Group > Add > Sampler > HTTP Request
The HTTP Request sampler is added to the Thread Group. It can be configured as shown in the screenshot.
Some of the parameters that can be configured in the HTTP Request are explained below.
- Name: You can name your HTTP Request Sampler using this field
- Server Name or IP: Name or IP address of web server under test. In this case we are testing the Google homepage so we will use www.google.com
- Method: You can select several method of HTTP protocol such as GET, POST, HEAD…etc based on your requirement. In our tutorial we will use GET.
- Path: URL path to invoke on the server. For example, if path is set calendar, JMeter will invoke the URL www.google.com/calendar in the request. In this case, we keep this path blank to request to the servers root page.
- Proxy Server: This is useful if your computer is connected to the Internet via a proxy server. You can set the Server Name, Port Number, Username and Password if needed.
- Source Address: This is used for IP Spoofing and we are not going into that topic in our current tutorial.
Step 3. Add Listener
In order to save or view the results of the test, you need to add a Listener to your Thread Group.
JMeter will display the performance results of the website through the Listener. This information can be displayed in several formats such as Graph, Tree, Table, Log File etc.
In this practical exercise, we will use a Result Tree to display the statistical information of web server under test.
Right click on the Thread Group > Add > Listener > View Results Tree
JMeter will add the Results Tree Listener to the Thread Group and display the View Results Tree configuration options in the right window pane as shown in the screenshot.
You can save the test data to file using the Filename field.
You can select some options such as saving/displaying only errors or successes.
Clicking on the Configure button will display a dialog box where you can choose the information that you would like to save.
Step 4. Run the Test Plan in JMeter
Now that all the configurations are ready, let us execute the test plan. Save the test plan before running the test.
Start running the test plan by click button Start or Start No Pause button in the menu bar.
JMeter will run the test and this may take some time. During the execution the Stop button will be enabled and the small rectangle on the far right corner of the menu bar will be green.
Once JMeter completes execution, the Stop buttons will be disabled and the small rectangle indicator will turn gray.
Let examine in detail the information displayed in JMeter.
In this test, JMeter sends the HTTP request to the google.com server. The left pane of the View Results Tree lists the Sampler Responses. Clicking on a Sampler response will display its data in the right pane.
In Sampler result tab, you can see the information of the regarding the request like load time, latency, etc.
In the Response Data tab, JMeter displays the response data returned from web server. In this example it is the HTML code returned by the Google homepage.
The Request tab shows the header information for the request.
Interpreting JMeter Results
If the status of request is Success, JMeter will display the green triangle with a checkmark as shown in previous screenshots above.
There are many parameters returned by JMeter but you need to focus on two important parameters.
- Latency: It is the time in milliseconds that elapsed between the request being sent to the server and the first response being received. Lower the latency, the better the performance.
- Load Time: The number of milliseconds that the server took to fully serve the request (Load time = response + latency)
According the above report, the Load Time was 361ms. This is an acceptable response time for a web page (which was about 158033 bytes).
You can use these parameters to compare the performance between web servers under test. The lower Load Time returned by JMeter, the higher the performance the web server.
You can download the sample JMeter Test Plan to run on your computer.
In the next topic you will learn about Processors and how to use Pre-Processors in JMeter.