Although testing is a key part of app development, many developers underestimate its importance. Skipping the testing phase could mean overlooking issues related to security, functionality, accessibility, and performance.
There are several different techniques for testing web apps, but the one we’ll be focusing on is performance testing. This is done to verify server response time and throughput under different load conditions.
A great resource for performance testing is Apache JMeter, an open-source, 100% pure Java application that load-tests functional behavior and measures performance. JMeter simulates a heavy load to test an app’s strength and analyze its overall performance under different load types.
There are four types of performance testing, and JMeter does two of those. Let’s have a look at them:
- Load Application Testing: JMeter simulates users and models expected usage. The users access the web service simultaneously, allowing you to know how many users your app can support.
- Stress Application Testing: Every web service on the planet has a load-bearing capacity which, if exceeded, means that the system won’t perform well. You could say that this is the breaking point for an application. In the testing environment, JMeter applies stress beyond the app’s bearing capacity, thereby determining the maximum load that the server can handle.
The diagram below shows how JMeter models users and simulates a heavy load:
As you can see, JMeter models users to calculate an app’s expected usage and load-bearing capacity.
How to Create a Performance Test Using JMeter
- Create a thread group
- Add thread properties (e.g., number of threads, loop count, ramp-up period)
- Add JMeter elements (e.g., HTTP request default, HTTP request sampler, output results)
- Run test
- Analyze results (e.g., throughput and deviation)
Creating a Performance Test in JMeter
Now, to help you understand how to actually do performance testing using JMeter, we’ll be testing Google’s website and modeling 1,000 users. Let’s look at each step in detail:
1. Create a Thread Group
Install and launch the JMeter application. Right-click on “Test Plan,” which you will see on the left panel. A test plan is made up of a sequence of test components that determine how the load test will be simulated.
Under “Test Plan,” click “Add,” then “Thread (Users)” and finally “Thread Group.”
You've successfully created a thread group.
2. Add Thread Properties
The Thread Group has 3 key properties that influence the load test. You enter the Thread Properties by navigating to the Thread Group control panel. These properties include:
- Number of Threads (or Users): The number of users that you want to model accessing the application simultaneously. Set the value to 100, because we want to model 100 users on the Google website.
- Loop Count: The number of times JMeter simulates a user. We will set this to 10.
- Ramp-Up Period: The time it takes in seconds for JMeter to model a new user. We’ll set this time to 100 seconds.
Understanding the difference between Loop Count and Number of Threads is critical, so let’s explain this in detail. Number of Threads are the total number of users that will connect to the web service at once, while Loop Count is the number of times an individual user connects to the web service.
Check out the diagram below for more clarification:
In the example above, JMeter creates 100 concurrent users. These users will be accessing the web service all at once. We have defined the Loop Count as 10, so that means every user made by JMeter would be connecting to the server 10 times.
3. Add JMeter Elements
You’ve created a Thread and added Thread Properties. Now, it’s time to add JMeter elements:
- HTTP Request Default: Attach the HTTP Request Defaults element to your thread.
Right click on “Thread Group” and click “Add,” “Config Element,” and “HTTP Request Defaults.” Then, enter the site or server name that you want to access under “Server Name or IP.”
Since we want to access www.google.com, we will be writing this in the server name:
This graphic shows what you’d enter into “Server Name of IP” if you were testing Google.
- HTTP Request Sampler: Add the HTTP Request Sampler to the Thread Group. Right click on “Thread Group,” then click “Add,” “Sampler,” and “HTTP Request.”
You can see these steps in the screenshot below:
Upon selecting “HTTP Request,” fill in the URL request you want to send to the server. In our example case, the server is www.google.com.
Now, fill in the item that you want each Thread, or user, to request. Fill in the “Path” field with parameters, which we will set as “calendar.” The final query would be www.google.com/calendar.
If you don’t enter a parameter in the Path field, then the user will only request www.google.com. You don’t need to specify Google here, because it was already specified in the HTTP Request Defaults item — so just enter “calendar.”
- Output Results: JMeter uses listeners to output the results of a load test. Right click “Thread Group” and click “Add,” “Listener,” and “Graph Results.”
For more clarity, see below:
JMeter is a very powerful tool that can show the results in graph format
4. Run the Test
With the basic test plan set up, it’s time to run it and see the results. Under “Test Plan” and “Thread Group,” click “View Results in Table,” then “Run” from the main menu. Click “Start,” or the green start arrow below the main menu, to begin the test.
As the test is run, the results appear in the table in real-time. In our example case, 100 users would be accessing the Google server simultaneously, with every user connecting to the server 10 times.
5. Analyze the Results
Carefully analyze the graph that you got in real time. Here are the two main factors to consider:
- Throughput: The measuring capacity of the server, or how much it can handle. Ideally, this number should be infinite, if not very high.
It’s important to note that throughput depends on other factors, such as internet speed, the Google server’s current load, and CPU power. These factors continuously change, meaning you won’t get the same results every time you run the test.
- Deviation: The variation from the average. This number should be zero, or very low.
Here is the output graph we’d get using our Google example:
As you can see, this output report comes in five colors, each of which signifies something different:
- Black- the total number of samples sent to the server
- Blue- the average of the total number of samples sent to the server
- Red- the standard deviation in real-time output
- Green- the throughput rate (the number of requests the server handled per minute)
- Purple: the median (a number which divides the samples into two equal halves)
How would we analyze this graph?
- The throughput is 867 requests per minute.
- This means that the Google server handled 867 requests per minute.
- Sometimes, the throughput even got 1,000 requests per minute.
Based on these numbers, we can deduce that Google has very good throughput.
The Importance of Performance Testing
Performance testing is a crucial step in determining how your web app will perform under heavy loads. JMeter is a valuable tool for performance testing, as it can discover the maximum number of users that your web app can handle.
JMeter does both load and stress testing; while load testing models expected usage by simulating concurrent users, stress testing determines the maximum load that a web server can handle. The results of these tests will help you reduce bottlenecks and boost performance.
Testing is one of the most critical parts of any software development project. We’ve only touched on JMeter in this article, but there are lots of automated QA software testing solutions out there. Consider choosing a development partner to help your business navigate testing nuances to ensure your app provides users with a seamless user experience.