Sunday, 17 May 2015

Testing Web Services With a Standard Web Vuser

It is possible to test web services using the standard Web (HTTP/HTML) virtual user type instead of the Web Services vuser type. The main disadvantage of this is that you cannot generate your SOAP body from the WSDL file using the VuGen wizard. But if you know what your XML request should look like, then you shouldn’t have any real problems.
Here are my tips:
  • Send your SOAP payload using lr_custom_request().
  • Add a SOAPAction HTTP header using web_add_header().
  • Remove unnecessary HTTP headers (that are generated automatically by VuGen) with web_remove_auto_header().
  • Don’t forget to verify that you get a valid response. Use web_reg_find() for a simple check. For better verification of the SOAP response use lr_xml_find().
  • To extract values from the response body, use lr_xml_get_values(). Brush up on your XPath qeries beforehand though.
  • It may be necessary to HTML-encode some characters in your XML/SOAP message (e.g. convert “&” to “&”). Unfortunately VuGen does not provide this functionality (but HP could easily add it to the web_convert_param function), so you will have to either write (or find) a function to do it, or convert all the entries in your data table before running the script.
As an example, here is a simple script that makes use of a web service that will look up the source of a Shakespeare quote for you. The WSDL is available from http://www.xmlme.com/WSShakespeare.asmx?wsdl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Action()
{
  // ContentCheck Rules for known error messages
  web_global_verification("Text=Speech not found", "ID=SpeechNotFound", LAST);
 
  lr_start_transaction ("Search For Shakespeare Quote");
 
  // By default, VuGen sends a user-agent header.
  // Let's remove this as an example of removing automatically generated headers.
  web_remove_auto_header("User-Agent", "ImplicitGen=No", LAST); 
 
  // Add a SOAPAction HTTP header
  web_add_header("SOAPAction", "http://xmlme.com/WebServices/GetSpeech");
 
  // Save entire body from the HTTP response for later checking with lr_xml_find.
  web_reg_save_param("ResponseBody",
    "LB=",
    "RB=",
    "Search=Body",
    "IgnoreRedirections=Yes",
    LAST);
 
  // Note that the text to search for would normally be replaced with a parameter,
  // and so would the <Request> element of the below SOAP message.
  web_reg_find("Text=TWELFTH NIGHT", LAST);
 
  web_custom_request("Search Shakespeare", 
    "URL=http://www.xmlme.com/WSShakespeare.asmx", 
    "Method=POST", 
    "Resource=0", 
    "Referer=", 
    "Snapshot=t1.inf", 
    "Mode=URL", 
    "EncType=text/xml; charset=utf-8", 
    "Body=" // As it is SOAP, you are unlikely to have to use BodyBinary, unless your request has CDATA.
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
    "<soap:Body>"
    "<GetSpeech xmlns=\"http://xmlme.com/WebServices\">"
    "<Request>Be not afraid of greatness</Request>"
    "</GetSpeech>"
    "</soap:Body>"
    "</soap:Envelope>",
    LAST);
 
  // The response from the web service looks like this:
  /*
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
      <GetSpeechResponse xmlns="http://xmlme.com/WebServices">
        <GetSpeechResult>
          &lt;SPEECH&gt;
          &lt;PLAY&gt;TWELFTH NIGHT&lt;/PLAY&gt;
          &lt;SPEAKER&gt;MALVOLIO&lt;/SPEAKER&gt;
          'Be not afraid of greatness:' 'twas well writ.&lt;/SPEECH&gt;
        </GetSpeechResult>
      </GetSpeechResponse>
    </soap:Body>
  </soap:Envelope>
  */
 
  // An example of extracting the a value from a SOAP reponse.
  // This saves the <GetSpeechResult> element into {OutputParameter}.
  // The same syntax could be used with lr_xml_find to check the response.
  lr_xml_extract("XML={ResponseBody}", 
    "XMLFragmentParam=OutputParameter", 
    "Query=/soap:Envelope/soap:Body/GetSpeechResponse/GetSpeechResult", LAST);
  lr_output_message("Source of Shakespeare quote: %s", lr_eval_string("{OutputParameter}"));
 
  lr_end_transaction ("Search For Shakespeare Quote", LR_AUTO);
 
  return 0;
}

