Thursday 6 June 2013

Embedding Pacing In Load Runner Scripts | Pacing For Blocks in Load Runner

In LoadRunner scripts, pacing logic is often crucial for controlling the flow of iterations. However, when Action blocks are involved and recalculating pacing time after each iteration becomes necessary, a different approach is needed. Let's explore a dynamic pacing logic that adjusts pacing time based on the test duration left.

This pacing logic consists of three distinct functions embedded in a .C function file:

1. InitCore()
2. TopOfIterations()
3. BottomOfIterations()

1. InitCore():

The `InitCore()` function initializes the core parameters required for dynamic pacing. It takes three parameters:

Syntax: InitCore(TestDuration (in Seconds), TotalBlockIterations, MaxNumberOfIterations);

Example: InitCore(180, 12, 2);` - The script will execute for 24 iterations and for 180 seconds (i.e., 3 minutes).

2. TopOfIterations():

The `TopOfIterations()` function calculates the initial pacing time based on the test duration and total number of iterations. This function call should be placed at the beginning of the main Action block.

3. BottomOfIterations():

The `BottomOfIterations()` function recalculates the pacing time after the completion of each block execution, considering the remaining test duration and iterations. This ensures dynamic adjustment of pacing time instead of using a fixed value. Note that each block execution is treated as an iteration. 

This function call should be placed at the end of the main Action block.

double TestDuration, pacing_time, Origpacing_time;
int Counter = 1, MaxCounter = 0, TotalIterations;
merc_timer_handle_t timer;
double duration;

InitCore(double TDuration, int TotalBlockIterations, int MaxNumberOfIterations)
{
    TestDuration = TDuration;
    TotalIterations = TotalBlockIterations * MaxNumberOfIterations;
}

TopOfIterations()
{
    if (Counter == 1) {
        lr_output_message("Action1 - Total Test Durations - First Time: %lf", TestDuration);
        pacing_time = (double)TestDuration / TotalIterations;
        lr_output_message("Action1 - Total Iterations Left - First Time: %d", TotalIterations);
        lr_output_message("Action1 - Pacing - First Time: %lf ", pacing_time);
    }
}

BottomOfIterations()
{
    if (duration <> 0) {
        TestDuration = TestDuration - pacing_time; //Is equal to Pacing time
        MaxCounter = 1;
    }

    TotalIterations = TotalIterations - 1;
    if (MaxCounter != 0) {
        lr_think_time(pacing_time - duration);
        pacing_time = TestDuration / TotalIterations;
        MaxCounter = 0;
    }
    else if (TestDuration > 0) {
        TestDuration = TestDuration - duration;
        pacing_time = TestDuration / TotalIterations;
    }

    if (TestDuration <= 0) {
        pacing_time = 0;
    }
    lr_output_message("Action1 - Total Iterations Left: %d", TotalIterations);
    lr_output_message("Action1 - Total Test Durations Left: %lf", TestDuration);
    lr_output_message("Action1 - New Pacing: %lf", pacing_time);
    Counter = 0;
}


Happy Testing !

No comments: