Someone asked me once if there was a way of putting think time into a VuGen script that could not be ignored by changing the runtime settings.

There are very few situations I can think of where this would be a good idea, but it is certainly possible to force a VuGen script to pause for a specified number of seconds irrespective of the script’s runtime settings.

The windows API provides a sleep function that can be substituted for lr_think_time, however you will need to load the Kernel32 DLL before you can use the function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int rc;
rc = lr_load_dll("Kernel32.dll"); // needed for sleep()
if (rc!=0) {
  lr_error_message("Error loading DLL");
}
 
lr_start_transaction("sleep time");
 
sleep(10000); // sleep time in milliseconds
 
// Check whether VuGen regards sleep time as "wasted time"
lr_output_message("wasted time: %d", lr_get_transaction_wasted_time ("sleep time"));
 
lr_end_transaction("sleep time", LR_AUTO);

Note that VuGen does not regard sleep time as “wasted time”, which can be determined using the lr_get_transaction_wasted_time() function from inside the transaction.

While this is a nice example of using a DLL to call non-VuGen functions, the only real-world example of when the sleep() function may be useful is when you have a BPM script that polls another application within a loop. Using sleep() instead of lr_think_time() would mean that no-one can accidentally cause your script to generate excessive load on the server by polling very quickly (using the “ignore think time” or “limit think time to x seconds” runtime settings).

2 comments on “Think time that cannot be ignored

  1. I have just found this “secret” function (in ./LoadRunner/include/lrun.h)

    /*
    * think time that ignores user RTS. thinks ‘secs’ time as specified
    */
    void lr_force_think_time (double secs);

  2. Note that Java vusers have a method they can call that does this for them.

    lr.sleep issues a Win 32 sleep command. For details, see Microsoft’s Windows API documentation.

    C-based vusers will have to import Kernel32.dll and make the Win 32 API call directly.

Leave a Reply