Saturday, 16 May 2015

LoadRunner, Memory Violations, lr_eval_string_ext and Pointers (ANSI C Style)

I think it’ll be quite accurate to say that an average programmer like me is daunted when first faced with the concept of pointers and memory management in C. During the initial programming years (much of which inevitably had to be in C), I tried my best to avoid using pointers in my code. Whether it be using character arrays with pre-defined size (who cares if it takes much more memory than is needed) or some other “nifty” trick… I thought I could get away as long as I can compile and run just “this” program. But I had to face it during a networking class in school when I worked on a peer-to-peer file sharing project and one of my classmates convinced me to “do it right” and pay heed to the requirement of the program being able to work with other students’ code.
So after much head-scratching and soul-searching, I begrudgingly revisited the concepts and began (or so I thought) to grasp the idea of address spaces. l-values vs. r-values and pointers. It all seemed to make sense and fit in place like a jigsaw puzzle finally coming together. And not before long, with some encouragement and confidence building, I rewrote the program using pointers instead of pre-allocated char arrays and making it as compatible as possible. But if it was supposed to make me happy and content, it didn’t last long and whatever feeling of competence I felt was shattered to bits when I compiled the program for the first time and got compile time errors that didn’t make any sense at all. It was even worse and torturous when after a few cycles of modifying and debugging, it finally compiled beautifully (oh the elation…) and then the first time I ran it, it threw a slew of memory violation errors and crashed as beautifully as it compiled.
Years have passed since then…some of which were spent in writing code in other languages (it doesn’t have pointers? I’ll take 10). And some others in trying to come to terms with how even after understanding the concepts if I now have to write a C program and I decide to (or have to) use pointers, the error messages still baffle the heck out of me. Brief moments of competence have existed…when after writing, re-writing, debugging, debugging again…debugging a few more times, I was finally able to turn out a decent piece of code that could accomplish what it was supposed to in a relatively efficient manner.
Background:
So how does all this relate to the subject of this post? A few days ago, I was writing a LoadRunner script for a web application which had an inquiry page that submitted a request. Depending on the data submitted, the request returned either a response page with the final result or a set of intermediate questions that needed to be answered. After submitting the answers, it again returned either another set of questions or the final result. Once the answers were submitted the second time, it returned the final result page. The number of questions returned was not constant, however 8 questions was the maximum. So a part of scenario logic was this:
a. Submit the initial inquiry
b. If Question Set A is returned, determine the number of questions, construct an answer string and submit
c. If Question Set B is returned, determine the number of questions, construct an answer string and submit
d. Final response
Problem:
Since the questions returned were in a select box, it was easy to find the left and right boundaries and use web_reg_save_param with "Ord=All". In this case, since the questions were in the form:
<SELECT NAME="Answer2" SIZE="5">
  <OPTION value="0"> ABC</OPTION><br>
  <OPTION value="1"> DEF</OPTION><br>
  <OPTION value="2"> MTG</OPTION><br>
  <OPTION value="3"> SVG</OPTION><br>
  <OPTION value="4">NONE</OPTION><br>
</SELECT>
it will be:

web_reg_save_param ("suffix", "LB=<SELECT NAME=\"Answer", "RB=\" SIZE", 
"Ord=All","NOTFOUND=Warning", LAST);
However, it wasn't as easy as determining the number of matches from {suffix_count} and looping to create a custom answer string. Each question had a relative order from 1 – 8 like the one above (the numeral after “Answer”) and the answer string had to be constructed based on that. The challenge was that the number of questions was variable and the order didn’t always start with 1 and go 1, 2, 3…and so on. So if 4 questions were returned, they could be labeled Answer2, Answer3, Answer5, Answer6 and based on this, the answer string would be answer2=2&answer3=2&answer5=2&answer6=2 (it didn’t matter if the questions were answered correctly, so a constant 2 would do). If I submitted answer1=2… here, it would return an error saying “Invalid Response” or something like that.
Solution:
So what I had to do was to save that suffix number in a temp variable and construct the answer string by concatenating it together. So, something like:

