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:
- VuGen String Comparison Behaviour Anyone who works with VuGen should know that they should...
- The “is it done yet” loop Occasionally you will find that you must write some code...
- Calculating the difference between two dates or timestamps Let’s say that you have to determine the difference between...
- Querying a MySQL database with LoadRunner Let’s imagine that you want to execute arbitary SELECT, INSERT,...
- Global variables aren’t really global in LoadRunner If you studied programming, you probably know a few little...
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.
February 3rd, 2010 at 3:11 pm
Note that Java vusers have a method they can call that does this for them.
C-based vusers will have to import Kernel32.dll and make the Win 32 API call directly.