Embedding Pacing In LoadRunner Script (Includes Pacing For Blocks Too)

We come accross many pacing logics in the LoadRunner script which is based on the multiple iterations. But if we need to have a pacing if there are Action blocks involved and if in case we need to re-calculate the pacing time after each iterations (which will be a good idea) as few iterations may not take the same time to execute in the LoadRunner Script, then, we need to implement a different Pacing Logic. Here it is.......
The below pacing logic calculates the pacing time after completion of each iterations and based on the test duration left.

This pacing logic have three different functions embedded in a .C function File.
1. InitCore()
2. TopOfIterations()
3. BottomOfIterations()

1. InitCore():
The InitCore() Function takes 3 parameters as mentioned in the below syntax:
InitCore(TestDuration(in Seconds), TotalBlockIterations, MaxNumberOfIterations);
Example: InitCore(180, 12, 2); - Script will execute for 24 iterations and for 180 seconds [i.e. 3 Min]
Refer the below screen for more understanding:

So, in this case the Total Number Of Iterations becomes 24 [TotalNoOfIterations = TotalBlockIterations + MaxNumberOfIterations].
This InitCore Function should be the first line in vuser_init section.

2. TopOfIterations():
This function calculates the Pacing Time based on the Test Duration and Total Number Of Iterations which will be used for the actual pacing time in the main script. This Function Call should be the first line in the Main Action Block.

3. BottomOfIterations():
This function does the main calculations of the Pacing Time when a Block Execution is completed based on the Test Durations left and the Total Number of Iterations left. This is same as re-calculating the Pacing Time instead of fixed Pacing Time each time the iterations is completed. Please note, here each BLOCK execution is considered as each ITERATIONS. This Function Call should be the last line in the Main Action Block.

These TopOfIterations() and BottomOfIterations() functions can be added in different Actions Blocks.

Bottleneck:
Since the Pacing Time is calculated based on the Test Durations left and Iterations left, there could be a possibility that few iterations might take long time to finish and if this is the case then at some point of time the Test Durations time becomes 0, in this case the rest of the Iterations are executed without calculating the Pacing Time and hence the Pacing Time becomes 0.

Actual Code Comes Here: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;

No comments:

Post a Comment