Jmeter | Capture Real Think Time of User
Goal:
As an automation tester, I would like to record real/actual think time of user which allows testers to avoid the long and tedious task of manually adding static timers.
What is THINK TIME?
When evaluating the performance of a given system, it is important to perform tests under realistic conditions. The “think time” plays an important role when doing performance tests.
It is defined as the time between the completion of one request and the start of the next request.
Problem:
By default, a JMeter thread executes samplers in sequence without pausing. JMeter sends requests without applying any delay between each sampler/request. In that case, JMeter could overwhelm your test server by making too many requests in a short amount of times.
Solution:
We recommend that you specify a delay by adding one of the available timers to your Thread Group. A timer will cause JMeter to delay a certain amount of time before each sampler
The JMeter Timers available are as follows: (Ref: JMeter Timers)
- BeanShell Timer
- BSF Timer
- Constant Throughput Timer
- Constant Timer
- Gaussian Random Timer
- JSR223 Timer
- Poisson Random Timer
- Synchronizing Timer
- Uniform Random Timer
Let’s have a look on some common types of timer:
A) Constant Timer:
If you want to have each thread pause for the same amount of time between requests, use this timer.
Enter Thread Delay value in milliseconds. We have entered delay of “1000” ms in between each user request.
B) Uniform Random Timer:
Uniform Random Timer element is used to delay each request for a random period of time.
The total delay is the sum of the random value and the offset value.
Total amount of delay = Random Delay Maximum + Constant Delay Offset
Have we solved the PROBLEM?
Are we capturing the real think time of User? Answer: NO
Timers which we have discussed above are more random in nature. it’s not actually considering the actual time which user has spent while performing sequential operations.
Ex:
User may wait 10 ms after he logs into application, may wait for 15 ms after he has added few items to the cart, etc.
Then what’s the SOLUTION?
Answer: Use “The HTTP Proxy Server” wisely :)
The Proxy Server allows JMeter to watch and record actions while users browse web application with standard browsers. JMeter will create test sample objects and store them directly into the test plan as the user browses (so samples can be interactively viewed in real time).
- Create a new test-plan and switch to WorkBench. Then go to “WorkBench”->”Add”->”Non-Test Elements”->”HTTP Proxy server”.
2. Next Step is Configure your browser to use the JMeter Proxy
More information: refer Jmeter manual
3. To record a more realistic test plan, insert timers between requests.
This will allow the recording of the think time of the user. For this purpose add a Constant Timer to the HTTP Proxy Server node to record think-time (right-click on the “HTTP Proxy Server” node -> choose “Add” -> “Timer,” and -> “Constant Timer.”). After that action change the “Thread Delay” on the timer to “${T}”. This will tell the proxy server to record your time rather than add a constant time for each request.
Note that a timer causes the affected samplers to be delayed. That is, the affected sampling requests are not sent before the specified delay time has passed since the last received response. Therefore, you should manually remove the first sampler’s generated timer since the first sampler usually does not need one.
Finally, the test plan should look like test plan below.
4. Now JMeter’s HTTP Proxy Server is ready.
We are ready to record. Let’s start the proxy and surf through the testing application.
See what you get after the recording is displayed below:
The timer recorded the user think time.
Are we capturing the real think time of User? Answer: YES :)