Archive

Archive for April, 2009

IP Spoofing with LoadRunner

April 23rd, 2009

As described here ip spoofing is a technique for hiding real identity of the attacker on the net. It is mainly used for hacking but it can be helpful for performance tests as well.

Let’s say we have some fancy network infrastructure that cache some of our requests in the performance test. Because of that our results may be incorrect. To omit this issue we can change the IP address of each (e.g. HTTP) request that reaches the server and simulate load from multiple users not only on the application level but on the network level as well. In that case cache won’t affect performance tests. Fortunately folks from Mercury/HP implemented special function for IP spoofing in LoadRunner API.

  1. lr_enable_ip_spoofing();
  2. lr_disable_ip_spoofing();

To use it, first put your code between these to functions calls.
Second (before connecting to load generator!!!) enable IP Spoofer option in LR Controller (Scenario > Enable IP Spoofer).

Let the hacking begin :)

Tip:
There is an option in Controller (in Expert mode) to choose between multiple IP addresses per process or per thread (Tools > Options).

LoadRunner ,

Don’t waste your time

April 19th, 2009

Waste time in Load Runner is a time spend on tasks that normal browser user wouldn’t perform like storing test results, performance monitoring, calculations, etc. Wasted time is measured by LR automatically but sometimes it is necessary to use it explicitly through lr_wasted_time() function .

lr_wasted_times() removes time from all open transaction. If you want to make some calculation and don’t count them into overall transaction time then you should use this function.

Small example

  1. Action()
  2. {
  3.         merc_timer_handle_t timer;
  4.         long i;
  5.         double wastedTime;
  6.  
  7.         lr_start_transaction("My_Transaction");
  8.         timer = lr_start_timer();
  9.         for(i = 0; i < 1000; i++)
  10.                 lr_message("%d\n", i);
  11.         wastedTime = lr_end_timer(timer);
  12.         wastedTime*=1000;
  13.  
  14.         lr_wasted_time(wastedTime);
  15.  
  16.         lr_end_transaction("My_Transaction", LR_AUTO);
  17.         lr_message("Wasted %lf milliseconds", wastedTime);
  18.         return 0;
  19. }

On line 7 I’m starting one transaction. On line 8 I’m starting timer and stoping it at line 11. For loop between is used to generate my wasted time. After stopping the time, we need to subtract wasted time from open transaction by calling lr_wasted_time() on line 14. But before that on line 12 we need to change time units. lr_end_timer() returns time in seconds but lr_wasted_time() takes time in milliseconds. Thats why we need to multiply it by 1000. There is one more think. lr_wasted_time() is defined as

  1. void lr_wasted_time (long wasteTime);

If you use long type variable to measure wasted time you will always get rounded results (e.g. 1000, 2000, 3000). Instead it is better to use double type variable so at the end the results are more precise.

LoadRunner , ,