c = atoi(lr_eval_string("{suffix_count}"));
if(c>0){
  for(i=1;i<=c;i++){
    strcat(answerString, "Answer");
    sprintf(sfx, "{suffix_%d}", i);
    strcat(answerString, lr_eval_string(sfx));
    strcat(answerString, "=2&");
  }
  lr_save_string(answerString, "aString");
  ...
And then I would create a web_custom_request and submit it:

web_custom_request("AnswerSetA",
  …
  …
  …
  "Body={aString}submit1.x=61&submit1.y=27",
"LAST");
My first instinct, as I’ve mentioned earlier was to use character arrays for both answerString and sfx.

char answerString[256], sfx[10];
I figured that the chances of the string being longer than 256 chars was remote so I was safe. And it worked fine when I ran it in VuGen. But when I ran the load scenario, all the users belonging to this script’s group failed exactly after 4th or 5th iteration. The error was something I hadn’t seen before:
Action.c(162): Error (-17991): Failed to add item to mfifo data structure.
on the line with lr_eval_string. I searched online and came across this link (http://www.sqaforums.com/showflat.php?Number=420958) which suggested using lr_eval_string_ext instead of lr_eval_string to free memory earlier. The help on lr_eval_string also mentions:
Note: lr_eval_string allocates memory internally. The memory is freed at the end of each iteration. If you evaluate a parameter or parameters in a loop, conserve memory by not using lr_eval_string . Instead, use lr_eval_string_ext and free the memory in each loop iteration with lr_eval_string_ext_free.
I changed the code to:

c = atoi(lr_eval_string("{suffix_count}"));
if(c>0){
  for(i=1;i<=c;i++){
    strcat(answerString, "Answer");
    sprintf(sfx, "{suffix_%d}", i);
    lr_eval_string_ext(sfx,strlen(sfx), &sfx1, &prmLen, 0, 0, -1);
    strcat(answerString, sfx1);
    strcat(answerString, "=2&");
    lr_eval_string_ext_free(&sfx1);
  }
  lr_save_string(answerString, "aString");
  ...
but to my disappointment, it still threw an error when executing in Controller after 4thiteration. The good part was that the error message was familiar, the bad part was that it was a memory violation exception:
Action.c(168): Error: C interpreter run time error: Action.c (168): Error -- memory violation : Exception ACCESS_VIOLATION
For some reason, I felt that all the years of avoiding or trying to avoid using pointers obligated me to get to the root of the issue this time and fix it instead of coming up with a workaround. The actual issue however turned out to be something else and I’ll come back to it later. First order of the day…use char pointers instead of static arrays to manage the strings.
To start:

char *answerString; //instead of char answerString[256]
char sfx[10]; //this still can be an array
Next step was to figure out how much memory will I need to allocate based on the number of questions returned and then allocate it. This was done using malloc:

//we need AnswerX=2& times the number of questions, + 1 for '\0' 
if((answerString = (char *)malloc(c * 10 * sizeof(char) + 1)) == NULL){
  lr_output_message("Insufficient Memory!!");
  return -1;
}
Also, we have to initialize it because there may be some garbage in the allocated space that may hinder the proper functioning of strcat:

*answerString = '\0';
Now we have something very similar to a brand new char array, but only of the exact size that we need. Next, we create the string exactly as above, and I used lr_eval_string instead of lr_eval_string_ext because I honestly didn’t think that was the issue. After creating the string, I null-terminated it.

for(i=1;i<=c;i++){ 
  strcat(answerString, "Answer"); 
  sprintf(sfx, "{suffix_%d}", i); 
  strcat(answerString, lr_eval_string(sfx)); 
  strcat(answerString, "=2&"); 
} 
answerString[c * 10 * sizeof(char)] = '\0'; 
lr_save_string(answerString, "aString"); 
free(answerString); 

---
Another way to clear array
memset(answerString, 0, sizeof(answerString));
And the best part, after saving the string in a parameter, I free the associated memory and relish my guilt-free existence (at least in terms of this script). The script worked like a charm, not only through VuGen but multiple iterations through the scenario in Controller.
So what was the issue with using character array: the issue was not that LR agents were running out of memory because I had used 256 bytes when I actually only needed less than that. The issue was that I was not emptying the array before using it. I had declared it within the Action itself:

Action()
{
  int i,c;
  char answerString[256], sfx[10];
and I wrongly assumed that LoadRunner throws away variables from previous iteration and initializes brand new variables in every new iteration. Instead, what happened as in this case when I used strcat was that it was concatenating the new answer string from this iteration to whatever was left from the previous iteration. So after a few iterations, it ran out of the pre-allocated 256 bytes of space and threw the memory violation exception. I could’ve continued to use char array (and I’m glad I didn’t) by just re-initializing it in every iteration.
So lesson learnt. Hopefully all this helps somebody not make the same mistakes I made. I certainly won’t and I will also be less hesitant in using pointers. Even though I’m pretty sure this is not the last I’ve seen of memory violation exceptions, I can say that I’ll be ready to learn something new next time that happens.
By the way…that peer-to-peer file sharing application, I finally was able to compile it and make it work using a mix of pointers and character arrays. It worked great and I felt satisfied when I completed it. But of course when I was demonstrating it to the TA, it didn’t function as expected and I later found out that it was because I had forgotten to null-terminate a string.

Friday, 15 May 2015

Loadrunner :How to record PDF file saving

long fp;
char *data;
unsigned long prmLen;

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

//Truncate to zero length or create file for writing.
fp = fopen("c:\\temp\\my_file.pdf","wb");

//Set the parameter size large enough to save the data.
web_set_max_html_param_len("200000");

//Use web_reg_save_param with the correct boundary to capture the data returned by the server.
web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);

web_url("PDF",
"URL=http://www.testing.com/writings/automate.pdf",
"TargetFrame=",
"Resource=0",
"RecContentType=application/pdf",
"Referer=http://www.testing.com/writings.html",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);

//Get the download size.
lr_eval_string_ext("{FILED}", strlen("{FILED}"), &data, &prmLen, 00, -1);

//Write the data saved to an output file.
fwrite(data, prmLen, 1, fp);

//Close the file pointer.
fclose(fp);

Tuesday, 12 May 2015

performance testing laws

Here are some of important law the drives performance testing activity.

1. Little’s Law
In performance testing environment, the Total Number of Users in the System is the Product of the Throughput and the total time taken for processing the requests. This is one of the most frequently used law while doing performance testing
N = X * (Z + R) where,
N – Number of Users
X – Throughput
Z – Think Time and
R – Response Time
Example: If the total time at a particular request ( Z + R) is 15 Sec's, and the Throughput is 100 Requests/Sec, then the Total Number of Users is 15*100 = 1500 Users

2. Bounding Analysis Law 
The Maximum Throughput of a System is equal to the inverse of the Service Demand.
Zmax = 1/SD
Throughput – The number of requests processed by a system in unit time
SD – Time taken by the system to process a particular request
Example: if the Service Demand of a System is 0.1, the maximum Throughput of the system is 1/0.1 which is 10 Requests/Sec.

3. Forced Flow Law
The Request Arrival Rate is equal to the throughput, when the system is not 100% utilized. In other words, whatever flows into the system, flows out of the system, till the system is fully utilized
Request Arrival = Throughput, when U<100%
Example: when the Utilization is 50% and Arrival rate is 5 Requests/Second, the Throughput is also 5 Requests/Second.

4. Utilization Law 
The Utilization Law is just an extension of the Bounding Analysis Law. The Utilization of a System is the Product of Throughput and Service Demand
U = Z * SD
Example: If the Throughput is 5 Requests/Sec and the Service Demand is 0.1, then the Utilization is 5 * 0.1, which is 50%
At Peak Utilization, U =1, so,
Z = 1/SD, which is the maximum Throughput of the System (which is the bounding Analysis Law)

5. Amdahl's law
http://en.wikipedia.org/wiki/Amdahl%27s_law

JVM explained

What are EdenSpace,Survivor Space,Young Generation,Java Heap Area,Virtual Space,PermGenSpace,Native Area in JVM?

Eden Space:

Eden Space is a Part of Java Heap where the JVM initially creates any objects, where most objects die and quickly are cleaned up by the minor Garbage Collectors (Note: Full Garbage Collection is different from Minor Garbage Collection). Usually any new objects created inside a Java Method go into Eden space and the objects space is reclaimed once the method execution completes. Where as the Instance Variables of a Class usually lives longer until the Object based on that class gets destroyed. When Eden fills up it causes a minor collection, in which some surviving objects are moved to an older generation.

Survivor Spaces:

Eden Sapce has two Survivor spaces. One survivor space is empty at any given time. These Survivor Spaces serves as the destination of the next copying collection of any living objects in eden and the other survivor space.
The parameter SurvivorRatio can be used to tune the size of the survivor spaces.
-XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6
If survivor spaces are too small copying collection overflows directly into the tenured generation.

Young Generation: (-XX:MaxNewSize)

Till JDK1.3 and 1.4 we used to set the Young Generation Size using -XX:MaxNewSize. But from JDK1.4 onwards we set the YoungGeneration size using (-Xmn) JVM option.
Young Generation size is controlled by NewRatio. It means setting -XX:NewRatio=3 means that the ratio between the Old Generation and the Young Generation is 1:3
.
Similarly -XX:NewRatio=8 means that 8:1 ratio of tenured and young generation.
NewRatio: NewRatio is actually the ratio between the (YoungGenaration/Old Generations) has default values of 2 on Sparc , 12 on client Intel, and 8 everywhere else.
NOTE: After JDK 1.4 The Young Generation Size can be set using (-Xmn) as well.

Virtual Space-1: (MaxNewSize – NewSize)

The First Virtual Space is actually shows the difference between the -XX:NewSize and -XX:MaxNewSize. Or we can say that it is basically a difference between the Initial Young Size and the Maximum Young Size.

Java Heap Area: (-Xmx and -Xms)

Java Heap is a Memory area inside the Java Process which holds the java objects. Java Heap is a combination of Young Generation Heap and Old Generation Heap. We can set the Initial Java Heap Size using -Xms JVM parameter similarly if we want to set the Maximum Heap Size then we can use -Xmx JVM parameter to define it.
Example:
-Xmx1024m —> Means Setting the Maximum limit of Heap as 1 GB
-Xms512m —> Means setting Java Heap Initial Size as 512m

NOTE: It is always recommended to set the Initial and the Maximum Heap size values as same for better performance.

NOTE: The Theoretical limitation of Maximum Heap size for a 32 bit JVM is upto 4GB. Because of the Memory Fragmentation, Kernel Space Addressing, Swap memory usages and the Virtual Machine Overheads are some factors JVM does not allow us to allocate whole 4GB memory for Heap in a 32 bit JVM. So usually on 32-bit Windows Operating Systems the Maximum can be from 1.4 GB to 1.6 GB.
.
If we want a Larger memory allocation according to our application requirement then we must choose the 64-bit operating systems with 64 bit JVM. 64-bit JVM provides us a larger address space. So we can have much larger Java Heap with the increased number of Threads allocation area. Based on the Nature of your Operating system in a 64 bit JVM you can even set the Maximum Heap size upto 32GB.
Example: -Xms32g -Xmx32g -Xmn4g

Virtual Space-2: (MaxHeapSize – InitialHeapSize)

The Second Virtual Space is actually the Difference between the Maximum Heap size (-Xmx)and the Initial Heap Size(-Xms). This is called as virtual space because initially the JVM will allocate the Initial Heap Size and then according to the requirement the Heap size can grow till the MaxHeapSize.

PermGen Space: (-XX:MaxPermSize)

PermGen is a non-heap memory area where the Class Loading happens and the JVM allocates spaces for classes, class meta data, java methods and the reference Objects here. The PermGen is independent from the Heap Area. It can be resized according to the requirement using -XX:MaxPermSize and -XX:PermSize JVM Options. The Garbage collection happens in this area of JVM Memory as well. The Garbage collection in this area is called as “Class GC”. We can disable the Class Garbage Collection using the JVM Option -noclassgc. if ”-noclassgc” Java Option is added while starting the Server. In that case the Classes instances which are not required will not be Garbage collected.

Native Area:

Native Memory is an area which is usually used by the JVM for it’s internal operations and to execute the JNI codes. The JVM Uses Native Memory for Code Optimization and for loading the classes and libraries along with the intermediate code generation.
The Size of the Native Memory depends on the Architecture of the Operating System and the amount of memory which is already commited to the Java Heap. Native memory is an Process Area where the JNI codes gets loaded or JVM Libraries gets loaded or the native Performance packs and the Proxy Modules gets loaded.

There is no JVM Option available to size the Native Area. but we can calculate it approximately using the following formula:

NativeMemory = (ProcessSize – MaxHeapSize – MaxPermSize)

What are the parts Of JVM And JVM Architecture Diagram?

Architecture of JVM:

JVM is the heart of any Java based Application Server. We face most of the issues deu to incorrect JVM tuning. It is very important to understand the Overall architecture of the JVM in order to trouble shoot different JVM tuning related issues.Here we are going to discuss the Architecture and the Major parts of a Java Process and the Java Heap Division.

The Following Diagram is just a basic overview of a Java Process in a 2 GB process Size Machine. Usually in 32 bit Windows Operating Systems the default process size will be 2 GB (In Unix based 64 bit operating Systems it can be 4GB or more). So i draw the following Diagram of Java Process to explain the Java Process partitions in a 2Gb process size machine.
Java Process Architecture Diagram:





In the above diagram we will find different partitions of a Java Process. Please compare the above diagram with below descriptions.

1)Just for Example we can see that Process Size is 2048 MB (2GB)

2) The Java Heap Size is 1024MB (means 1GB) -Xmx1024m

3) Native Space = ( ProcessSize – MaxHeapSize – MaxPermSize) It means around 768 MB of Native Space.

