JMeter Load Testing Tutorial
JMeter Load Testing Overview
Every web application has a maximum load capacity, and exceeding it can lead to slowdowns, errors, or overall ineffectiveness. Load testing is crucial in assessing a web application’s performance. This type of testing is a vital component of the software and application development life cycle, especially when dealing with web applications, sites, or APIs that are expected to handle significant user traffic. To ensure that your applications can perform under peak or sustained high traffic conditions, it is essential to employ performance testing tools. Apache JMeter is a popular choice for this purpose, and if you’re new to performance testing, you might be asking yourself what is JMeter? And how does JMeter work? We’ll look at JMeter and how to use JMeter for performance testing.
What is Load Testing?
Load testing is a type of performance testing to determine how your web application behaves during normal and peak load conditions or even to find the breaking point. It’s the practice of simulating real-world usage, or load, on any software, website, web application, API, or system to analyze and identify factors such as responsiveness, degradation, and scalability.
Tools for Load Testing
Load Testing tools are extremely important to streamline your load testing needs and to improve your digital performance. There is no end to the amount and variety of tools and platforms in the market today, with a variety of features. There’s plenty of load testing tools such as:
-
- LoadView
- Apache JMeter
- WebLOAD
- LoadRunner
- Tricentis NeoLoad
- LoadNinja
For this guide, we’ll look at JMeter load testing. We’ll answer some questions such as: what is JMeter, how to do JMeter load testing, and how to use JMeter for API performance testing.
What is JMeter Load Testing?
Apache JMeter, also known as JMeter, is a widely used open-source software designed as a 100% pure Java application for conducting load testing of functional behavior and assessing performance. It is a preferred tool among developers and software development teams for performance tests due to its extensive documentation, strong community support, and established best practices. Moreover, being free and open-source makes it a cost-effective choice, but since it’s 100% Java, it may take your team additional time and resources to initiate testing processes.
JMeter supports a range of protocols, including HTTP, HTTPS, FTP, and more, making it versatile for testing different types of applications. Users can create and execute test plans that define various scenarios, such as simulating user interactions, monitoring server performance, and analyzing response times.
JMeter load testing is designed to conduct load tests on functional behavior and measure its performance. You can use JMeter to analyze and measure the performance of web applications or services. By analyzing the data collected and generating reports, you can observe the behavior of the application and identify performance bottlenecks, providing valuable insights into areas where application enhancements are required.
Why use JMeter?
- Open source: JMeter is completely free, and developers can use the source code.
- Platform Independent: JMeter is 100% and can be run on multiple platforms.
- Support for Multi-Protocol: JMeter supports both web application testing and database service performance. It supports all basic protocols such as HTTP, JDBC, LDAP, SOAP, JMS, and FTP.
- Record & Playback: JMeter allows you to record the user activity on a browser to be simulated and then you can playback recording.
- Customizable Reporting: Visualize your test results in different formats such as charts, tables, or tree and log files.
- Community Support: There is a large community with help, guidance, and tutorials.
- Extensibility: JMeter can be extended with plugins to enhance its functionality, allowing users to tailor the tool to their specific needs.
Benefits of JMeter Load Testing
Using JMeter for load testing offers several significant advantages. Firstly, it’s freely available, making it accessible regardless of budget constraints. Secondly, it’s powerful enough to simulate real-world scenarios effectively, helping testers understand how their applications perform under different loads. JMeter’s scalability is another key benefit, as it can handle large-scale testing effortlessly. Lastly, its detailed reporting and analysis features enable teams to pinpoint performance issues early on, making it easier to optimize applications and improve overall reliability.
One of the key benefits of using JMeter for load testing is its user-friendly interface which enables testers to build complex test scenarios without extensive programming knowledge. Also, JMeter provides detailed reporting and visualization features that help teams understand test results and identify potential performance bottlenecks.
How to Perform JMeter Load Testing
Let us look at some of the steps involved in how to use JMeter for load testing and how to configure a basic load test.
Step 1: Verify System Compatibility for JMeter Installation
Before proceeding with JMeter installation, it’s crucial to ensure that your system meets the requirements. JMeter is Java-based, so you need to have Java 8 or a higher version installed on your system. Confirm that your operating system is compatible with JMeter. JMeter is designed to work on various operating systems, including Windows, Linux, and macOS.
Once you’ve confirmed that your system meets these basic requirements, you’re ready to proceed with the JMeter installation. This ensures a smooth setup and optimal performance during load testing.
Step 2: Downloading and Installing JMeter for Your System
After ensuring your system meets all necessary requirements, proceed to download the latest JMeter version—choosing between binaries or source files based on your specific needs. Binary files, comprising of pre-compiled JMeter versions, can be run immediately, while source files provide flexibility for manual configuration and compilation by developers or teams. Typically, binary versions are preferred for ease of installation. Different file download types, such as .zip and .tgz, are available.
Once you’ve selected your preferred version, download it to your system. You can then open the file, move it to a designated location, or create a new folder for future access. Begin the extraction process, which may take a few minutes. Note that installation steps may vary depending on your operating system, but once installed, JMeter’s functionality remains consistent.
Step 3: Create a Load Test Plan
JMeter users can begin creating their load test plan from scratch or also select from various test plan templates located from the File drop-down menu. Templates include SOAP WebService Test Plan, basic and advanced Web Test Plan, FTP (File Transfer Protocol) Test Plan, Functional Testing Plan, and many others. These test templates will include all the necessary specific elements, sections, and fields that you will use to create and build your load test plan.
To create a Test Plan, simply navigate to File and select New or select the New button from the Tool Bar. It is important to note that you must run JMeter in GUI mode to create the Test Plan. The CLI, or command line interface, is used to execute the load test. Next, we will talk about specifying the number of users for your load test, which is also known as the Thread Group.
Step 4: Add and Configure Thread Group in JMeter
To incorporate a Thread Group, follow these steps: Right-click on Test Plan, hover over Threads (Users), and click Thread Group.
In the ensuing Thread Group dialog box, you can edit various Thread Properties such as Number of Threads (Users), Ramp-up period (in seconds), and Loop Count (test iterations). Additionally, specify actions like delays, set test start and stop times, and define responses to Sampler errors. Thread properties are:
-
- Number of Threads: Represents the quantity of virtual users connecting to the server.
- Ramp-Up Period: Denotes the time JMeter takes to transition the specified number of threads into a running state.
- Loop Count: Indicates the number of times each thread executes the task.
- Loop Count Infinite: When activated, it disregards the loop count, causing an infinite loop until manually stopped.
- Delay Thread Creation until needed: Delays thread creation until a specified value (in seconds) is reached.
- Scheduler: Enables scheduler configurations for scheduling tests at specific times when activated.
This step enables meticulous customization of load test parameters, providing users with control over concurrency, duration, and specific test conditions.
Step 5: Configure Sample in JMeter
In JMeter, Samplers allow JMeter to send different types of requests. For example, these can be an HTTP request (for a website, application, or API), FTP request, SMTP request, TCP request, and many others. From here, you enter additional details such as the Protocol (HTTP/S), Server Name or IP, Path (for specific web page), and what type of request, such as GET, POST, HEAD, PUT, etc., which can be used for API load testing.
Step 6: Configure Listeners
To analyze Sampler results in JMeter, the next step involves configuring what is referred to as Listeners. In the JMeter Test Plan window, you can choose from various Listeners, including Summary Report, Aggregate Graph, View Results Tree, View Results in Table, and numerous others, to thoroughly inspect and analyze your test outcomes. Moreover, you have the flexibility to add multiple Listeners to a JMeter Test Plan. Once this is done, your Test Plan is ready, and you can proceed to execute the test.
Step 7: Recording the Load Test Scripts
If your goal is to conduct basic HTTP or protocol-level load tests without extensive configuration, there’s no additional setup required. However, if you require a test that closely resembles your user’s actions, you’ll need to utilize the HTTP(S) Test Script Recorder in JMeter.
In the Thread Group, you should add the Recording Controller. This controller lets you navigate a site or application, recording your actions through HTTP/S requests. You can also include multiple Recording Controllers per page, and this saves you time so that you don’t have to manually add each request.
The downside to this is that your recording is done with HTTP/S requests and it’s not recording within a real browser from the user’s perspective. You can also record browsers using the JMeter Proxy Server, but this can be a tedious and difficult process. If you’re looking for an easier and intuitive solution, you can opt to use LoadView which has the EveryStep Web Recorder. LoadView’s recorder provides point-and-click scripting using real browsers without the complex and time-consuming setup in JMeter.
Step 8: Run and Execute the Load Test
After you have configured all your load test details and settings, save your test plan. Then you can simply select the Run button in the Tool Bar and your test will begin. Remember to run the test in CLI mode to get better results.
Step 9: View Load Test Results
You will see the test results in the table, but this may depend on your listener. Your results will include additional metrics, such as Time (in milliseconds), Status (shows valid responses and errors), Bytes and Bytes Sent, Latency, and Connect Time. By examining these results, you can identify the locations of any errors or instances of slow load times.
How to Perform API Load Testing with JMeter
Previously, we discussed the step-by-step instructions on how to set up a protocol-based load test on a website or application with JMeter. We’ll now cover testing different APIs, such as SOAP and REST APIs, with JMeter. The installation and setup procedures remain consistent with the previously mentioned steps. However, we’ll focus on fundamental aspects of API testing and discuss important considerations when conducting API testing using JMeter.
Rest API Testing with JMeter
RESTful APIs, short for Representational State Transfer APIs, play a vital role in developing diverse web services. In contrast to SOAP APIs, REST is not a protocol but an architectural style relying on URIs (Uniform Resource Identifiers) and the HTTP protocol.
Step 1: Create a Load Test Plan
To begin, open JMeter. You will see that a new Test Plan window will open. If you already have JMeter open, you can also select the New button from the Main Tool Bar to create a new Test Plan.
Step 2: Add and Configure Thread Group in JMeter
Similarly to the previous section, the Thread Group window is where you can add the number of users (Threads), set the ramp-up time, and number of test iterations (Loop Count) and edit many more properties.
Step 3: Configure Sampler
Next, we need to add the Sampler. You can choose from some pre-configured Samplers in JMeter or select from one of your own. For this example, we’ll use a pre-configured option.
To initiate this process, right-click on the Thread Group, triggering a drop-down window. Choose Add, then Sampler. A list of Sampler options will appear. For API testing, opt for HTTP Request, opening the configuration window where you can name your test and set up the parameters for your REST API test. It’s worth mentioning that the HTTP Request window is divided into Basic and Advanced sections. For this test, we’ll concentrate on the Basic settings. Various fields, including Protocol, Server Name or IP, Port Number, HTTP Request (GET/POST/HEAD/PUT/DELETE, etc.), parameters, and more, are available for configuration.
To begin, enter the API URL in the Server Name or IP field (just the domain name), along with the appropriate protocol, and in the Path field, add the path of the API.
If this is a GET request, select GET from the HTTP Request list.
If you have certain parameters, such as a specific page, you can add that portion of the URL in the Parameters field.
You can also include it in the Path field as well, however, by adding it to the Parameters field, you have additional field options, such as URL Encode?, Content-Type, and Include Equals?
For certain requests, it’s necessary to include request headers. To accomplish this, go to the HTTP Request in the Test Plan window. Right-clicking will reveal a drop-down menu; select Add, then Config Element. This action opens the available options. In this case, opt for HTTP Header Manager. The ensuing HTTP Header Manager window allows you to input your API headers. After configuring your settings, proceed to the next step.
Step 4: Add Listeners
To include Listeners, simply right-click on the Thread Group, choose Add, then Listener. This action prompts a drop-down menu offering over 15 options to select from. Popular choices include View Results Tree and View Results in Table. It’s important to note that Listeners offering graphical representation, like View Results Tree, may consume more memory and CPU. After adding your Listeners, save your test plan.
Step 5: Run the Test and View the Results
Once you’ve configured and saved your load test details and settings, initiate the test by clicking the Run button in the Tool Bar. The window will display your Sampler results, presenting various details, data, and metrics—such as latency, response codes, connect time, etc.—pertaining to your REST API test.
SOAP API Testing With JMeter
SOAP (Simple Object Access Protocol) stands distinct from a REST API as it operates under its own protocol. When load testing SOAP APIs, specific considerations arise, including security and compliance, bandwidth requirements (SOAP APIs typically demand more resources), and functional aspects like retry logic, which is absent in REST APIs.
Step 1: Create a Load Test Plan
JMeter offers a range of Test Plan templates accessible through the Menu or the Templates icon in the Main Tool Bar. One of the options available is “Building a SOAP WebService TestPlan.” Choosing this option will generate and open the corresponding Test Plan. As this is a template, certain fields will contain placeholder values that require you to input the relevant data and information.
Step 2: Input Data
Similar to what we discussed in the configuration of REST APIs, you’ll need to input the number of users (Threads), ramp-up period, and loops (test iterations) for SOAP API testing.
Within a sub-group of the main Thread Group, you can access HTTP Request settings, akin to the REST API setup we covered earlier. However, the layout of this section differs, defaulting to displaying the SOAP API request body. This section also includes sub-sections for HTTP Header Manager and Response Assertions. Similar to REST API configuration, you can incorporate additional Config Elements, such as the HTTP Authorization Manager, if specific authorization details need to be included.
Step 3: Add HTTP Request Sampler
For a SOAP API load test, you will want to add the HTTP Request Sampler. In this window, you’ll need to input the relevant details, including Server Name or IP, Path, HTTP Request, Port Number, and the Body Data of the SOAP request.
Step 4: Add Listeners
Once you have configured the Test Plan, you’ll need to add your Listeners, which will display your test results. Again, you can add as many Listeners as you like and as appropriate for the SOAP API load test.
Step 5: Run Your Test
Once your Test Plan configuration and settings have been set, you can finally run your SOAP API load test and review the results once it has finished.
Conclusion
By now, you should’ve learned what JMeter is, how to do JMeter load testing, and how to perform load tests for APIs with JMeter. As you can see, setting up load tests with JMeter comes with many different steps and configuration options, which equates to plenty of time spent setting up tests, rather than running them. Even though JMeter is an open source and free solution, you may need to look for other load testing tools that provide better features and suit your business needs.
LoadView: The Best JMeter Alternative
LoadView stands out as one of the premier paid performance testing solutions available today, offering an array of features. These include a point-and-click script recorder, access to a global network of load injector servers, and the ability to configure various load curve scenarios for enhanced testing flexibility. In contrast to JMeter, LoadView requires no additional infrastructure or considerations as everything is managed seamlessly. Unlike JMeter, which is limited to protocol-level load tests, LoadView employs real browsers, allowing you to assess actual performance for critical sites, applications, and APIs. Additionally, LoadView provides multiple options, such as whitelisting static proxy IPs or utilizing an on-site agent, enabling tests on applications behind your firewall and providing greater flexibility for performance testing.
LoadView delivers user-friendly performance reports and dashboards, offering clear insights into the factors contributing to suboptimal performance. Additionally, it includes a reference video for web page and web application tests, enabling a direct comparison with the reports to visualize the user’s perspective. LoadView provides flexible month-to-month and annual plans, accompanied by 24×7 support for all customers, irrespective of their chosen plan, distinguishing it from some other tools in the market.
Next Level
Experience unparalleled features with limitless scalability. No credit card, no contract.