How to do Load Testing Using JMeter?
By DeviQA on Mon Nov 14 2016 00:00:00 GMT+0000 (Coordinated Universal Time)
JMeter is a very powerful tool for load testing with the ability to create a large number of requests at the same time thanks to parallel work on multiple computers. It supports plugins to extend its functionality. The tool can be used for testing huge Internet banking systems. In this post, I will describe how to use JMeter for load testing of your project.
You can easily download JMeter here. Go to \bin\JMeter.bat to start it.
How to do load testing using JMeter?
When running the program, you will see 2 issues on the left side: Test Plan and WorkBench. Let’s add a Thread group into the Test plan by right-clicking on the Test plan -> Add -> Threads (Users) - Thread group.
Now we’ll create test settings elements inside the Thread group: right-click on the Thread group -> Add -> Config Element and select 4 points in succession:
- HTTP Authorization Manager. We use it when we need to perform the test with the user's authorization. Click Add and fill in the Base URL of the resource, specify the username and password for the account in the corresponding Username and Password fields.
- HTTP Cookie Manager will automatically save cookies.
- HTTP Header Manager will be a title to each recorded packet. To see it, just click on the drop-down tree (we’ll create it a little later). The title can be edited.
- HTTP Request Defaults. The parameters of the settings (such as name and port of the server, queries with some parameters, etc.) will be applied to all items in the test plan, that don’t have their own ones.
Now let’s go to any browser to configure a proxy server. We prefer Firefox for such purposes. In the network settings, specify the use of a proxy and enter localhost for HTTP Proxy, 8089 for port. Do not forget to remove the exception for the localhost.
We’re now back in JMeter for load testing in the HTTP Proxy Server and it’s time to click the Start button. Now we’re back in the browser to load all the interfaces that require load testing.
Now go back in JMeter and click Stop in the HTTP Proxy Server.Note! In a situation when you need to edit the host settings in the package that’s different from the HTTP Request Defaults, it is more convenient to do the following. Save the project (File -> Save), and close it. Open the saved \*.jmx file using Notepad ++ (or Notepad) and delete the values for all rows:
- and all other parameters that need to be changed.
Save the file and open it in JMeter. We return the value to the HTTP Request Defaults. Now they also apply to those requests with their own settings specified.
It’s high time to clean the project from unnecessary information. Some packages refer to third-party services, for which we do not have to create a load. They need to be removed. To do this, you need to go through them all and see which Server Names or IPs are set. If the server name is not related to the test resource, we do not create additional load on it. Just delete them:Let’s add the viewing elements to the Thread Groups. Right-click the Thread Group -> Add -> Listener -> Graph Results, Aggregate Report, View Result in Table and View Result Tree.
The last setting before running the test is specifying the number of users (Number of Threads) and the number of iterations (Loop Count) by clicking on the Thread Group and setting the appropriate parameters.
All is ready. Start the test by pressing the green triangle on the top panel and open any of the elements to view the online statistics is in front of you. As we’ve installed the Loop Count - Forever, press the Stop after testing. Now, it’s time to analyze the results.
How to use JMeter for load testing: Analysis of Results
Graph Results displays the result as follows:
- The values are provided in milliseconds.
- Data - response time of each individual piece of data that is an URL.
- Average - the average response time, an objective timetable of load changes.
- Median - the median value (used in statistics, I do not use these data).
- Deviation - an error, standard deviation.
- Throughput - the throughput ability to perform queries.
The response time has significantly increased, the higher the requests bandwidth (less than a millisecond), the more time the server requires for processing.
Aggregate Report displays statistics for each individual URL separately:
The Average column shows the average response time, it is logical to assume that the bigger it is, the greater the load on the URL is.
View Result in Table displays the results with time and status (successful / not successful).
There’s an error at the bottom line. You can check the reason for this in View Result Tree. Let’s go over there and find this line. Now we see the cause of the error.
Now the load testing is completed. We’ve checked out one of the web applications and received great results.