4) MaxPermSpace is around -XX:MaxPermSize=256m

5)Young Generation Space is around 40% of Maximum Java Heap.

What Are these Different Parts in JVM?

Eden Space:

Eden Space is a Part of Java Heap where the JVM initially creates any objects, where most objects die and quickly are cleaned up by the minor Garbage Collectors (Note: Full Garbage Collection is different from Minor Garbage Collection). Usually any new objects created inside a Java Method go into Eden space and the objects space is reclaimed once the method execution completes. Where as the Instance Variables of a Class usually lives longer until the Object based on that class gets destroyed. When Eden fills up it causes a minor collection, in which some surviving objects are moved to an older generation.

Survivor Spaces:

Eden Sapce has two Survivor spaces. One survivor space is empty at any given time. These Survivor Spaces serves as the destination of the next copying collection of any living objects in eden and the other survivor space.
The parameter SurvivorRatio can be used to tune the size of the survivor spaces.
-XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6
If survivor spaces are too small copying collection overflows directly into the tenured generation.

Young Generation: (-XX:MaxNewSize)

Till JDK1.3 and 1.4 we used to set the Young Generation Size using -XX:MaxNewSize. But from JDK1.4 onwards we set the YoungGeneration size using (-Xmn) JVM option.
Young Generation size is controlled by NewRatio. It means setting -XX:NewRatio=3 means that the ratio between the Old Generation and the Young Generation is 1:3
.
Similarly -XX:NewRatio=8 means that 8:1 ratio of tenured and young generation.
NewRatio: NewRatio is actually the ratio between the (YoungGenaration/Old Generations) has default values of 2 on Sparc , 12 on client Intel, and 8 everywhere else.
NOTE: After JDK 1.4 The Young Generation Size can be set using (-Xmn) as well.

