Tuesday, May 17, 2011

Running the load test


You can also view the graph for your test after running it. For this go to Thread group -> Add -> Listener -> Graph results as shown in the picture below. After clicking on the graph element, you will see the chart getting populated with the data representing requests to the server.  


The chart  above shows the Test results with number of threads = 5, ramp-up time = 10, loop count = 100, and loop controller set to 1.
Three parameters on the charts have been displayed - throughput (green line), median (purple line) and average (blue line). If we modify the parameters to simulate a higher load on a server by increasing the number of threads to 50, and changing the ramp-up time to 5 and loop count to 20, then we get the following graph by clicking the start again.

The meaning of the parameters at the bottom of the chart is as follows: 
  • The number of requests processed by the server per minute is denoted by Throughput.
  • Average is being calculated as the total time running divided by number of requests sent to the server.
  • Time is represented by Median i.e. server's half response time is lower than this number.
  • The variation in the server's response time is denoted by Deviation.
  • The completion of any last request is shown by Latest.
The summary of the above two runs is shown below in the form of a table.
 Number of threads Throughput, responses/minute Average, ms Median, ms
 5 1665 57 31
 50 1749 314 62
You can also add the Spline Visualizer to further visualize the test results of all sample times. It provides a smooth view of distribution based on polynomial approximations as a continuous line. The picture below displays the screen of Spline Visualizer.
The same test results have been shown using Spline Visualizer.

Using JMeter for a Simple Test


     
Lets see how to run JMeter now. We will conduct a simple test to set up a test plan and stress test a Web application. Before proceeding with the test we need to have a test plan first which will help the Jmeter to perform the testing in steps. There are several elements in a test plan like thread groups, listeners, assertions, sample generating controllers, logic controllers etc. Well, these elements will be described later. One point to remember here is that a test plan must have at least one thread group having all other JMeter elements which is the starting point of a test plan. All of the other threads created by the Jmeter to simulate simultaneous users will be controlled by this thread group. Lets go through the steps now.
Step 1: Start JMeter by running the JMeter.bat file for Windows or the JMeter file on Unix.
Step 2: Create a thread group by right-clicking the Test plan element as shown in the picture below. Now select ADD and then the Thread group option. After selecting the thread group option a thread group element will be created by the Jmeter under Test Plan element. This is to confirm about the number of users to be stimulated by you and the number of times the test plan to be repeated. 
The screen after creating the Thread group appears like this.
Following properties can be set as shown below:
Name -- You can give any name to the thread group.                                               Number of Threads -- You can enter as many threads to stimulate a load test. A single user is represented by each Thread so if you wish to simulate a load test with 5 concurrent users then you need to enter 5 as the value for this property.                 
Ramp-Up Period -- 
It indicates the time taken by Jmeter to create all of the threads needed. If you set 10 seconds as the ramp-up period for 5 threads then the JMeter will take 10 seconds to create those 5 threads. Also by setting its value to 0 all the threads can be created at once.                                                                 
Forever -- If you choose this option then the Jmeter will keep sending the unspecific requests to the tested application. And if disabled then the test will be repeated the number of times entered in the Loop Count box.                                                                                                           
Loop Count -- 
By specifying its value Jmeter gets to know that how many times a test is to be repeated provided that the Forever check box should be unchecked.                                 

Step 3: Now you need to mention the HTTP request (URL and parameters). To this right click on the Thread Group node then you need to select Add -> Sampler -> HTTP Request as shown in the picture. 

The picture below shows the screen of HTTP Request in which you can set some properties as described below. Here address which we have taken for the "Hello World" servlet ishttp://localhost:8080/examples/servlets/servlet/HelloWorldExample.
The following properties can be set on the HTTP Request screen.                        
Name -- You should put a descriptive name as a thread group can have multiple HTTP Request elements.                                                    Server Name or IP -- Mention the server name or the IP address of the machine which is running the application to be tested.
Port Number -- Give the port number on which the Web applications run which is usually 80.  Protocol -- Mention the protocol to be used here i.e. either HTTPS or HTTP.Method -- The GET or POST method is to be mentioned here.                 Path -- You need to mention the path of the resource that will handle this request.                       Follow Redirects -- follows redirections, if any, sent by the Web application.Parameters -- This option shows the list of parameters sent with the request. You can add and remove parameters by using Add and Delete buttons.
Send a file with a request -- With the help of this option a file upload can be simulated to the Web application.
Retrieve all images and Java Applets -- This option is used to download embedded content.

Step 4: Now the format of the results is to be selected to get a page containing the results of every request by right-clicking on the Thread group node then select Add -> Listener -> View Results Tree.
Step 5: Now its time to run the Test plan by selecting Run from the menu and then select Start (or Ctrl-R): Hence The test plan will be repeated 10 times in View Result Tree as shown below.

Step 6: The results can been seen in the Results Tree after the completion of the Test plan. As you can seen in the picture below we have selected the first request in the upper pane and also the request which was generated with the results in the form of an HTML page with the text "Hello World!"


Step 7:  JMeter has got an interesting feature which is Add more listeners. You can add a View Results in Table listener to view the requests in tabular form as shown below.
Moreover you can add an Aggregate Report listener to get the summary of run as shown below.   
                                                                                    
Step 8: To save the test plan for later use select File from the menu and then Save Test Plan (or Ctrl-S). Its preferable to save the test plan before running it.