Development, Thought Leaders

How to Use JMeter to Test Your Web Application

December 5, 2019

by Karishma Nimavat

SEO Expert and Content Writer, NEX Software

When developing an application, it’s important to know how it performs under various workloads. Performance software testing helps determine how responsive and stable an app will be in different scenarios.

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. 

JMeter flexibly tests the dynamic and static resources of an application. Now, you might be wondering what these resources are. Dynamic resources include JSP, Servlets, and AJAX, while static resources are Document Object Model (DOM) elements like JavaScript and HTML. 

There are four types of performance testing, and JMeter does two of those. Let’s have a look at them:

  1. 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. 
  2. 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: 

Create a copy of sampler individual users can use to send requests and receive HTTP responses.

Source

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

  1. Create a thread group
  2. Add thread properties (e.g., number of threads, loop count, ramp-up period)
  3. Add JMeter elements (e.g., HTTP request default, HTTP request sampler, output results)
  4. Run test
  5. 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.

Right click on “Test Plan,” which you will see on the left panel.

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:

  1. 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.
  2. Loop Count: The number of times JMeter simulates a user. We will set this to 10.
  3. 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:

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.
 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.

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.

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.  

The red box is where you’d enter “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:

Right-click "Thread Group" > Add > Listener > Graph Results

JMeter is a very powerful tool that can show the results in graph format

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. 

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:

The output report comes in five colors, each of which signifies something different.

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. 

Related Articles More

How to Hire Programmers if You Aren’t a Tech Person
How to Build a Successful Product: A Framework for Entrepreneurs

Stay Updated With Clutch

Never miss new content. Subscribe to get weekly content roundups – delivered straight to your inbox.