Performance Testing @ the Frontline

A hidden world where small things make a big difference

In-Script simulation of a load-balancer with LoadRunner

Posted by Kim on Thursday, September 18, 2008

When testing enterprise grade web-based solutions there is often a company-wide LoadBalancer present that is a black-box from the testers point of view. Bypassing the LoadBalancer during testing is usually very important to be able to determine one servers limits or capacity.

There are however situations where the LB’s need to be simulated in a controlled way, and having the load share known and controlled during testing. To achieve this there is a simple trick that can be used in LoadRunner scripts.

The easiest way is to create a new action and then place this action in the correct place in the Run-Logic tree. Depending on the script it can be inserted as the last VUSER_INIT action or the 1st action in the VUSER_RUN section.

We now add a new parameter named VUserID to the parameter list, selecting the VUSER ID parameter type.

The code in the new action simply changes the target DOMAIN based on the VUserID parameter. Using the VuserID is good since we know it’s an integer number and always unique for the test.

Below is an example code where even and odd VuserID’s are used to determine the domain name:

// Manual Load-Balancing
// This code enables execution of traffic to two separate web-servers, distributed 50/50
// by sending Even and Odd VUserID's to separate Web-Servers</code>

// Get the VUserID (Does not matter what the ID is
VUserID = atoi( lr_eval_string("{VUserID}") );

if (VUserID & 0x0001==0) // use AND operator to filter out LSB bit
{
  lr_save_string( "http://www.server1.com", "BaseURL" ); // Even VUserID's
} else
{
  lr_save_string( "http://www.server2.com", "BaseURL" ); // Odd VUserID's
}

And here’s an example on how to actually use the BaseURL parameter:

	lr_start_transaction("Homepage");

	web_url("Home",
		"URL={BaseURL}/",   // BaseURL is determined by code above!
		"TargetFrame=",
		"Resource=0",
		"RecContentType=text/html",
		"Mode=HTML",
		LAST);

	lr_end_transaction("Homepage", LR_AUTO);
Advertisements

10 Responses to “In-Script simulation of a load-balancer with LoadRunner”

  1. Abhishek said

    Can we replicate the same using Webload…??

  2. Kim said

    Given that WebLoad has an equivalent to the VUserID parameter it should not be a problem.
    I’ve not used WebLoad myself, but looking at the demos/screenshots I see it’s also uses scripts so my guess is that it’s possible.

    • kannan said

      Webload has parameter to find out the userid parameter in LR. it’s called ThreadNum.
      for the user1 – ThreadNum value is 0 and User2 -> ThreadNum is 1

      The code is

      if(ThreadNum %2 ==0)
      {
      Base URL 1
      )
      else
      {
      Base URL2
      }

  3. Nice one Kim!

    I have a slightly different solution to the load balancing problem, that I have written about in this article: Load balancing vusers without a load balancer.

    Cheers,
    Stuart.

  4. Anon. said

    Is there a way to do this using Web (GUI) Click ‘n Script protocol?

    Anon.

    • Kim said

      Yes. I just created a small sample where the target domain is stored in the variable Domain. Varying the content of Domain will make the web_browser() function go to different places.

      The code below would to Google1 or Google2 servers and look for Wikipedia but not click any link:

       // Get the VUserID (Does not matter what the ID is
       VUserID = atoi( lr_eval_string("{VUserID}") );

       if (VUserID & 1==0) // use AND operator to filter out LSB bit
        lr_save_string( "http://www.google1.com", "BaseURL" ); // Even VUserID's
       else
        lr_save_string( "http://www.google2.com", "BaseURL" ); // Odd VUserID's

       web_browser("Google",
        DESCRIPTION,
        ACTION,
        "Navigate={BaseURL}",
        LAST);

       web_edit_field("q",
        "Snapshot=t2.inf",
        DESCRIPTION,
        "Type=text",
        "Name=q",
        ACTION,
        "SetValue=wikipedia",
        LAST);

       web_edit_field("q_2",
        "Snapshot=t3.inf",
        DESCRIPTION,
        "Type=text",
        "Name=q",
        ACTION,
        "UserAction=Submit",
        LAST);

  5. Sathish said

    Hi,

    Could you please explain how this particular piece of code works?

    if (VUserID & 1==0) // use AND operator to filter out LSB bit

    Regards,
    Sathish

    • Kim said

      The VUserID is obtained from a variable in the Prameter List (in VuGen) defined as a “VUser ID” with format %s.

      This ID is then used as the determining factor for the Even or Odd users. Even/Odd is determined using a binary AND operation on the actual VUserID number. If you apply VuserID AND $0001 you will take out only 1 bit, that bit changes between 0 and 1. It also happends to be the bit that changes the most (being the Least Significant Bit (LSB) bit).

      In C code the && characters signifies the AND operation. More info at http://www.gamedev.net/reference/articles/article1563.asp

      For a more indepth description of the AND operation in general have a look at http://en.wikipedia.org/wiki/Binary_and.

  6. Rajendra T said

    Hi Kim,

    This information is really helpful. Could you please let me know where I can find more info on the Load Balancing techniques?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: