How to perform a JMeter load testing in 3 simple steps

Blog post

Before releasing an application to the general public, you want to ensure your app is fully optimized, capable of high performance, and ready to endure considerable traffic for your client.

If you have doubts about your app breaking down under a load of a high visitor count, fear not — you can easily test this before the application gets into the hands of customers. Read on to find out how a load test is performed and how it can help you in the final stage of developing an app.

How do you benefit from load testing?

Thanks to load testing, we can check how systems operate under a large number of simultaneous virtual users carrying out transactions over a period of time. The load test answers two basic questions: “Does my system do what I expect it to do under these conditions?” and “Does it perform well?”. In the Microsoft guide Performance Testing Guidance for Web Applications, load tests are defined as the following:

 

A load test enables you to measure response times, throughput rates, and resource-utilization levels, and to identify your application’s breaking point, assuming that the breaking point occurs below the peak load condition.

 

Three steps are crucial for a complete load test: preparation, implementation, and analysis. To better understand the importance of load testing, let’s demonstrate these steps with an example of how to perform a load test on the Google website using tools such as JMeter and BlazeMeter.

1. Load test preparation

Proper preparation is crucial if you want your load test to succeed. This means identifying the correct targets in test cases, test groups, and expected results. As we have mentioned before, we will show the Google Chrome website load test as an example. There are three test cases that the virtual users will go through on the Google website, as you can see in this table:

Test case / Test stepsSearch Quality weekYouTubeImages of cats 
1Open Google ChromeOpen Google ChromeOpen Google Chrome
2In empty field add Quality weekClick on YouTube iconClick on Google images
3Click on Search iconIn empty field add text “House relax”In empty field add text “cat”
4Click on the first link that shows upClick on Search iconClick on Search icon
5Scroll to the bottomExitClick on the image when it shows up
6ExitExit

Load test preparation - test cases table

 

After writing the test cases, we should define:

  • the number of virtual users
  • thread start-up period
  • how many times the virtual users will perform test cases (loop)
  • the duration of test cases.

 

Here you can see the defined values for the specified parameters.

Virtual users11060200
Thread startup period (sec)0049
Loop1111
Duration (sec)102030120

Load test preparation - Test groups table

 

We have only one parameter left to define — the expected results, which are very important because we are going to compare them with the results actually achieved. These are our numbers, aka the expected time required by virtual users to complete the defined test cases.

Virtual users/Test case11060200
Search Quality week2 sec5 sec15 sec35 sec
Youtube7 sec 12 sec 22 sec 40 sec
Images of cat10 sec16 sec32 sec42 sec
Total19 sec 33 sec69 sec117 sec

Load test preparation - Expected results table

As soon as we’ve defined these three parameters, we are ready to move forward with the next step: implementation.

2. Load test implementation

We will use the two tools mentioned earlier to implement the load test, BlazeMeter and JMeter. In this example, we will use the BlazeMeter extensions on Chrome to record test case steps. Next, we will save the recorded scripts and open them in the JMeter tool.

BlazeMeter

BlazeMeter is an easy-to-use, open web application available to anyone, making work simpler for Quality Assurance engineers everywhere. It’s an advanced SaaS tool that increases the capability of JMeter by being able to simulate up to 10 million users, providing advanced test analysis and collaboration, and having functional and API testing capabilities.

The Chrome browser includes a BlazeMeter extension that captures all HTTP/S requests and actual user interactions sent by the browser, creates JMeter or Selenium scripts, and automatically sends them to the BlazeMeter application, where the script can be executed with just one click. The extension can also enable debugging and testing of a recorded Selenium session on a local Chrome browser, and JMeter can be used to locally debug and improve the JMX file created by the Chrome extension to ensure the script is ready. We will show how the extension works, and the recorded script resulting from the BlazeMeter extension will be edited in the JMeter tool.

 

After you go on Chrome extensions and add BlazeMeter extensions, you will see the BlazeMeter icon in the top right corner. To record your steps, click on the icon to get the following image. When you add the name of our test case and click on the red button, it starts to record the steps defined in our test cases table.

After you finish and click the “Stop” button, the steps are documented and you can edit record scripts and see every API request we recorded.

Load test implementation - The BlazeMeter editor with API requests

Load test implementation - The BlazeMeter editor with API requests

Load test implementation - The BlazeMeter API request details

Load test implementation - The BlazeMeter API request details


After recording the three test cases: Search a “Quality week” phrase, YouTube, and Images of cats, you need to save the records. On the top right of the BlazeMeter editor, you can find the “. JMX” button, and when you click on it, the recorded case is saved on your computer with the .JMX extension. You can also save the recorded case with a .JSON extension or Taurus, but in this case .JMX is needed to add a recorded case in the JMeter tool.

Apache JMeter

Apache JMeter is an application designed to carry out a load test and measure the performance of the tested system. Apache JMeter is used to test the performance of dynamic web applications and static and dynamic resources, simulating a large load on a server, server group, network, or facility to test its strength or to analyze performance under different loads.

 

