load runner

15
Learn Load runner in a couple of Days Yes, I know Load runner is huge complex tool and cannot be learned in a couple of days. But still from all of my experience what we use regularly in a day to day activity of a performance engineer can be learnt in a couple of days. This article is designed in very practical manner which can be used by fresh graduate who never heard about load runner before or for a person who has lots of experience in load runner. Before going to the actual topic let use start from basic question… What is a LoadRunner? LoadRunner is just a simple tool (I don’t mean it has less features but I meant easy to use) which is used to load the system. Let us take an example, that your customer came to you with an issue that his website is very slow during peak hours of the business. Now to understand what has went wrong we need to monitor the application under peak hours. As for I know no customer will allow you to see his production environment since that’s the bread earner for him and he don’t want to take risk. Now you have to simulate the same environment in your test environment. Ok, you got the servers, applications, everything ready. Now the actual question comes... Do I need about 100 people who access my website (which is running under test environment) and do the regular routine to simulate the same situation that customer is facing. Then this is the foolish thing that you can do!!! Now comes the importance of LoadRunner. This is excellent tool, using which we can mimic or simulate the actual load in our test environment.

Upload: shailendra366

Post on 10-Sep-2014

196 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Load Runner

Learn Load runner in a couple of Days

Yes, I know Load runner is huge complex tool and cannot be learned in a couple of days. But still from all of my experience what we use regularly in a day to day activity of a performance engineer can be learnt in a couple of days.

This article is designed in very practical manner which can be used by fresh graduate who never heard about load runner before or for a person who has lots of experience in load runner.

Before going to the actual topic let use start from basic question…

What is a LoadRunner?LoadRunner is just a simple tool (I don’t mean it has less features but I meant easy to use) which is used to load the system. Let us take an example, that your customer came to you with an issue that his website is very slow during peak hours of the business. Now to understand what has went wrong we need to monitor the application under peak hours. As for I know no customer will allow you to see his production environment since that’s the bread earner for him and he don’t want to take risk.

Now you have to simulate the same environment in your test environment. Ok, you got the servers, applications, everything ready. Now the actual question comes... Do I need about 100 people who access my website (which is running under test environment) and do the regular routine to simulate the same situation that customer is facing. Then this is the foolish thing that you can do!!!

Now comes the importance of LoadRunner. This is excellent tool, using which we can mimic or simulate the actual load in our test environment.

Below we will now see how it all can be done.

Where to download LoadRunner?

LoadRunner can be downloaded with a free trail version of 10 days from hp web site (check in Google) …

With this you can enjoy the LoadRunner for 10 days. For learning this should be more than enough.

TIP: During Installation don’t install Controller part as this is the one which is licensed and rest all is free. After you learn complete LoadRunner scripting and rest of the concepts, you can install this part alone and learn the controller.

LoadRunner Architecture

Page 2: Load Runner

I am not going in to the deep design of LoadRunner. Let us see the main parts of the LoadRunner and how each works.

Above picture it self should have told you half of the story…

The main Components of LoadRunner are…

VUser Generator Controller Analyzer

There are some other parts also but not that important and can safely forget about them.

VUser Generator

This Component is used to create the actual LoadRunner script.

What is LoadRunner Script?

This is just script written using C (Even you can write using Java also but for now let’s stick to C). This script contains some code which actual does exactly what an end user (Who uses the application) does. For example, you can write a script which actually opens the website and click some buttons.This is not used only for web applications, even you can write a script which does a SOAP call (for testing web services), or sending a request to real term emulator based applications (Eg: DOS based applications), or the application can be a win32 application (applications installed in your system).

Ok from now let us stick to web applications as I feel most of us use LoadRunner for testing web based applications only.

Do I need to manually write the code or LR script?

Page 3: Load Runner

That is where the beauty of LoadRunner will come in to picture. The VUser Generator has recorder tool. What you have to do is…

Just start the recorder Do your work (Technically speaking, do the key business transaction which you

want to measure) Stop the recorder

Simple… You are done with the script. Let us see below detailed information on the LoadRunner script.

How does the VUser Generator works internally?

The browser sends the request using HTTP (Hyper text transfer protocol) protocol to server and the server sends the response back to the browser as shown below…

Now when we use VUser Generator and record the user actions, VUGen will sit in between the browser and the server and it will capture all the data that is passing throw. I mean, it will record each request that is sent and the response that it got as shown below…

Now it will create a method for each request that is sent. Let us see more details about these methods in further document. Then when you say run the script, it will resend all those requests by calling those methods. That’s it…So simple logic.

Hey, what is “V” stands for in VUser Gen?

Yes many people even don’t know what it stands for but still use it many times. So “V” means virtual. We are trying to create a Virtual User who does exactly same as the real user. That is the reason we call this tool as Virtual User Generator.

Creating a LR Script

Below steps may change bit from version to version, but still the overall concept remains same. The below steps are using LoadRunner 8.1.

Page 4: Load Runner

Part-1: Get Started

Open the VUser Generator Some main menu click on File New You will get a “New Virtual User” Wizard.

Under this wizard, you can observe 4 things on the left side. 1. New Single Protocol Script.2. New Multiple Protocols Script.3. New Script Recent Protocol4. SOA test Generator.

Which one to use when?

If we are testing the application using only one protocol then we use first option. For example if we are testing web application, then generally we need only one protocol that is Web (HTML/HTTP). In this case we will select first one.

If we need to communicate with the application with more than one protocol then we go for second option. Very rarely this option is used.

Third one is simple. It will just list out all the recently used protocols. Just like history.

Fourth one used while testing SOA based application. Best example would be testing webservices.

Select the protocol to use.For now I will stick to the Web (HTML/HTTP) protocol as we are creating script

for web application.

Part-2: Basic parts of VUser Script

Once you select the protocol and click ok, you will enter a new screen where by default “Start Recording” wizard will be there. For a moment press cancel to close this wizard. Even if it doesn’t come it’s fine.

You can observe 4 main default parts of the script in the left pane. vuser_init

vuser_init would contain all the clicks / transactions / operations which are required at first and which will be done only once.

ActionAction contains the part of the scenario which is repeated many time.

vuser_endvuser_end contains the last part of the scenario which is again done only once.

globals.hAll the variable and methods which are used globally across init, action and end.

For example, if you are testing yahoo mail. Let us take the Customer have given the scenario as follows

1. Opening the mail.yahoo.com 2. Performing the Login

Page 5: Load Runner

3. Check you inbox for new mails.4. Click on any one mail and open it.5. Again perform the above 3rd and 4th step for some time.6. Click logout

In the above business scenario, we are going to do first 2 steps only once in the whole cycle and repeat the 3rd and 4th for some time (may be for some duration and for some number of times). Now once you are done with this you have perform the last 6th step (Again only once). So this is how you need to design your Script…

globals.h

This is very less used option but very useful option. This is a header file contains all global variables and global method which can be accessed in all the 3 places (init, action, end). Let us take simple example; think you want to write a log through out the script after each step in a formatted way as shown below…

Do some transactionPrint “------------------“Print “your message”Print “-----------------“

Now your LR script will be filled with these statement only. Rather than this way we can create a method by name logIt() and place in globals.h as…

logIT(String msg){ Print “------------------“ Print “msg” Print “-----------------“}

Now simply call this method everywhere rather than writing the whole formatting code.

Part-3: Recording Option

Open mail.yahoo.comPerformance Login

Check InboxClick on any mail

Logout

vuser_init

action

vuser_end

Repeat for some time

globals.h

Page 6: Load Runner

Which Protocol to select?First thing is to find which protocol you need to select before you go for actual

recording. It all depends on application that you use and the way you access it. For example, if the application is deployed in some server and accessed through web client (Browser), then you need to select web/HTTP protocol. The main reason for this is that the browser uses HTTP protocol for connecting to the application.

Now if the same application is connected through your mobile or palmtop then you have to use WAP protocol.

RTE protocol: If the application is terminal based. Example will be application that you generally see in old banks consoles, government offices. It will be something DOS based applications where only keyboard can be used to use application.

SOAP Protocol: Some times you need to test the application which is webservices enabled. Then you go for it.

LoadRunner supports huge set of protocols. In rest of our discussions we will use only HTTP protocol as this is more commonly used.

NOTE: VUser Scripts written using different protocol generates different code. If you learn on protocol then it may not that tough to learn another.

Recording Options: These are some of the settings or recording configurations that you need to do before starting the recording. Many people just select default one and start recording and some people even don’t know this exists. In fact these options will make our life easier if you use it properly.

Open this wizard by selecting “Recording Options” under tools or just by pressing “Ctrl+F7”.Main Screens that you see in this wizard are as below… I will cover only important and most commonly used one.

General:Script: To select which language you want to write LR script. Default is C. You

can leave this default as C is very easy to understand. Protocol: again select which protocol to use. If by mistake many protocols come

according to your selection that you did at first, you can deselect them now.Recording: HTML based script or URL based script. I will discuss this in detail

below as this is very important.Network:

Port Mapping: Used to direct traffic via a specific server: port combination to the desired communication protocol. This is very advanced and I have never seen people using it so we can safely neglect this for now with default thing.HTTP Properties:

Advanced: Discussed below in details.Correlation: Adding and Configuring correlation rules. I will come to this in

detail under correlation topic which is very important.

Page 7: Load Runner

Recording level: When to HTML based, URL based script and GUI based script? What is the difference between HTML based script, URL based script?

These are the very common question asked by many people. And this is most confusing thing. Let me make very clear and easy to learn it.

HTML Based: Using this recording mode LR will generate script by performing certain user actions on only HTML context. This mode recognizes the user inputs either in the form of data or in the form of forms. For each action that we perform on the application, LR will generate a function called web_url. Along with this 4 more functions will generated depending on actions we perform. Those are

