pcl2004_27 发表于 2006-10-30 14:23:30

LoadRunner:Dynamically calculated Think Time

Description

      a technique to pad a scripts execution time to a fixed duration


Solution

      Recently in order to meet a contractual requirement I had to execute a scenario in such a way that it was of fixed duration regardless of load. I couldn抰 find any obvious way to achieve this in LoadRunner and neither could the support desk, this forced me to get a little creative with the load runner function calls. Thought I抎 post my solution here in case it抯 of use to anyone else.

With this technique I couldn抰 randomize think time using the run time settings so I also had to generate this as well. With this code the mean script execution time was typically within 15ms of the target time.

double maxStepThinkTime = 5.000;
double minStepThinkTime = 2.500;
double target_time = 180.000;
double think_time;
double time_elapsed;
merc_timer_handle_t timer;
double wasted_time;
merc_timer_handle_t waste;


Script
{
/*
* Body of script wrapped in a timer as follows:
*/

timer = lr_start_timer();

Application抯 transactions go here?

/*
* Add some random think time.
*
* Time how long it takes to calculate the think time
* this is the recorded as wasted time.
*/
waste = lr_start_timer();

/*
* Compute think-time in the range minStepThinkTime to
* maxStepThinkTime, granularity is 1000th the difference
* between max & min values
*/

think_time = (minStepThinkTime + ((maxStepThinkTime - minStepThinkTime) * (rand() % 1000) / 1000));

/*
* Compute time taken to do above and record as wasted
* time
*/
wasted_time = lr_end_timer(waste);
lr_wasted_time(1000 * wasted_time);

/*
* Wait the determined amount of time.
*/
lr_think_time(think_time);
More Application transactions go here?

/*
* Pad transaction to fixed duration specified
* by target time.
*/

time_elapsed = lr_end_timer(timer);
think_time = target_time - time_elapsed;

lr_start_transaction("Padding");
if(think_time > 0)
{
lr_think_time(think_time);
}
lr_end_transaction("Padding", LR_AUTO);
I
页: [1]
查看完整版本: LoadRunner:Dynamically calculated Think Time