Fine-Tuning JMeter Tests with Timers

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Timers in JMeter
Timers in JMeter help us in simulating the real user behavior by putting delay between requests because when we run the test in JMeter and send multiple requests on target, JMeter executes all requests one after another without any delay and that is not a real user behavior, to resolve this issue we use timers in JMeter and to generate accurate reports.
If we take an example of an E-Commerce website like Amazon, so the user will perform the below action to purchase a product
Log in to the Amazon
Search for the product
Select the product
Read the product description
Click on add to cart
Do the payment
While performing all the above action user might take some time before moving forward while searching for a product user might check multiple products based on his requirement then only the user will select the product and after selecting the product again user will take some time to read the detail description then only they will add the product to cart and proceed to payment.
So all the think time user has taken in each step while using Amazon, to replicate that user behavior in JMeter we use Timers. Timers help us to put a think time between each request because, in the real world, users take time sometime between each action and to replicate that behavior in JMeter we have different types of Timers.
Types of Timers
In JMeter we have different types of Timers but most of the time we use the below timers.
Constant Timers: As its name suggests constant timers in JMeter are used to put a delay between each request with same time span.
Suppose if we have 10 requests and we want to put a 2 second of delay between each request then we use this, when we run the test with 2 seconds of constant timer then while executing each request there will be a 2 seconds delay

Uniform Random Timer: It is used to put a random time delay to each request.
When we add Uniform Random Timer in the Test plan we have 2 fields inside that
Random Delay Max- In this we enter the maximum random delay time which we want.
Constant delay offset- In this, we enter the fixed delay time which we want.
Let’s understand how to calculate the total delay time in Uniform Random Timer
Suppose if we want to enter 10,000 milliseconds in Random Delay Max and 5000 milliseconds in Constant Delay offset then the delay time will lie between 5000 milliseconds to 15,000 milliseconds.

Synchronizing Timer: It is used to hold the thread request until its matches the required numbers which is also known as a group and then release & allow the execution. The value which we enter in “Number of simulated users to group by” is the number of threads for that JMeter will wait for grouping then only it will allow executing the particular request.
If we enter 0 in Timeout in Milliseconds then the JMeter will wait till the Number entered in “Number of simulated users to group by” and then allow the execution or else If we enter any value other than 0 in Timeout in Milliseconds then JMeter will wait only the number given in Timeout in Millisecond if wait time exceeds the given timeout value then the users will be released without meeting the “Number of simulated users to group by”.
Example: If we enter 20 in “Number of simulated users to group by” and the total thread count we have is 40 at the test level, then JMeter will create two groups of threads for that particular request and then only it will allow execution.
We use synchronize thread when we want to hit a particular request by grouping the thread, suppose if we want to hit the submit button in the test every time with 20 threads in each iteration then we will use this timer.

JSR223 Timer: In this timer, JSR stands for Java Specification Request, JSR223 timer is used to add think time according to our own logic, If we want to add think time according to some unique logic or algorithm which is not provided by JMeter in that JSR223 timer is very helpful.
We can write our own logic using some scripting language like Beanshell, Java, JavaScript etc.

Advantages of Timers in JMeter
It helps in simulating real user behavior.
We can avoid unrealistic load from the target server by adding timers.
All request doesn’t hit the server at the same time when we have add timers in JMeter.
We can mimic different user behavior using timers.
Conclusion
Timers in JMeter play an important role in replicating real user behavior in JMeter. By adding timers we can put a delay between each request which helps us in simulating the natural real-world scenarios. When we use timers it improves the test accuracy and prevents unnecessary load on the target server. While doing performance testing Timers play a very important role and help us in achieving credible results.




