How To Use Apache JMeter To Perform Load Test On Mobile App

In an era where mobile app performance is critical, Apache JMeter emerges as a powerful tool for conducting thorough load tests.

This technical guide delves into using JMeter to simulate real-world user traffic and network conditions, critically analyzing how a mobile app withstands varied load scenarios.

It involves configuring JMeter for mobile environments, setting up proxy settings for accurate request capture, and crafting realistic user interaction scripts.

The process aims to uncover performance metrics, such as response times and error rates, essential for pinpointing scalability and efficiency issues.

This comprehensive approach ensures that your mobile application is not only functional but also resilient under heavy user load, a key to maintaining a competitive edge in the dynamic app market.

app testing

Understanding Load Testing and Its Significance for Mobile Apps

Load testing involves simulating real-world usage scenarios to evaluate how an application behaves under different levels of demand. For mobile apps, factors like network latency, varying device capabilities, and fluctuating user loads can significantly impact performance.

Load testing helps identify potential bottlenecks, such as server overloads or inefficient code, allowing developers to optimize their apps for a smoother user experience. It enables them to anticipate and address performance issues before they affect end-users, thereby enhancing reliability and satisfaction.

Getting Started with Apache JMeter

Apache JMeter is an open-source Java-based tool renowned for its versatility in performance testing, including load testing mobile applications. Mentioned below is the guide that can help you get started with Apache JMeter:

Download and Install Apache JMeter: Visit the official Apache JMeter website and download the latest version. Installation instructions are provided for different operating systems, ensuring a smooth setup process.

Familiarize Yourself with the Interface: Apache JMeter features a user-friendly interface with various components such as Thread Group, Samplers, Logic Controllers, and Listeners. Understanding these components is crucial for creating effective test plans.

Prepare Your Mobile App for Testing: Ensure your mobile app is ready for testing by deploying it on a test environment accessible to Apache JMeter. This may involve configuring the network.

JMeter Configurations

To perform a load test on mobile applications using Apache JMeter, you’ll need to set up JMeter and configure your mobile device to connect through a proxy. Here’s a summarized guide based on information from multiple sources:

Install Apache JMeter: Ensure Java Development Kit (JDK) is installed on your PC. Download Apache JMeter and run it.

Configure JMeter for Recording:

  • Add a Thread Group to your Test Plan in JMeter.
  • Add a Logic Controller, such as a Recording Controller, to the Thread Group.
  • Add a Listener, like the View Results Tree, to observe requests and responses.
  • Add an HTTP(S) Test Script Recorder to your Test Plan. Set the port (e.g., 8080 or 8888) that will be used for recording.

Configure Mobile Device for Proxy:

  • Connect both your PC and mobile device to the same Wi-Fi network.
  • On your mobile device, go to Wi-Fi settings and modify the network settings to use a manual proxy.
  • Set the proxy hostname to your PC’s IP address and the proxy port to the one you specified in JMeter.

Install JMeter’s Certificate on Mobile Device:

  • Find the ApacheJMeterTemporaryRootCA.crt file in JMeter’s bin folder.
  • Transfer and install this certificate on your mobile device. You may need to set a screen lock password if prompted.

Record Mobile App Traffic:

  • Start the HTTP(S) Test Script Recorder in JMeter.
  • Operate the mobile app as normal. JMeter will record the HTTP requests made by the app.
  • Stop the recording in JMeter once you’re done and save the Test Plan.

Run and Analyze the Test Plan:

  • Execute the recorded script in JMeter.
  • Use the View Results Tree Listener to analyze the responses of each request.

A video tutorial to make the process clearer:

Designing Effective Load Test Plans

Creating comprehensive load test plans is essential for obtaining meaningful insights into your mobile app’s performance. Here’s a step-by-step guide to designing effective load test plans using Apache JMeter:

  1. Identify Test Scenarios: Start by identifying the key user scenarios or workflows within your mobile app. These could include actions such as logging in, browsing products, making purchases, or interacting with multimedia content.
  2. Define User Behavior Profiles: Determine the distribution of user interactions based on factors like frequency, concurrency, and duration. This helps simulate realistic usage patterns during load tests.
  3. Configure Thread Groups: Thread Groups in Apache JMeter allow you to define the number of virtual users (threads) and their behavior. Adjust parameters such as ramp-up time and loop counts to simulate gradual increases in user load.
  4. Select Appropriate Samplers: Samplers represent different types of requests sent to the server, such as HTTP requests for REST APIs or JDBC requests for database interactions. Choose the relevant samplers based on your mobile app’s architecture and functionalities.
  5. Add Timers and Logic Controllers: Timers help introduce delays between user actions, mimicking real-world user behavior. Logic Controllers enable conditional and iterative execution of test elements, enhancing test realism and flexibility.
  6. Configure Assertions: Assertions verify the correctness of server responses, ensuring that the mobile app functions as expected under load. Define assertions to validate response status codes, content, or performance thresholds.
  7. Set Up Listeners for Result Analysis: Listeners capture and display test results in various formats, including tables, graphs, and summary reports. Choose appropriate listeners to monitor key performance metrics such as response times, throughput, and error rates.

Executing and Analyzing Load Tests

