One important aspect of load testing is the ability to simulate real-world scenarios, often involving users performing actions at varying speeds. To simulate this, Apache JMeter provides various timers and delays that can be used to control the pace at which requests are sent to a web server. In this article, we will discuss how to set up JMeter timers and delays to simulate real-world scenarios in load testing.
Table of contents
- What are JMeter timers?
- How to add timers in JMeter?
- Types of JMeter timers and their configurations
- How to view JMeter timer results
- Conclusion
What are JMeter timers?
JMeter Timers are essential components of performance testing that allow users to replicate real-world scenarios where users don’t interact with a web application uniformly. These timers can introduce think times, pacing, or random delays between requests, improving test scenarios’ realism.
By simulating various user behaviors, JMeter Timers contribute to more accurate performance assessments, enabling testers to identify potential bottlenecks and optimize system performance under different conditions. Timers can be customized based on specific use cases, like constant delays, Gaussian random delays, or synchronization pauses to simulate concurrent user activities more effectively.
How to add timers in JMeter?
Launch JMeter and open the test plan where you want to add a timer. Then, add a Thread group for the test plan.
Right-click the selected test plan or thread group and navigate to Add -> Timer in the context menu.
A submenu will appear with various timer types. Choose the type of timer you want to add from the dropdown list.
Types of JMeter timers and their configurations
Here are some of the JMeter timers that are available for you to use. We will also discuss how to configure them, and we will go over what elements or parameters are present in each of them.
Constant timer
The constant timer adds a fixed delay or pause between requests. The delay time can be set in milliseconds. It is useful when you want to simulate a specific delay between requests, regardless of the previous response time.
This timer is particularly beneficial for scenarios where consistent pacing between requests is essential for accurate performance testing. It ensures a controlled and uniform flow of requests, allowing testers to observe the system’s behavior under a steady load.
How to add constant timer
To add a constant timer to a thread group, right-click on the thread group and select Add, then Timer, and finally Constant Timer.
How to configure constant timer
In the Constant Timer configuration, you can specify the timer’s name for identification, provide comments for documentation, and set the thread delay in milliseconds.
This parameter, known as the thread delay, determines the duration of the pause between each request initiated by the thread. It plays a critical role in controlling the test pacing and is particularly useful when enforcing a consistent delay between requests, regardless of the preceding response times.
Adjusting the thread delay allows for fine-tuning the simulation, ensuring that the test accurately reflects real-world user interactions and helps identify potential performance issues under controlled and realistic conditions.
Once you add the timers in the Thread Group, you can enable or disable the Constant Timer. Just right-click on the added timer under the thread group, and you will find a Disable button there. Once you click on it, the timer will be disabled. To make it available again, go to the exact location and click Enable.
Gaussian random timer
The Gaussian Random Timer in JMeter adds a random delay between requests based on a Gaussian distribution. It is a valuable tool for simulating user behavior where users perform actions at varying speeds.
This randomness introduces a realistic touch to performance tests, allowing for a more accurate representation of user interactions and enabling testers to uncover potential system vulnerabilities under diverse and dynamic conditions.
Note
To add a Gaussian random timer, follow the same steps as the Constant timer.
How to configure Gaussian random timer
Once you add the timer, you will have the following set of parameters under it:
Deviation (in milliseconds): Adjust this parameter to control the spread or width of the Gaussian distribution. A higher deviation results in a broader range of random delays.
Constant Delay Offset (in milliseconds): Specify the baseline delay that will be applied uniformly to all requests. This constant delay provides a starting point for the random delays introduced by the Gaussian distribution.
Uniform random timer
The Uniform Random Timer in JMeter is a timer element that introduces randomness to the pacing of requests by adding a random delay based on a uniform distribution.
Unlike constant timers that apply a fixed delay, the Uniform Random Timer allows for variability within a specified range. In more technical terms, the Uniform Random Timer in JMeter selects a delay value uniformly at random from the defined range for each request.
Note
Follow the same steps as the Constant timer to add a Uniform Random Timer.
How to configure Uniform random timer
Its configuration involves two essential parameters:
Random Delay Maximum (in milliseconds): This parameter sets the upper limit for the random delay that will be added to the thread sleep time. It defines the maximum range within which the random delay can vary, contributing to the variability of user interactions in your performance test.
Constant Delay Offset (in milliseconds): Representing the minimum delay added to the thread sleep time, this parameter establishes a baseline delay applied consistently to all requests. By combining this constant offset with the random delay, the Uniform Random Timer allows for a flexible and realistic simulation of user behavior.
Synchronizing timer
The Synchronizing Timer in JMeter coordinates multiple threads in your test plan by pausing them until a specified number of threads have reached a designated point. That can be useful in load-testing scenarios where you want to ensure that threads start executing simultaneously and produce accurate JMeter test results. To use it, add the timer to your test plan and configure the options as needed.
How to configure Synchronizing timer
Once you add the timer, you will have the following set of parameters under it:
Number of Simultaneous Users to Group by: This parameter allows you to define the number of threads to be synchronized by specifying a target number. Once this target number of threads is reached, the timer simultaneously releases all the waiting threads.
Timeout in milliseconds: A timeout value can be set to handle situations where the expected number of threads might not be reached within a reasonable time. Suppose the required number of threads doesn’t arrive within the specified timeout. In that case, the timer will release the available threads, ensuring that the test progresses even if the synchronization condition is not met.
Precise Throughput timer
The Precise Throughput Timer provides much more control over balancing your load profile across a specific time duration and is more complex than the timers we have already looked at. It also allows batch requests to provide fine control over your performance testing profile.
How to configure Precise Throughput timer
Its configuration involves six essential parameters:
Target throughput (in samples per throughput period): This parameter defines the desired number of samples (requests or transactions) executed during each throughput period. It represents the target throughput rate you want to achieve in your performance test.
Throughput period (seconds): The throughput period specifies the duration, in seconds, during which the defined target throughput should be achieved. It sets the time window for the specified number of samples to be processed.
Test duration (seconds): This parameter determines the overall duration of your performance test. It represents the total time the test will run, including ramp-up, steady-state, and ramp-down periods.
Number of threads in the batch (thread): Specifies the number of threads used in each batch during the test. A batch refers to a group of threads collectively used to achieve the target throughput within the specified period.
Delay between threads in the batch (ms): This parameter introduces a delay, in milliseconds, between individual threads within a batch. It helps control the pace at which threads are started within the batch, contributing to the synchronization of thread execution.
Random seed (change from 0 to random): The random seed is a value used to initialize the random number generator. Setting it to “0” ensures a consistent sequence of random numbers in each test run. Changing it to “random” allows for different random number sequences in each test run, introducing variability.
How to view JMeter timer results
JMeter timers do not produce separate or distinct results that a specific listener, like other samplers, can view. The timers in JMeter are used to introduce delays or pauses between requests, but they don’t generate individual results or entries in the listeners.
To understand timers’ impact on your test results, you typically look at the listeners’ overall performance metrics and response times that display results for the samplers.
Types of Listeners
Some listeners that can help you analyze the impact of timers include:
View results tree
While timers won’t have separate entries, the View Results Tree listener can display overall results for each sampler, including response times. By examining the response times, you can infer timers’ impact on the pacing between requests.
Additionally, the detailed view in the View Results Tree allows you to inspect individual samplers’ request and response data, helping pinpoint any anomalies or issues introduced by specific timers.
View results table
The View Results Table listener offers a tabular view of the test results, providing a structured and concise overview of the performance metrics for each sampler. While it doesn’t specifically highlight timers’ impact, it enables you to systematically inspect critical information such as response times, latency, and throughput.
By exploring this listener, you can identify any trends or correlations between the introduced delays by timers and the corresponding sampler metrics, enhancing your understanding of how timers influence the test scenario.
Summary report
The Summary Report listener provides aggregate information about the performance test, including average response times, throughput, and error rates. It can help you understand the overall impact of timers on the test scenario.
In the Summary Report, focus on the Throughput metric to gauge how well the application handles the specified load, considering the influence of timers on the overall pacing of requests.
Aggregate report
Like the Summary Report, the Aggregate Report listener provides aggregated data for your test plan. It allows you to analyze response times and other performance metrics. In the Aggregate Report, pay attention to the Error % column to identify any unusual error rates that may be linked to specific timing configurations.
This listener provides a consolidated view of how timers contribute to the test results.
Response times over time
The Response Times Over Time listener visually represents response times throughout the test duration. While it doesn’t specifically isolate timers’ impact, it can help you observe patterns and variations. Look for any trends or spikes in response times that align with the timing patterns introduced by timers.
This listener provides a dynamic visualization that aids in understanding the temporal behavior of your application under different pacing conditions.
View timer results in the listeners
Begin by adding one or more timers to your Thread Group in JMeter. Timers control the pacing between requests and are crucial for simulating realistic user behavior.
Introduce a sampler, such as an HTTP Request, to represent a type of interaction with your application or server. This is the action that you want to test.
Inside the sampler, configure the parameters such as the request method, path, and server name. These details define the specifics of the request being sent.
Right-click on your Thread Group or the test plan itself and select Add -> Listener. Let’s take View Results in Table as a reference. This listener allows you to view detailed information about each executed request.
Once the View Results in Table listener is added, you can save your overall test plan to preserve the configurations and changes you’ve made.
Initiate the test run by clicking on the Run menu and selecting Start or using the green start button at the top of the toolbar.
Observe the results in the View Results Table listener as the test runs. Pay attention to the Start Time column to see when each sample starts, and check the Sample Time and Latency columns to understand how timers influence the timing and pacing of your requests.
Final thoughts on JMeter timers and delays
JMeter timers and delays are essential for load and performance testing web applications. They enable you to simulate real-world scenarios and regulate the request rate sent to a web server. Using timers effectively creates realistic loads, identifies performance issues, and ensures that your app can handle expected traffic.
JMeter timers and delays are not limited to load testing but can also be used for API, functional, and regression testing. JMeter also offers tools like assertions, listeners, and controllers to help you create more complex test plans.
This post is part of our comprehensive JMeter Mini-Course.
Follow our blog
Be the first to know when we publish new content.
- What is Unit Testing? From Bugs to Brilliance - February 26, 2024
- What is Regression Testing? A Complete Overview - February 22, 2024
- Mastering Git: Strategies for Efficient Version Control - February 16, 2024