Topics In Demand
Notification
New

No notification found.

Performance testing guide with JMeter
Performance testing guide with JMeter

3

0

Have you ever wondered how your application performs during a surge in user traffic? Performance testing can provide the answers, and Apache JMeter is an excellent open-source tool to help you discover them. Having worked on numerous products with diverse testing needs, I've observed the increasing significance of performance testing. It has become a fundamental aspect of our TestOps process, reflecting our clients' desire to deliver the best possible customer experience.

What is a performance test?

Performance tests are a way to test software speed, responsiveness and stability under different conditions and loads. The most important goal is to ensure that the tool can manage the expected visitors to the site and preserve the overall performance over the years.

Types of performance testing

  • Load Testing: Load testing checks how well the app works when there are a lot of users using it at once, to make sure it can handle the usual traffic.
  • Stress Testing: Stress testing pushes the app beyond its limits to see when it breaks, helping us know how it fails and if it does so safely.
  • Endurance Testing: Endurance testing tests how the app performs over a long time with constant use, making sure it doesn't slow down or crash.
  • Scalability Testing: Scalability testing checks if the app can handle more users or tasks as it grows, to see if it has enough resources to grow with demand.

Why use JMeter for performance testing?

Apache JMeter is an open-source performance tool designed to test the functionality and performance of both stable and dynamic applications. Many organizations that provide software testing services rely on JMeter to perform thorough performance and load testing to ensure that applications can handle expected data traffic and stress features correctly. It lets users simulate many virtual users and monitor the system's behavior in real-time. This is especially effective: 

  • Net app test: JMeter HTTP/HTTPS is great for testing applications, including REST API, SOAP services, and websites.
  • Database test: JMeter can be used to test the performance of the database by mimicking multiple questions and measuring the response time.
  • Server load test: This allows you to consider how the server behaves under different load conditions and helps identify potential obstacles.

JMeter supports a wide range of tests, including functional, performance, and regression tests. JMeter also provides detailed reports and analysis for better insights into performance.

Steps to conduct load testing with JMeter

Step 1: Download and install JMeter. 

Ensure Apache JMeter is installed on your computer before you begin. 

  • Download JMeter: Select the most recent version from "https://jmeter.apache.org/download_jmeter.cgi" on the official Apache JMeter website. 
  • Set up JMeter: The installation of Java on your computer is essential because JMeter is a Java-based program. Run the JMeter executable from the "bin" folder after removing the zip or tar file. 
  • Launch JMeter: Double-clicking the JMeter.bat (Windows) or JMeter.sh (Linux/MacOS) file after installation launches JMeter.

Step 2: Create a test plan 

  1. Open JMeter and create a new test by right-clicking on Test Plan on the left side and choosing Add > Threads (Users) > Thread Group.
  2. Set up the Thread Group:
    1. Number of threads (users): This is how many virtual users will pretend to use your app. For example, if you choose 100, 100 dummy or fake users will send requests to your app at the same time.
    2. Ramp-up period: This is how quickly JMeter will add users. For example, if you set it to 10 seconds, JMeter will add 10 users per second until it reaches the total number you have set.
    3. Loop count: This shows JMeter how many times each user should do the test. If you set it to “1,” each user will only perform the test once.

Create a JMeter performance test planCreate performance test plan in JMeter

Step 3: Add HTTP requests (Samplers)

Now, you’ll set up what the virtual users will do on your app. These actions are called Samplers in JMeter.

  1. Right-click on Thread Group and select Add > Sampler > HTTP Request.
  2. Set up the HTTP Request:
    1. Server name or IP: Enter the website address or the server's IP address which you need to test.
    2. Path: Write the specific part of the website URL you want to test (like /login or /product-page).
    3. Method: Choose what kind of action the virtual users should perform (like GET, POST, DELETE, PUT etc.).

Add http request in JMeterAdd sampler request in JMeter

Step 4: Add listeners to view results

Listeners let you see and analyze the results of your test. You can choose different ways to view the results, like graphs, tables or logs.

  1. Right-click on Thread Group and select Add > Listener > View Results Tree. This will show you the details of each request made during the test.
  2. You can also add other listeners like:
    1. Summary report: Gives a quick overview of how the test went, including things like average response time and how much traffic the app handled.
    2. Graph results: Shows the app’s performance in a graph format.
    3. Aggregate report: Gives summary stats like average response time, error rate, and traffic handled.

View results in JMeter

Step 5: Set up assertions to check responses

Assertions help you make sure the server is responding correctly during the test.

  1. Right-click on HTTP Request and choose Add > Assertions > Response Assertion.
  2. Set up the Response Assertion: 
    1. Field to test: Choose what part of the response you want to check (e.g., the response code or text).
    2. Pattern matching rules: Define what values or patterns should be in the response (e.g., check if the response says "Login successful").

This makes sure the server is not just replying but replying correctly even when under load.

Step 6: Run the test

Once you’ve set up your test plan, you can run the test:

  1. Click the Start button (green play icon) in JMeter.
  2. JMeter will simulate the virtual users and start sending the requests.

Step 7: Monitor the results

As the test runs, JMeter will show real-time data through the listeners you added. Keep an eye on these:

  • Response time: It will show the time taken for the server to respond.
  • Throughput: It will show the number of requests that can be handled by the server per second.
  • Error rate: It will show the percentage of request that failed or had errors.

Step 8: Analyze the results

After the test is done, look at the results to find any issues:

  • High response time: If the response time is high, the server might have performance problem, like slow database queries.
  • Low throughput: If the throughput is low, the server can not handle enough requests.
  • High error rates: A high error rate suggests problems with the app or server that need to fix.

JMeter provides reports with graphs and tables to help you understand the data.

Step 9: Optimize and retest

Based on the results, you might need to improve your app, database or server. Once you have made changes:

  1. Improve performance based on what you found.
  2. Run the test again to see if the changes worked.
  3. Repeat this process until your app performs well under load.

Step 10: Generate reports

After testing, you can create reports that summarize your results:

  • The Summary Report will give you key numbers like average response time, throughput, and error rates.
  • You can save or share the results, and even export them as CSV or XML files for further analysis.

Secure application reliability with JMeter

Performance tests must be conducted to ensure the software works well in real-world situations. Tools like Apache JMeter make running load tests easier. By simulating different user activities and examining the results, you can see how well your app grows and whether it works well under stress. Focus on what you want to test and maintain an overview of your necessary performance measurements. This way, whether you use JMeter or another tool, you can make the right decisions to improve your app.

Looking to enhance your application's performance and provide a seamless user experience? Reach out to the experts at Opcito today for thorough performance testing services and to discuss your unique requirements.


That the contents of third-party articles/blogs published here on the website, and the interpretation of all information in the article/blogs such as data, maps, numbers, opinions etc. displayed in the article/blogs and views or the opinions expressed within the content are solely of the author's; and do not reflect the opinions and beliefs of NASSCOM or its affiliates in any manner. NASSCOM does not take any liability w.r.t. content in any manner and will not be liable in any manner whatsoever for any kind of liability arising out of any act, error or omission. The contents of third-party article/blogs published, are provided solely as convenience; and the presence of these articles/blogs should not, under any circumstances, be considered as an endorsement of the contents by NASSCOM in any manner; and if you chose to access these articles/blogs , you do so at your own risk.


© Copyright nasscom. All Rights Reserved.