Saturday, April 13, 2013

How to get host name and IP address of system in Loadrunner?

This is so interesting and just like getting to know about you, the eternal feeling of yourself. Sometimes, while running test we want to know the Vuser IP and Load generators where they are running or getting data clustered in form of IP or LG in particular; this will be so handy in these case. In this script I have used lr_get_host_name() and lr_get_vuser_ip() function of Loadrunner.

Action()
{
char * my_host;char *ip;

my_host = lr_get_host_name( );
Click here to know more

lr_output_message("%s", my_host);

ip = lr_get_vuser_ip();

if (ip)

lr_output_message("The IP address is %s", ip);

else

lr_output_message("IP spoofing disabled");

return 0;
}

How to generate a random word in Loadrunner?

It’s quite often that while load testing we have to generate random load test data and for that we need some random words or strings.

To meet this objective I have made a function call random_word() in the action part of script, you have to provide length of the word you want and it gives you that. This function uses srand() to seed the pseudo-random number generator and rand() to get a random alphabet.

You can use the below code:
Click here to know more

char buff[32] = "";

random_word(char* param_name, int length)
{ 
  int r,i;
  char c;
  srand((unsigned int)time(0));

for (i = 0; i < length; i++)
{
    r = rand() % 25 + 65;
    c = (char)r;
    buff[i] = c;
    printf("%c", c);
   
}

lr_save_string(buff, param_name);
return 0;

}

Action()

{
    random_word("rnword", 8);
    lr_output_message("%s",buff);
    return 0;
}

Wow!! Even oxford dictionary can’t explain what does this word means ;). Just kidding, no offence.

Thursday, April 11, 2013

What are rendezvous points and policy?

While running a scenario, you can instruct multiple Vusers to perform tasks simultaneously by using rendezvous points. A rendezvous point creates intense user load on the server and enables LoadRunner to measure server performance under load.

Suppose you want to measure how a Web-based banking system performs when ten Vusers simultaneously login. To emulate the required user load on the server, you instruct all the Vusers to login at exactly the same time.

You ensure that multiple Vusers act simultaneously by creating a rendezvous point. When a Vuser arrives at the rendezvous point, it waits there for others to gather (specified number of Vusers).

Rendezvous policy is criteria according to which the Controller releases the Vusers from the rendezvous point either when the required number of Vusers arrives, or when a specified amount of time has passed. We have four options:
Click here to know more

1.       Release when X% of all Vusers arrives at the rendezvous.

2.       Release when X% of all running Vusers arrive at the rendezvous.

3.       Release when X Vusers arrive at the rendezvous.

4.       Timeout between Vusers. (Default 30 seconds)

How to use IP spoofing in LR?

IP of client machine's is identity used by Servers and Network devices like routers to recognize them and then to cache the information and optimize themselves.
Sometimes we need to use different IPs to emulate the real world scenarios to make servers and devices see as if users are coming from different sources.

But this task is not as simple as pressing button on vending machine and grabbing your cappuccino .
Kidding!!!!!!!!!!!

Click here to know more

Our job here is to fool the devices and it requires three simple steps:


1. Run IP Wizard (Start > Program Files > LoadRunner > Tools > IP Wizard) on LG to add the IPs you want to emulate in scenario.


2. Update the server’s routing table with new IPs, this is done so that servers are able trace back to the client. If client and server are in same network and subnet mask then not need of modification is required.

To update the table edit the batch file in IP wizard summary use route command as below to update:
“route ADD [IPs you want to add] MASK 255.255.255.255 [Your_IP] METRIC1”
“route ADD [IPs you want to add] MASK 255.255.255.255 [Your_IP] METRIC2”
Now run this .bat file on server to update.

3. Enable IP Spoofing (Scenario > Enable IP Spoofer) from Controller, before connecting to LG.


Hey congrats!!!! It’s done

How to check successful download of a file?

We can simply use web_get_int_property(), a very helpful function to check this. 

Use the below code:

int pdf_size;

lr_start_transaction("Download_PDF");
web_link("PDF download",
        "Text=PDF download",
        "Snapshot=my_pdf.inf",
        LAST );

pdf_size = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
lr_output_message("The download size of PDF file is : %d", pdf_size);

if(pdf_size > 10000)
{
lr_end_transaction("Download_PDF ", LR_PASS);
}

else
{
lr_end_transaction("Download_PDF ", LR_FAIL);
}
    return 0;
Click here to know more
}

HTTP_INFO_DOWNLOAD_SIZE gives size (in bytes) of the last download, including header, body, and communications overhead (for example, NTLM negotiation).

Let’s have more fun? Scheduling batch runs using windows scheduler.

This is so easy, even my Grandma can do this; though she is smart

Step 1: Open Task Scheduler: Start > Control Panel > System and Security > Administrative Tools > Task Scheduler.
I think lots of steps are in step 1 ;)

Step 2: In Action menu, click Create Basic Task.
Give a name for the task (scheduled_fun_time is good one) and description, click Next.
Click here to know more

Step 3: Schedule in calendar:
Select one time, click next.
Specify the start time, click next.
Select Action, click Start a program, and then click next.
Click Browse to find run_through_cmd.bat (told you to keep it handy), and then click Next.
Click Finish.

See how you did it in just three steps. :)

Want to have fun? Let’s run script from command line.

Type the following in a notepad file and save it as run_through_cmd.bat

c:
cd \
cd “<LR installation directory>\Program Files\HP\Virtual User Generator\bin” vugen.exe -usr “<Script_path>\<script_name>.usr”
mmdrv.exe -usr “<Script_path>\<script_name>.usr”

Now, double click run_through_cmd.bat file and see the black magic ;)
Click here to know more

Hey, please keep run_through_cmd.bat handy next article we will have more fun using this.

What if VUGen records no events and script comes blank?

This is very common problem and can be dealt by following below workarounds

Option 1: Change the protocol. The number of events will not increase till it comes across the protocol that is specified.

Option 2: It can be possible that activities are done at client side and no server interaction is there.
Click here to know more

Option 3: Disable your antivirus, sometimes it treats VUgen as non native and mess up the things.

Option 4: Use WinSock, personally not recommended.

Option 5: Check out if you need to install some patch or LR got corrupted so install patch or repair LR from setup file

Option 6: Raise help ticket with HP support team.

What is Hyper threading? How it helps in better performance?

The concept behind hyper threading is to make full use of resources. In this for each physical processor core, the operating system attends to two or more virtual or logical cores, and shares the workload between them when possible. 
This helps to decrease the number of dependent instructions in pipeline. These logical instances appear to the OS as different processors, thus the OS can schedule two processes at once.
Click here to know more


Now, let’s see how it improves performance hyper threading duplicates some sections of the processor, which store the architectural state but not the main execution resources. This helps processor to appear as if there are multiple processors to the host OS allowing it to schedule two threads or processes simultaneously. When execution resources would not be used by the current task in a processor without hyper-threading, and especially when the processor is stalled, a hyper threading equipped processor can use those execution resources to execute another scheduled task. This improves the time spend on jobs.

Why the values of the summary information showing Max, Average and Min response times and the Graph Max, Graph Average and Graph Min response times are different?

The first thing that we need to understand is both the results are derived from the raw results file; which can be extracted from analysis in .csv format.
Click here to know more

Graph data is a subset of raw results, which means a sample of data is taken from raw results and graph is drawn using that; if you make granularity same as data collection frequency the summary and graph results will become same as summary results are directly calculated from raw results.