Virtual Space-1: (MaxNewSize – NewSize)

The First Virtual Space is actually shows the difference between the -XX:NewSize and -XX:MaxNewSize. Or we can say that it is basically a difference between the Initial Young Size and the Maximum Young Size.

Java Heap Area: (-Xmx and -Xms)

Java Heap is a Memory area inside the Java Process which holds the java objects. Java Heap is a combination of Young Generation Heap and Old Generation Heap. We can set the Initial Java Heap Size using -Xms JVM parameter similarly if we want to set the Maximum Heap Size then we can use -Xmx JVM parameter to define it.
Example:
-Xmx1024m —> Means Setting the Maximum limit of Heap as 1 GB
-Xms512m —> Means setting Java Heap Initial Size as 512m

NOTE: It is always recommended to set the Initial and the Maximum Heap size values as same for better performance.

NOTE: The Theoretical limitation of Maximum Heap size for a 32 bit JVM is upto 4GB. Because of the Memory Fragmentation, Kernel Space Addressing, Swap memory usages and the Virtual Machine Overheads are some factors JVM does not allow us to allocate whole 4GB memory for Heap in a 32 bit JVM. So usually on 32-bit Windows Operating Systems the Maximum can be from 1.4 GB to 1.6 GB.
.
If we want a Larger memory allocation according to our application requirement then we must choose the 64-bit operating systems with 64 bit JVM. 64-bit JVM provides us a larger address space. So we can have much larger Java Heap with the increased number of Threads allocation area. Based on the Nature of your Operating system in a 64 bit JVM you can even set the Maximum Heap size upto 32GB.
Example: -Xms32g -Xmx32g -Xmn4g

