Labels

Showing posts with label Load Runner. Show all posts
Showing posts with label Load Runner. Show all posts

Friday, August 10, 2012

How to Record-Replay JAVA with LoadRunner ?

On increasingly rare occasions, you might be required to load test an application that has a Java-based client. While it’s nice for users to have an application that has a rich GUI, it will probably lead to a world of pain for you as a performance tester.
Don’t immediately reach for LoadRunner’s Java Record-Replay virtual user type. It might not be the right solution.
LoadRunner's Java Record-Replay vuser
This article will guide you through your first steps when selecting the correct vuser type to test an application with a Java-based client…

There are several LoadRunner vuser types that are candidates for your test. Your first task is to pick the correct one. The possible vuser types are:
  • Web (HTTP/HTML)
  • Java
  • Windows Sockets
  • Citrix
  • JAVA Record Replay
HP sells each of these vuser types are in separate license bundles, so you can’t just buy LoadRunner and figure out the vuser type later.
In order to pick the most appropriate virtual user type, you need to know what protocol the Java client uses to communicate with the server. It is best to talk to an architect (or someone else who is suitably technical), but a smart performance tester backs up this conversation by recording the application to see if the architect is correct. You may like to use the LoadRunner Protocol Advisor, but I am old-school, so I record the application with the Windows Sockets vuser, or inspect the network traffic with WireShark.
If you are really lucky, your Java application communicates using HTTP – I had a Java “Web Start” application that just sent SOAP/XML messages to the server. In this case, you can just record using a standard Web (HTTP/HTML) vuser. All your requests will be recorded as web_custom_request, and you can reformat your requests so that they are readable, and do all kinds of neat things with XPath and the lr_xml functions.
The Java vuser is part of the “template” vuser bundle. You can put any Java code you like in these scripts, but there is no ability to record an application. This makes this vuser type only useful for very simple situations where you can confidently rewrite code that will make all the server calls that the client makes – I would only use this vuser type in situations where the application does something trivial like putting a message on a queue.
While you will definitely be able to record your application with the Windows Sockets vuser (winsock), there is only a 1 in a million chance that this is the correct vuser type for you. The basic rule of thumb is: if the captured network traffic that you see is plaintext, and you can figure out the details of the protocol just by eyeballing it for a few seconds, then maybe it is okay to use the winsock vuser type; in all other cases, avoid it. Don’t try to write code in C that will deserialise Java objects.
The Citrix vuser type is like a Get Out of Jail Free card for difficult to script applications. You can bypass all the protocol-level (or method-level) mucking around and just create a script that clicks on the buttons etc in the application. Citrix isn’t the cleanest or most reliable protocol, but a week of hacking at a Citrix script beats many weeks of pain using the Java Record-Replay vuser. Note that you will need to have a Citrix server to run the Citrix vusers against.
Have I dropped enough hints that using the Java Record-Replay vuser type is difficult and not much fun? I have created scripts for a few applications using this protocol now, and it is still not one that I would feel comfortable giving a time estimate for scripting with.
This vuser type works differently from most other vuser types in that it does not record protocol-level traffic, it records Java method calls and their arguments. Obviously if you record every single method call, your script will be huge and unusable, but if you record the method calls that are close to the point where data is sent to the server (while avoiding the low-level java.net classes), you might be able to massage your script into something that actually sends the same requests as the real application.
“Hooks” files instruct the recording engine which methods to record. They will look kind of familiar to people who are used to customising HP Diagnostics. Here is an example from my user.hooks file…
1
2
3
4
5
6
7
[oracle.jdbc.driver.OracleStatement]
;---------- oracle.jdbc.driver.OracleStatement --------
class      = oracle.jdbc.driver.OracleStatement
method     = executeQuery
signature  = !.*
cb_class   = mercury.corba.CORBASupport
general_cb = true
If you look for files with a .hooks extension under your LoadRunner directory, you will see hooks files for four main protocols RMI, CORBA (BEA Weblogic, Iona OrbixWeb, Visigenic/Inprise Visibroker), JMS, Jacada; and various extensions and JNDI, EJB, JNDI, JTA, ORBacus etc.
LoadRunner Java Record-Replay protocols
Even if your protocol is listed, don’t get too excited. It won’t necessarily work without lots of tweaking. If you need to develop your own custom points file (user.hooks) for your application, it is even more effort work. Don’t expect to be able to do anything useful with this virtual user type unless you have a solid Java background.
The good news (I guess), is that this vuser type will be able to (eventually) record and replay any Java-based application. The bad news is that you may not be able to get it working by yourself – I have seen smart people reduced to helplessness by this vuser type.
Don’t try to do it when you are on a tight deadline. And don’t assume that just because you can record something from your application with this vuser type with the out of the box configuration, that you will be able to get your script to replay successfully (or accurately) without a lot of hard work.
If I have a choice (and the Web vuser does not work), I would always prefer to use Citrix, rather than battle with the Java Record-Replay vuser again.