The Apache JMeter tool is free and allows the use of source code for system development. It has a simple user interface, so it doesn’t take much time to get familiar with it. You can also run it on multiple platforms and it allows the simultaneous operation of different functions of separate test groups.

The results from the application can be shown in different formats, such as trees, charts, tables, and log files. You can also write your tests and include basic protocols such as HTTP, JDBC, LDAP, SOAP, JMS, and FTP. The JMeter application can also record/playback the tests.

Now let’s get back to our steps! 

Once we have the recorded test cases, we must install Apache JMeter. You first need to download the latest version of Java, then install Apache JMeter and run it. Once the installation is completed, you should see this screen:

Load test implementation - Apache JMeter

Load test implementation - Apache JMeter


Now add recorded test cases to JMeter GUI. With the right click on the “Test plan” element and a click on the “Merge” element in the dropdown menu shown here, we repeat the process until all the recorded cases are added.

Load test implementation - Added recorded case in Apache JMeter

Load test implementation - Added recorded case in Apache JMeter


After adding all the required saved cases, this is what you’ll get: on the left side you can see all the saved APIs, and on the right side you can see the details of the APIs, which you can change.

 

Load test implementation - Recorded API requests in Apache JMeter
Load test implementation - Recorded API requests in Apache JMeter

 

On the left side, above the recorded cases, there is a “Thread Group” element. When you click on this element, the right side opens the “Thread Group” details. Here you add the data from our Load test preparation table.

Load test implementation - Recorded Thread Group in Apache JMeter

 

Once you have defined all these elements in the JMeter, you need to create a .csv document where the results are saved, and create a folder where that report will be generated in. The test can be performed directly in JMeter or via the console. It’s recommended to do it via the console if tests are performed on a local server, to minimize complications and misunderstandings.

Load test implementation - Command in the console for running the Load test

 

The command line to run the test consists of:

  • sh jmeter – indicates the program the action is performed in
  • -n – indicates operating mode without GUI
  • -t – indicates the location of the JMeter script
  • Script path
  • -l – indicates the location of the .csv file or the file the results are saved in
  • Path to the .csv file
  • -e – indicates the creation of an HTML report
  • -o – indicates the creation of a report folder
  • Path to the folder where the HTML report will be saved.

 

After you put in the command, you get the screen from the following image, where you can see the results of the load test. You can see that we are adding 200 virtual users, each user connecting to the test every 9 seconds. When the load test is completed, the message “End Run” will appear. You must repeat the command after modifying the data in Thread Group in the Apache JMeter application for 1 user, 10 users and 60 users. For each change, you need to create a new folder and .csv file to obtain and compare all the reports for each number of virtual users.

Load test implementation - Command running Load test in console

 

The report during testing consists of a summary of the average execution time, the minimum and maximum execution time and the number of active and started users, as well as the number of users who have completed their paths. At the end of the test, the recorded data is verified and the test group values are modified.

3. Load Test Analysis

As mentioned before, the analysis will be done using the generated HTML reports from the folder specified in our console command. Once you open the HTML report, you will see charts and tables with the data needed to get the answers to our questions: “Does my system do what I expect it to do under these conditions?” and “Does it perform well?”. As part of the analysis, you need to compare the results achieved with the expected results (defined in step one, preparation). In this video you can see an HTML report for 200 virtual users, just to show an example.

 

Expected results:

Virtual users/Test case11060200
Search Quality week2 sec5 sec15 sec35 sec
YouTube7 sec12 sec22 sec40 sec
Images of cats10 sec16 sec32 sec42 sec
Total19 sec33 sec69 sec117 sec

  Load test analysis – Expected results

Obtained results:

Virtual users/Test case11060200
Search Quality week3 sec9 sec21 sec214 sec
YouTube11 sec17 sec45 sec1904 sec
Images of cats7 sec13 sec34 sec316 sec
Total21 sec35 sec100 sec2434 sec

Load test analysis – Final results

Conclusion

Based on the tabular display and the HTML report, we can conclude that the system performs as intended in the given conditions. We can see that 80% of requests to the server have succeeded and 16% have failed, which means that the system can support multiple users at once. Make sure to inform your team of the results in order to clearly define if the system works and is in line with the expected behavior. Next, when we compare the expected results with the final ones, we see a big difference in the test cases when we have 200 users at a time. The system is expected to be slower, as the server is busier with requests and responses.

 

For our example test, we used the Google website, which is a great system and must be able to receive many requests and send many replies. This shows how important the load test is for large systems and for systems visited by many people. After completing the load test, you will understand how your app performs, as well as how it will behave if loaded with a large number of users, i.e., a large number of calls and responses at the same time.

 

I hope you found something new and will use this guide to create your own loading test. If you have any problems or have any other questions, please feel free to contact me. 

Good luck!

Similar blog posts

Get in touch