Virtual Space-2: (MaxHeapSize – InitialHeapSize)

The Second Virtual Space is actually the Difference between the Maximum Heap size (-Xmx)and the Initial Heap Size(-Xms). This is called as virtual space because initially the JVM will allocate the Initial Heap Size and then according to the requirement the Heap size can grow till the MaxHeapSize.

PermGen Space: (-XX:MaxPermSize)

PermGen is a non-heap memory area where the Class Loading happens and the JVM allocates spaces for classes, class meta data, java methods and the reference Objects here. The PermGen is independent from the Heap Area. It can be resized according to the requirement using -XX:MaxPermSize and -XX:PermSize JVM Options. The Garbage collection happens in this area of JVM Memory as well. The Garbage collection in this area is called as “Class GC”. We can disable the Class Garbage Collection using the JVM Option -noclassgc. if ”-noclassgc” Java Option is added while starting the Server. In that case the Classes instances which are not required will not be Garbage collected.

Native Area:

Native Memory is an area which is usually used by the JVM for it’s internal operations and to execute the JNI codes. The JVM Uses Native Memory for Code Optimization and for loading the classes and libraries along with the intermediate code generation.
The Size of the Native Memory depends on the Architecture of the Operating System and the amount of memory which is already commited to the Java Heap. Native memory is an Process Area where the JNI codes gets loaded or JVM Libraries gets loaded or the native Performance packs and the Proxy Modules gets loaded.