How to send Emails using Blat utility in LoadRunner

we can send hundreds of emails to the server then one option is to use a web email client to simulate the load but it has following limitations

1. Your own corporate/personal Email id need to be used in LoadRunner Script but it may fill up the mail box

2. Password credentials need to be made visible in the script.

Other option is to use Blat utility which is a third party freeware utility. It sends the contents of a file in an e-mail message using the SMTP protocol.

Download the attached blat.dll utility and create a sample script as shown below.


Action()

{
command_line_Send = (char *)malloc(1024 * sizeof(char));

if(CheckLoadBlatDLL != 0) //if return code not zero then DLL not loaded!!Reload it
{
    lr_output_message("BLAT Emailing DLL Not Loaded Successfully !!! Reloading the DLL");
    CheckLoadBlatDLL = lr_load_dll("blat.dll");
}
f1=fopen(lr_eval_string("C:\\SR_{vuser_id}.txt"), "wb+" );
fprintf(f1,lr_eval_string("Email Performace Testing {TimeStamp}"));
fclose(f1);

//Initialize all the command line parameters for Blat tool

strcpy(DestEmailID,lr_eval_string("{EmailId} ")); // Destination Email ID
strcpy(Subject,lr_eval_string("\"Email PerfTesting{TimeStamp}\" ")); // EmailID Subject
strcpy(SMTPServer,lr_eval_string("{SMTPServer}")); //Your Corporate SMTP Server
strcpy(FromEmailID,lr_eval_string("{FromEmailID} "));// Source Email Id
strcpy(AttachFile,"C:\\attach.pdf "); // Any attachment
strcpy(BodyText,lr_eval_string("C:\\SampleBody{vuser_id}.txt "));// Email Body
lr_output_message("The Destination EmailId is :%s",lr_eval_string("{EmailId}"));

//Verify whether DLL Loaded successfully

if (CheckLoadBlatDLL == 0) //if return code not zero then not DLL not loaded
{
    lr_output_message("BLAT Emailing DLL Loaded Successfully ");
    // Build the Command line for sending Emails
    strcpy( command_line_Send, BodyText);
    // strcat( command_line_Send, "-attach ");
    //strcat( command_line_Send, AttachFile);
    strcat( command_line_Send, "-to ");
    strcat( command_line_Send, DestEmailID);
    strcat( command_line_Send, "-f ");
    strcat( command_line_Send, FromEmailID);
    strcat( command_line_Send, "-s ");
    strcat( command_line_Send, Subject);
    strcat( command_line_Send, "-server ");
    strcat( command_line_Send, SMTPServer);
    lr_output_message("Parameters for Send Command : %s", command_line_Send);
    temp_error_code = Send(command_line_Send);
    lr_output_message("Return code of Send command %d " , temp_error_code);
  //Check successful message sending.
   if (temp_error_code == 0) {
      lr_output_message("Email Sent Successfully ");
   }
  if(temp_error_code != 0){
  switch( temp_error_code ){
  case 1:
   //Command Line Bad Argument
   //Unable to open SMTP socket
   //Command unable to write to socket
   //Server does not like To: address
   // Mail server error accepting message data
   lr_error_message("ERROR : Check the command Line Argument Format");
   break;
  case 2:
   //The server actively denied our connection.
   //The mail server doesn't like the sender name.
   lr_error_message("ERROR : Email Server Denied connection or File does not exist");
   break;
   }//end SWITCH
 }//end IF
}else{
  lr_output_message("Unable to Load the Blat DLL - Check whether DLL exists at the specified location ");
}
free(command_line_Send);
return 0;
}

