Forum Discussion

punekar's avatar
punekar
Occasional Contributor
12 years ago

Solution: Transaction response times in LoadComplete

So, those of you from the LoadRunner world are probably wondering why you're restricted only to page level response times in LoadComplete as opposed to an atomic transaction response time that spans multiple requests.



With the absence of scripting in LoadComplete, this may not seem doable.



However, my team here has come up with a solution involving LAMP or at  least Apache/PHP/MySQL.



Outline:



1. Run an Apache server on the LoadComplete Controller machine to host some PHP pages (to be described).



2. In your scripts (scenarios in LC parlance), make calls to these PHP pages *before* you send requests out to the target application under test.



3. Make the requests to your Application Under Test (AUT).



4. Once done, make a call to the PHP page *After* to let the page know the transaction is completed.



How it works:



* You have PHP pages hosted on Apache for the following:

 - Create a unique VUserID and send it back on the response ( LoadComplete really should have had this capability out of the box as a parameter) 

- "Start" a transaction - essentially, a page that records that such-and-such VUserID running Iteration #n has started a transaction called "XYZ" at such-and-such time.

- "Stop" a transaction : identical to the one above, except this stops the aforementioned transaction.



The transaction PHP pages will write these records to a MySQL database.



This kind of solution can be extended to do all kind of neat things including -



* Manipulating data in code, returning what we need

Without scripting in LoadComplete, you have no other way to do something like this. 

As an example, lets say the AUT gives me a response page with 20 items. And I want to select one of these randomly to pass into the next request to the AUT, this can;t be done in LC without scripting. And of course, there is no scripting. Doing your data manipulation in PHP, returning that in a response for LoadComplete to capture into a parameter will work.



* The equivalent of VTS tables in HP LoadRunner

Virtual Table Server (VTS) helped running VUsers to exchange data at runtime. Of course, this required responsible coding. 



I'll be attaching sample code as we go along.

5 Replies

  • punekar's avatar
    punekar
    Occasional Contributor
    Files are given below
  • punekar's avatar
    punekar
    Occasional Contributor
    Well, I tried to to attach code, but the forum won't let me do it.



    Here's the relevant snippets:




    This is the GetVUserID.php file



    <html>

    <head>

    <title>HTTP Post Handler</title>

    <head>

    <?php

    //$StationName = $_REQUEST['FromStation'];

    //print("Testing");

    ?>

    </head>

    <body bgcolor="#FFFFFF" text="#000000">

    <p>

    <?php



    function gen_uuid($len=8)

    {

     $hex = md5("yourSaltHere" . uniqid("", true));

     $pack = pack('H*', $hex);

     $tmp =  base64_encode($pack);

     $uid = preg_replace("#(*UTF8)[^A-Za-z0-9]#", "", strtoupper($tmp));

     $len = max(4, min(128, $len));

     while (strlen($uid) < $len)

      $uid .= gen_uuid(22);

     return substr($uid, 0, $len);

    }



    $ActionNeeded = $_REQUEST['TxAction'];

    If ($ActionNeeded = "GetVUserID")

    {

     $a = gen_uuid(8);

     print("User ID:$a<br>");

    }



    $con = mysql_connect("localhost", "root", ""); // or die('Error', mysql_error());

    if (!$con)

      {

      die('Could not connect: ' . mysql_error());

      }





    mysql_select_db("LoadCompleteTx");

    $query="INSERT INTO `loadcompletetx`.`runlog` (`VUserID`, `TxAction`, `TimeIn`) VALUES ('$a', '$ActionNeeded', CURRENT_TIMESTAMP);";



    /*

    print("<p>");

    print("Running query: $query");

    print("<p>");

    */



    if(!mysql_query($query, $con))

    {

     die ('Error updating database');

    }

    else

    {

     print("<p>Success: Logged");

    }

    mysql_close($con);





    ?>

    <p>

    </body>

    </html>


  • punekar's avatar
    punekar
    Occasional Contributor
    Here's the code for LogMessage.php




    <html>

    <head>

    <title>Log Message HTTP POST Handler</title>

    <head>

    <?php

    // This PHP is for logging any runtime messages to the database

    //$StationName = $_REQUEST['FromStation'];

    ?>

    </head>

    <body bgcolor="#FFFFFF" text="#000000">

    <p>

    <?php



    $VUserID = $_REQUEST['VUserID'];

    $ActionNeeded = $_REQUEST['TxAction'];

    $Message = $_REQUEST['LogMessage'];



    $con = mysql_connect("localhost", "root", ""); // or die('Error', mysql_error());

    if (!$con)

    {

      die('Could not c  onnect: ' . mysql_error());

    }





    mysql_select_db("LoadCompleteTx");



    $query="INSERT INTO `loadcompletetx`.`runlog` (`VUserID`, `TxAction`,`LogMessage`, `TimeIn`) VALUES ('$VUserID', '$ActionNeeded', '$Message', CURRENT_TIMESTAMP);";



    if(!mysql_query($query, $con))

    {

     die ('Error updating database');

    }

    else

    {

     print("<p>Success: Logged");

    }

    mysql_close($con);





    ?>

    <p>

    </body>

    </html>


  • punekar's avatar
    punekar
    Occasional Contributor
    The JPEG files I posted earlier should give you an idea as to how to invoke these PHP scripts. The idea is to HTTP Post the relevant information to them.