There is no JVM Option available to size the Native Area. but we can calculate it approximately using the following formula:

NativeMemory = (ProcessSize – MaxHeapSize – MaxPermSize)

LoadRunner Correlation with web_reg_save_param_regexp

Do you have a correlation which you can’t solve because the values of the left and right boundary are dynamic? Correlation is an essential part of performance test scripting and there are plenty of different challenges with correlation. Imagine having a value of “GraphA123567EndGraphA” and the goal is to correlate 123567
From the example above, the left and right boundaries would be “LB=GraphA” “RB=EndGraphA”
What if the word GraphA is dynamic and can be anything from GraphA-GraphZ?
There is a solution at hand!
Using web_reg_save_param_regex will allow the user to grab a correlation value using dynamic left and right boundaries. This function uses the power of regular expressions, below are a few examples:
Example 1:
Source: “GraphA123567EndGraphA”
Solution: web_reg_save_param_regexp(“ParamName=CorrValue”, “RegExp=\“Graph[A-Za-z]\”, \“([0-9]+)\”, \“EndGraph[A-Za-z]\””, LAST);
Result: 123567
Example 2:
Correlate the values from a drop down list of a form
Source: dropdown >>> red, blue, green
Solution: web_reg_save_param_regexp(“ParamName=ColourList”, “RegExp=option=[0-9]+>([A-Za-z])
  • {ColourList1}=red
  • {ColourList2}=blue
  • {ColourList3}=green
Example 3:
Correlate up till the end of 642
Source:J\u002blsGd3zj1qdP\u002bvk0vDRaKyJFde5tCa6spDEy08SNab1hP8j5GTs4j6\u002f\u002bTqOwvxMHEQZLWd\u002btu8NlHJrVAarIQ==|634998513832503642″];
Solution: web_reg_save_param_regexp(“ParamName=SecurityString”,”RegExp=\”([A-Z0-9a-z\\\\+]+==\\|[0-9]+)\”\\];”,LAST);
Result:J\u002blsGd3zj1qdP\u002bvk0vDRaKyJFde5tCa6spDEy08SNab1hP8j5GTs4j6\u002f\u002bTqOwvxMHEQZLWd\u002btu8NlHJrVAarIQ==|634998513832503642
Example 4:
Correlate only “634998513832503642” Source:
<em>J\u002blsGd3zj1qdP\u002bvk0vDRaKyJFde5tCa6spDEy08SNab1hP8j5GTs4j6\u002f\u002bTqOwvxMHEQZLWd\u002btu8NlHJrVAarIQ==|634998513832503642"];</em>
Solution:
web_reg_save_param_regexp("ParamName=SecurityString",
    "RegExp=\"[A-Z0-9a-z\\\\+]+==\\|([0-9]+)\"\\];",
    LAST);