What is concurrency testing ?

1. Concurrency testing employs many users at a time and therefore it is considered to be a type of multi- user testing.

2. Concurrency testing was invented in order to determine what happens if many users are accessing the same data base records, modules or application code.

3. Other than this, concurrency testing also identifies the use of single threaded code, dead locking, locking semaphores and locking and it is also effective in measuring the level of these aspects.

4. While carrying out the concurrency testing several users perform same kind of task on the same application and that too at the same time.

5. The application serves too many users at a time.

TOOLS FOR PERFORMING CONCURRENT TESTING
Several tools are available for performing concurrency testing but we would recommend you load Runner since it helps you create concurrency at a point you wish.

- All you need to do is create a test scenario after you have recorded and improved your scripts using the virtual user generator.

- You can decide and add how many users you want your scripts to support.

- You should input the number of users in the controller component of this testing tool.

- There are several ways to add user like gradual ramp- up or spike, stepped etc.

- You can choose for yourself which way you want the users to be added.

- This is the most effective way to create concurrency.

- Apart from the multi user testing, the concurrency testing tests one application over the other one.

LEVELS OF CONCURRENCY TESTING
Two levels of concurrency testing have been developed so far and they have been discussed below:

# 1st Level:
- This involves concurrency testing of one application being executed on the top of another application.

- We can illustrate this by a simple example; you receive an incoming call while playing some game on your cell phone. The game will go to paused state. This is the simplest example we can give.

# 2nd Level:
- This involves concurrency testing of one application being executed on the top of other two applications.

- This can also be illustrated with a similar example, you receive an incoming call while playing games and while you are on the call you receive an SMS. The game is paused.

- Apart from just testing the multi user capacity of the software, concurrency is also responsible for finding out the bugs like dead lock, live lock, data race and data corruption.

- These bugs usually occur when the parallel processing is implemented in the application.

- If you are also using the user scenario apart from the test scenario your concurrency testing will yield much better results.

- Some applications make use of more than one module where some accept parallel processing and other are sequential.

- Identifying the type of modules can help you in writing effective test cases against them which in turn will reflect in your testing.

This is the internet era. Almost everyone is using web and web applications all over the world. Such a huge number of users require great stress handling capacity for the servers. If the servers are not able to take the load they often slip in to the position of the dead lock.

Concurrency testing is a way to ensure that such kinds of situations do not occur. Therefore concurrency testing is important. Performance is the basic aspect that is tested most in the concurrency testing.

Number of users using the application at a time equals to the number of hits per second. With the growing number of internet users world wide more and more security is needed over the web

What are the cookies and its types? Where are cookies used?

 cookie or an HTTP cookie can be defined as a message used by an origin website to send the information about the state to the browser of the user and by the browser to send the information about its state to the origin site.
An HTTP cookie is known by many names such as web cookie, browser cookie etc.

The information of the state that is sent across the origin site and the user’s browser is used for the purpose of:

- Authentication
- Identification of the session of an user
- Preferences of the user and
- Contents of the shopping cart