Once your load test plan is configured, it’s time to execute the tests and analyze the results. Follow these steps to execute load tests using Apache JMeter:

  1. Start the Test: Run the load test plan within Apache JMeter by clicking the “Start” button. Monitor the progress as virtual users simulate user interactions with the mobile app.
  2. Monitor System Resources: Keep an eye on system resource utilization during load tests, including CPU, memory, and network bandwidth. Excessive resource consumption may indicate performance bottlenecks that require attention.
  3. Collect and Analyze Results: After the load test completes, review the results collected by Apache JMeter’s listeners. Pay attention to performance metrics such as response times, latency, throughput, and error rates. Identify any anomalies or areas for improvement.
  4. Generate Reports: Apache JMeter offers built-in reporting capabilities to generate comprehensive test reports in formats like HTML, CSV, or XML. Share these reports with stakeholders to communicate test findings and recommendations effectively.

Conclusion

So, after understanding the complete process, we can conclude certain benefits linked with JMeter mobile performance testing:

  • Zero investment since it is an open-source tool!
  • Accessible on both Android and iOS devices.
  • The simplest and most efficient tool to check mobile performance.
  • It is very user-friendly and has an interactive UI.

Hopefully, after going all through this guide, you will be capable of recording a JMeter script for mobile performance testing.

FAQs

How To Do Performance Testing For Web Application Using Jmeter?

Performance testing is done to ensure whether the application is capable enough to bear the load. It can analyse the system’s performance under high load. Jmeter performance testing offers various benefits like it can be used to test the performance of both static and dynamic resources.

Dynamic resources can be JSP, Servlets and AJAX. Static resources can be Javascript and HTML.
There are two kinds of web application testing done using Jmeter.
1. Load Application Testing: The process is mainly used to predict the expected usage by simulating various conditions.
2. Stress Application Testing: Be it any web application the architecture of it can only support a certain number of users at a time. With the help of stress testing load above this capacity will be given on the server after which it behaves weirdly. By doing so, maximum load the web server can handle can be found out.
This can be understood in a much better way by below diagram:
How to create a Performance test in Jmeter
Let’s test the Google website for 1000 users with the help of Jmeter.

  • Add Thread Group

First, start the JMeter application and click on test plan option on the dashboard.          Click on add option and then Thread(Users). Afterwards, click on Thread Group.
The Flow would be:

Add -> Threads (Users) -> Thread Group

  • Enter thread properties in the thread group control panel. You have to enter a certain number of things like :

Number of Threads: Number of users which you want to target to the target website. For example, here we will use 100
Loop Count: 10 (Number of times to execute testing)

Know More: Step by Step Implementation of App Performance Test

Ramp-Up Period: 100 (It is the delay which Jmeter has to wait before starting the next user). 100 seconds is the time which we have used.
Now, you must be confused between thread count and loop count. It is very easy to understand.
Thread count means how many concurrent users Jmeter will create to connect to the web server.
Loop count would be the number of times, Jmeter would simulate one user connecting to the target server.
Suppose in the above example: Jmeter would create 100 concurrent users connecting to the server while one user would be connecting to the server 10 number of times.

  • Adding JMeter elements

There are various JMeter elements which can be used to the test case. Let’s see what they are:
1. HTTP request default
Now, you have created a thread group and you can attach HTTP request element        to it by following the below path:

Add -> Config Element -> HTTP Request Defaults.

In the HTTP request control panel, enter the website name which you have to define. In our example, it would be “www.google.com”.
2. HTTP request
You can add this element to the thread group by following below path:
Add -> Sampler -> HTTP Request.
Now, in the control panel of the HTTP request, you have to enter the URL      request you want to send to Google. If you give the command as “calendar” in path field, Jmeter will send request http://www.google.com/calendar to google server. If you will keep it blank then send request http://www.google.com/ to google server.

  • Adding Graph Result to the test output

Jmeter can show the results in graph format. You have to right click on the test plan and then follow the below path:

Add -> Listener -> Graph Results

In this way, you will be able to see the results in graph format.

  • How to run the test and get the test result

You can see the test button on the toolbar to start the testing process. You would be able to see the test result in real time. When you will simulate 100 users which will access Google server then you will get the real-time output.
But all output lines would not be in the same colour. Some would be in black, blue, red and green colours. Black colour means the total number of current samples sent. Blue colour represents the current average of all samples sent. Red colour represents the current standard deviation. Green colour represents throughout rate that represents the number of request per minute the server handled.
How to analyse the graph results in Jmeter
There are two main parameters which you should focus while looking at the result graphs. Throughput and deviation are those which are very important while looking at any JMeter output graph.

Know More: Performance Testing-Types, Stages and Advantages

Throughput is the ability of the application to handle a heavy load. Throughput should be very high ideally. Deviation indicated deviation from average. It should be very low.
In the above graph, throughput is 867/minutes. It means this server can handle 867 requests per minute. This data is of yahoo website. While if you will test Google.com then you see throughput is 1000/ minute. Google has higher throughput than yahoo.
These parameters can vary on other factors also. Which include internet speed at JMeter site, current server load at google server, your CPU power and many others. It’s not necessary that you will get the same results every time as they can vary because of other factors.
Conclusion
So start the web application testing using Jmeter and see how much load one website can handle. In this way, you can see why your site stops responding and one of the reasons can be low load-bearing capacity.

If you had some difficulty while doing the above test then try to not connect to the internet via a proxy. If you are connecting through a proxy then don’t connect via that. Try opening a new JMeter instance and then try to run the test.
By following these you would be able to run the test cases with Jmeter. So, keep doing performance testing with JMeter and make your site less prone to vulnerable attacks. All the best!!