web_submit_data ()web_submit_form ()web_link ()web_image ()

URL based: This recording mode will be used on Non-HTML resources like Bitmap, Jpeg, gif, java scripts..., In this mode LR will generate the function web_url for each and every step that we perform on the application. This mode recognizes the user input data only in the form of data submitted function. Some more functions will generates such as

web_submit_data ()web_concurrent_start ()web_concurrent_end ()

NOTE: Correlations are bit messy and difficult in case of HTML based mode.

I know its bit confusing; Lets take an example and learn it in more detail. These concepts are very important, as the whole Performance Numbers that you give or you get will depend on these settings. So as a performance Engineer you have to be more perfect in selecting this mode.

Let’s take an example and learn. Scenario:

Step -1: Open the Google page Step -2: Type “Hello” in the text box and press search.

Now basically we want to measure the performance of Google page. Here performance is the time (Technically speaking response time) of home page and search button.

Now we all know this is web based application and hence set the protocol as “web/HTTP”. Now let us see what is recorded when each recording option is selected.Little background:Load runner Transaction: It can be just a simple user action or group of actions. No fix rule to say on this. It all depends what you want to measure. If a customer says, I click on

Page 8: Load Runner

the button “a” and then on button “b” and he wants to treat this as one transaction. Then it is. It all depends what you or customer want to measure.

For now according to me we have 2 transactions. Each is one step performed as said above.

HTML Based recording:Script Type: A Script Containing Explicit URLs only (e.g.: web_url,

web_submit_data)Non HTML Generated elements: Record in a separate steps and use concurrent

groups

Now with these settings the script looks like…

web_url ("www.google.com", "URL=http://www.google.com/", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST);

web_concurrent_start(NULL);

web_url("favicon.ico", "URL=http://www.google.com/favicon.ico", "TargetFrame=", "Resource=1", "RecContentType=image/x-icon", "Referer=", "Snapshot=t2.inf", LAST);

web_url("nav_logo3.png", "URL=http://www.google.com/images/nav_logo3.png", "TargetFrame=", "Resource=1", "RecContentType=image/png", "Referer=http://www.google.com/", "Snapshot=t3.inf", LAST);

web_concurrent_end(NULL);

Page 9: Load Runner

web_submit_data("search", "Action=http://www.google.com/search", "Method=GET", "EncType=", "TargetFrame=", "RecContentType=text/html", "Referer=http://www.google.com/", "Snapshot=t4.inf", "Mode=HTML", ITEMDATA, "Name=hl", "Value=en", ENDITEM, "Name=q", "Value=Hello", ENDITEM, "Name=btnG", "Value=Google Search", ENDITEM, LAST);

I will cover explanation of each step later. For now just see 2 method web_url() and web_submit_form(). One generated by the step-1 and another by step-2.

URL Based recording: Now if the same 2 steps are performed using this mode then the script looks like below.NOTE: URL Based with default options…

"Create Concurrent Groups for resources after their source HTML Page" = Enabled

"Use web_Custom_request only" = Disabled

web_url ("www.google.com", "URL=http://www.google.com/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTTP", LAST);

web_url ("logo.gif", "URL=http://www.google.com/intl/en_ALL/images/logo.gif", "Resource=1", "RecContentType=image/gif", "Referer=http://www.google.com/", "Snapshot=t2.inf", LAST);

web_concurrent_start(NULL);

web_url("favicon.ico", "URL=http://www.google.com/favicon.ico",

Page 10: Load Runner

"Resource=1", "RecContentType=image/x-icon", "Referer=", "Snapshot=t3.inf", LAST);

web_url("nav_logo3.png", "URL=http://www.google.com/images/nav_logo3.png", "Resource=1", "RecContentType=image/png", "Referer=http://www.google.com/", "Snapshot=t4.inf", LAST);

web_concurrent_end(NULL);

web_submit_data("search", "Action=http://www.google.com/search", "Method=GET", "EncType=", "RecContentType=text/html", "Referer=http://www.google.com/", "Snapshot=t5.inf", "Mode=HTTP", ITEMDATA, "Name=hl", "Value=en", ENDITEM, "Name=q", "Value=Hello", ENDITEM, "Name=btnG", "Value=Google Search", ENDITEM, LAST);

web_url("2.jpg", "URL=http://img.youtube.com/vi/PDZcqBgCS74/2.jpg", "Resource=1", "RecContentType=image/jpeg", "Referer=http://www.google.com/search?

hl=en&q=Hello&btnG=Google+Search", "Snapshot=t6.inf", LAST);

Page 11: Load Runner

Now just have a look once again the two scripts and see what the difference is. The difference is,

web_url ("2.jpg", "URL=http://img.youtube.com/vi/PDZcqBgCS74/2.jpg", "Resource=1", "RecContentType=image/jpeg",

Now, let us come back to the definition. HTML mode is the actual