In other word HTTP cookies are used for any purpose that can be accomplished using the process storing text data on the computer of the user.

Characteristics and Uses of Cookie
- The main characteristic of Cookies is that they cannot be programmed and thus, cannot carry any kind of viruses or worms.

- Any malware cannot be installed on the host system with the use of a cookie. So they are safe to this extent.

- However, cookies can be effectively used by a spyware to track the browsing activities of the users.

- This is a major privacy concern and has prompted European and US law makers to take action in the past few years.

- Cookies are very easy to steal and are thus often misused by the hackers.

- Hackers steal the cookies and use them to gain access to the web account of the victim.

- Cookies were first used to solve the problem of implementation of the shopping cart.

- Initially the cookies were developed for the Netscape browser.

- They were used to check if the earlier visitors visited the site again.

- Later cookies were developed for internet explorer and other browsers.

- The concept of the cookies was not widely known to the public at that time.

The term “HTTP cookie” came into existence in the year of 1994. It has been derived from “magic cookie”.

What are Magic Cookies?
- Magic cookie was actually a data packet that a program receives and sends again to the program on the other side without altering the contents of the packet.

- Magic cookies were used in computing systems long back and were introduced in web communications by Lou Montulli in June 1994.


The development of a cookie for formal specifications is always in progress. Till date many types of cookies have developed. They have been discussed below:

Session cookie:
- This cookie has a lifetime equal to the time period of the user using the website.
- These cookies are automatically deleted after the end of a session.

Persistent cookie:
- These cookies last even after the session has expired.
- If a persistent cookie has its maximum age set to one year, then till the one year is over, the cookie will be sending information to the server every time the website is visited.
- These are also called tracking cookies.

Secure cookie:
- These cookies are used by the browser if it accessing server through an HTTPS connection.
- This ensures that the cookie is always encrypted during the transmission of the information.
- This prevents cookie theft.

HTTP only cookie:
- This type of cookie is mostly supported by all the modern browsers.
- On a browser which supports HTTP, an HTTP only cookie is used during transmission of HTTP requests.
- It restricts the access from other non HTTP scripts.

Third party cookie:
- The first party cookies are set with the same domain or sub domain in the address bar of the browser.
- But, third party cookies are set with various domains other than the one mentioned in the address bar.

Super cookie:
- A cookie with a public suffix domain like .co.uk, .com etc.

Zombie cookie:
- This cookie is automatically recreated after its deletion.

Tips for JAVA Related Load Runner Tuning

Servlet performance Tips:
  • Use the servlet init() method to cache static data, and release them in the destroy() method.
  • Use StringBuffer rather than using + operator when you concatenate multiple strings.
  • Use the print() method rather than the println() method.
  • Use a ServletOutputStream rather than a PrintWriter to send binary data.
  • Initialize the PrintWriter with the optimal size for pages you write.
  • Flush the data in sections so that the user can see partial pages more quickly.
  • Minimize the synchronized block in the service method.
  • Implement the getLastModified() method to use the browser cache and the server cache.
  • Use the application server's caching facility.
  • Session mechanisms from fastest to slowest are: HttpSession, Hidden fields, Cookies, URL rewriting, the persistency mechanism.
  • Remove HttpSession objects explicitly in your program whenever you finish the session.
  • Set the session time-out value as low as possible.
  • Use transient variables to reduce serialization overheads.
  • Disable the servlet auto reloading feature.
  • Tune the thread pool size.
