In previous blogs, we know that Netgend platform, built on javascript, can support 50,000 VUsers on one system. But performance testing is not only about supporting a large number VUsers, it's also about flexibility - how easy it is to emulate client.
To make the test platform flexible, we have to deal with per-VUser variables, these are variables that are only accessible (read and write) by a VUser. This is the basis for many VUsers to run independently. We will use "pvar" to denote per-VUser variable in this blog.
Loadrunner offers flexible support on pvar, you can create a pvar and assign value to it and use its value later to do some operations. Down side is that it requires some good C background to use it. In netgend javascript, a variable is naturally a pvar. So user doesn't need much programming background. Here is a quick comparison.
Loadrunner | NetGend Javascript | |
---|---|---|
Assign to a pvar | lr_save_string("John Doe", "fullName") //generate a random number //between 20 and 30 randomnumber = rand() % 11 randomnumber += 20 lr_save_int(randomnumber, "age") | fullName = "John Doe"; age = randNumber(20,30); |
get value from pvar | name = lr_eval_string("fullName"); age = lr_eval_string("age");
char msgbuffer[100];
sprintf(msgbuffer, "my name is %s, age is %s", name, age);
lr_save_string(msgbuffer, "msgbuffer")
| msgbuffer = "my name is ${fullName}, my age is ${age}"; |
compare pvar with a string | if(strcmp(lr_eval_string("{pMonth}"),"JAN")==0) | if (pMonth == "JAN") { ...... } |
The above is about scalar pvar, it only holds one value. What about array variable? We need it to hold a list of values, for instance, a list of links within a HTML page. In netgend javascript, a pvar can be array variable, you just need to use an index to get the value of an item. The following will give you a good idea of the syntax.
Here is is an example (taken from Google group discussion), that shows how to grab a list of values (in string format) from a http response and print them out in Loadrunner.
web_reg_save_param ("IDValues", "LB=value=\"", "RB=\"", "Ord=All", LAST);
// get number of matches
nCount = atoi(lr_eval_string("{IDValue_count}"));
for (i = 1; i <= nCount; i++) {
// create full name of a current parameter
sprintf(szParamName, "{IDValue_%d}", i);
// output a value of current parameter
lr_output_message("Value of %s: %s",szParamName, lr_eval_string(szParamName));
}
In netgend javascript, this is super easy, thanks to the simple syntax for array variable. IDValues = substring(http.replyBody, "value=\"", "\"", "all");
for (i=0; i < getSize(IDValues); i++) {
logMsg(sprintf("Value of %d is %s\n", i, IDValues[i]));
}
Note that in the above, "substring" function will grab all the strings between "value=\"" and "\"" and return a list, "IDValues" variable will hold this list.Lastly, we look at syntax related to HTTP. To access information about a HTTP transaction, Loadrunner requires you to do the following
HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE);
downloadSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
downloadTime = web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);
In netgend javascript, we can easily access the information from following variables
http.respCode
http.request
http.replyHeader
http.replyBody
http.finalRespTime : The time it took beween http request and entire http response is received.
With them, we can easily do many interesting operations, such as logging all the requests and replies when the respCode is >= 500.if (http.respCode >= 500) {
logMsg(http.request);
logMsg(http.replyHeader);
logMsg(http.replyBody);
}
There will be more to come on Loadrunner syntax vs netgend javascript. Stay tuned.