Result: 634998513832503642
So what is a Regular Expression? 
Also known as regex, a regular expression is a search string which enables matching of a string. Think of it as an advance searching function which can pick out values from a string of multiple characters.
Examples of regex:
  • \d matches a single digit
  • \w matches a single word (including alphanumeric characters and underscore)
  • [A-Z]+ matches any word which is upper case
  • [a-z]+ matches any word which is lower case
  • [0-9]+ matches any numeric value
There are other alternatives to web_reg_save_param_regexp. However these functions are limited and not as flexible.
LB/DIG RB/DIG – # will be a wildcard for a numeric value“session_id_##”
  • Adding LB/IC/DIG will ignore case
  • “LB/IC/DIG=session_id_##=” (e.g. Session_id_20)
LB/ALNUM or RB/ALNUM – ^ will be a wildcard for an alphanumeric value
  • ALNUMIC – ignore case
  • ALNUMLC – match only lower case
  • ALNUMUC – match only upper case
SaveOffSet
  • If there is a dynamic value for a boundary e.g. “session_id_2” (3,4,5)
  • SaveOffSet = 2 (to cover “2=”)
  • Web_reg_save_param(“SessionID”, “LB=session_id_”, “RB=\””, “SaveOffSet=2”, LAST);
LR implementation
  • PERL based
  • LR 11 does not support multiple capture groups however this is now supported in LR 11.52 (example below)
Example Multiple Capture Groups
Source: rows”:[[“NW,RO,RA”,”DLY”,”10/07/2011″,”10/17/2011″,”10/01/2011″,”RA”,”Y”,”FR”,”AMEA”,”AC”,”1945″,”50″,”50″,”AC 100IOSH-08″,”UserDefined”,”10/07/2011″,”Reassigned”…”
Solution: web_reg_save_param_regexp(“ParamName=ParamValue”,”RegExp=rows”:\[\[“[^”\r\n]*”,”([A-Z]{3})”,”[^”\r\n]*”,”[^”\r\n]*”,”[^\/]+\/[\d]+?\/2011″,”[A-Za-z]*”,”[^”\r\n]*”,”[^”\r\n]*”,”([^”\r\n]*)”,”[^”\r\n]*”,”([^”\r\n]*)”,LAST);
Result:
  • {ParamValue1} = DLY
  • {ParamValue2} = AMEA
  • {ParamValue3} = 1945