JSP performance Tips:
  • Use the jspInit() method to cache static data, and release them in the jspDestroy() method.
  • Use the jspInit() method to cache static data.
  • Use StringBuffer rather than using + operator when you concatenate multiple strings.
  • Use the print() method rather than the println() method.
  • Use a ServletOutputStream rather than a PrintWriter to send binary data.
  • Initialize the PrintWriter with the optimal size for pages you write.
  • Flush the data in sections so that the user can see partial pages more quickly.
  • Minimize the synchronized block in the service method.
  • Avoid creating a session object with the directive <%@ page session="false" %>
  • Increase the buffer size of System.out with the directive <%@ page buffer="12kb" %>
  • Use the include directive instead of the include action when you want to include another page.
  • Minimize the scope of the 'useBean' action.
  • Custom tags incur a performance overhead. Use as few as possible.
  • Use the application server's caching facility, and the session and application objects (using getAttribute()/setAttribute()). There are also third-party caching tags available.
  • Session mechanisms from fastest to slowest are: session, Hidden fields, Cookies, URL rewriting, the persistency mechanism.
  • Remove 'session' objects explicitly in your program whenever you finish the session.
  • Reduce the session time-out as low as possible.
  • Use 'transient' variables to reduce serialization overheads.
  • Disable the JSP auto reloading feature.
  • Tune the thread pool size.
Web application scalability Tips:
  • Web application scalability is the ability to sustain the required number of simultaneous users and/or transactions, while maintaining adequate response times to end users.
  • The first solution built with new skills and new technologies will always have room for improvement.
  • Avoid deploying an application server that will cause embarrassment, or that could weaken customer confidence and business reputation [because of bad response times or lack of calability].
  • Consider application performance throughout each phase of development and into production.
  • Performance testing must be an integral part of designing, building, and maintaining Web applications.
  • There appears to be a strong correlation between the use of performance testing tools and the likelihood that a site would scale as required.
  • Automated performance tests must be planned for and iteratively implemented to identify and remove bottlenecks.
  • Validate the architecture: decide on the maximum scaling requirements and then performance test to validate the necessary performance is achievable. This testing should be done on the prototype, before the application is built.
  • Have a clear understanding of how easily your configurations of Web, application, and/or database servers can be expanded.
  • Factor in load-balancing software and/or hardware in order to efficiently route requests to the least busy resource.
  • Consider the effects security will have on performance: adding a security layer to transactions will impact response times. Dedicate specific server(s) to handle secure transactions.
  • Select performance benchmarks and use them to quantify the scalability and determine performance targets and future performance improvements or degradations. Include all user types such as "information-gathering" visitors or "transaction" visitors in your benchmarks.
  • Perform "Performance Regression Testing": continuously re-test and measure against the established benchmark tests to ensure that application performance hasn?t been degraded because of the changes you?ve made.
  • Performance testing must continue even after the application is deployed. For applications expected to perform 24/7 inconsequential issues like database logging can degrade performance. Continuous monitoring is key to spotting even the slightest abnormality: set performance capacity thresholds and monitor them.
  • When application transaction volumes reach 40% of maximum expected volumes, it is time to start executing plans to expand the system

How to excute LoadRunner Flex / amf Protocol ?

LoadRunner Flex / amf Protocol


Flex

Flex software development kit provides user interface components like button, data grids, layouts. Flex work as a presentation layer for n-tier web applications.
It maintains a state, where it can send; receive data from server side without reloading the page. Flex works just like AJAX.

Working on Flex Protocol

1. Choose multi protocol recording and select Web, Flex or Web, AMF protocol depending on the requirement.

2. Set the Flex code generation options and don’t forget to provide path of the flex jar files. To Get valid xml we require jar files, which were used by developers like,
  • flex-messaging-core.jar
  • flex-messaging-common.jar
  • flex-messaging-opt.jar
  • flex-messaging-proxy.jar
  • flex-messaging-remoting.jar
3. Start recording the business flow. After completion of recording, in the script you can see the there are flex_amf_call with BEGIN_ARGUMENTS, then XML formatted values and END_ARGUMENTS.

4. To correlate the values in amf request, go to tree view.

5. Find the dynamic value in xml grid of the response and right click and create a parameter.

6. Provide file name and parameter name where you want to capture the dynamic value.

7. Then replace all the instances of that value in the script with the created parameter.