Wednesday, February 6, 2008

Wasted Time

Time is precious and once wasted it never comes back! But speaking in loadrunner terms we can at least keep track of the time that we waste with uber precision.

Consider this, as we all expect, we should measure the exact timings for the identified transaction when doing performance testing. But some times we spend time within our scripts doing incidental or secondary actions like content checks, doing some complex calculation for setting up the data, etc., that might result in skewed transaction timings. However, if we carefully insert these actions within the less frequently functions lr_start_timer() and lr_end_timer() we will be able to measure the time spend and then later add this to the wasted time for the transaction.

See the quote from the LR API reference.

Wasted time is time spent on activities whose purpose is to support test analysis, but would never be performed by a browser user, for example, time spent keeping transaction statistics for later reporting. Wasted time is calculated internally by LoadRunner. Your script can also add wasted time with lr_wasted_time.

Sometimes, you may enter activities in a script that your do not want reported as part of the transaction statistics. Generally, these are activities related to record keeping, logging, or custom analysis. If you enhance the script with steps whose durations should not be included in the test statistics, you can track the time used by these steps with lr_start_timer and lr_end_timer. Then, the function lr_wasted_time is used to add this user-determined time to the internally generated wasted time.


In this example, let us look at the following loadrunner utility functions,
1. lr_start_timer()
2. lr_end_timer()
3. lr_wasted_time()
and also the lesser known function sleep() and how it can be used in place of lr_think_time().

I use in this example two actions other than the init and end action. These are the main Action() and helper/utility action Wait() that can be used instead of the normal lr_think_time().
Find below the code for the two functions.

Main Action

Wait Action


In the Action() action, I've just one transaction and within this I call the Wait() action. Please take a look at the Wait() action. It takes an int type argument named time and this value if not NULL is passed to the standard ANSI C funtion sleep()[I am not very sure sleep() is a ANSI C standard function :)]
Whatever, I just know this. On windows, sleep issues a Win 32 sleep command. For details, see Microsoft's Windows API documentation.

Note: Sleep suspends execution of a thread for specified number of miliseconds.

Coming back from the sleep function, let us investigate the Wait action a little deeper. I have sandwitched the sleep() function between lr_start_timer() and lr_end_timer(). lr_start_timer() starts a timer that calculates the passage of time in seconds. lr_start_timer() returns a handle to the timer. Pass the handle to lr_end_timer to stop the timer. lr_end_timer() stops a timer that began timing when lr_start_timer() was called. It returns the elapsed time in seconds. The resolution depends on the run-time environment. The maximum resolution is a microsecond.

Once lr_stop_timer() returns the elapsed time, it is passed to lr_wasted_time(). Convert value returned in seconds to wasted time in milliseconds by multiplying it with 1000.

Here is a snapshot from the replay log for the script.

Replay Log

In the on-line graphs in the LoadRunner Controller and the transaction response time graphs in the LoadRunner Analysis, the transaction times are reported after subtracting the wasted time. This is the time most pertinent to understanding the system being tested.

0 comments: