Think time that cannot be ignored

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).

 


Related posts:

  1. VuGen String Comparison Behaviour Anyone who works with VuGen should know that they should...
  2. The “is it done yet” loop Occasionally you will find that you must write some code...
  3. Calculating the difference between two dates or timestamps Let’s say that you have to determine the difference between...
  4. Querying a MySQL database with LoadRunner Let’s imagine that you want to execute arbitary SELECT, INSERT,...
  5. Global variables aren’t really global in LoadRunner If you studied programming, you probably know a few little...


Bookmark using any bookmark manager!

 

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Think time that cannot be ignored”

  1. Stuart Moncrieff Says:

    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