Load Testing ASP.NET Web Applications using Jmeter

People do not like slow responses on web sites. It just drives them away. If you would like to know how fast/slow your web site is when 100 or 1000 users access it, what you are attempting to is labelled ‘load testing’. There are many commercial and free tools that do the job for web applications running on Java, ASP.NET, PHP etc. We will specifically look at testing ASP.NET applications using the open source tool called Jmeter.

 


Apache JMeter is open source software, a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

 

Apache JMeter may be used to test performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types. You can use it to make a graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.

 

In fact, Jmeter can load and performance test many different server types:

 

* Web – HTTP, HTTPS
* SOAP
* Database via JDBC
* LDAP
* JMS
* Mail – POP3(S) and IMAP(S)

 

So, as mentioned above, let us look at how to load test our ASP.NET applications.

 

Let us assume that the ASP.NET web application that we are testing uses something called ‘postback’ and has enabled the ASP.NET security mechanisms of event validation and request validation.

 

In very simple terms, when ever a postback is used, the page is submitted to itself & the server sends a set of hidden variables (that are considerably long ) to the user eg. __VIEWSTATE & __EVENTVALIDATION.

 

Here are a few notes on postback requests:

 

* The current value of every control on a Web Form is contained in the postback request. This is referred to as the Post Data
* The content of the ViewState is also contained in the Post Data. ViewState holds the original property values of every control on a Web Form – before the user made any changes
* If a postback was caused, for example, by a button click, Post Data is used to identify the button that caused the postback

 

When the user submits such a page with event validation enabled, the server checks to see if it has received back the variables that it sent for eg. the __VIEWSTATE and __EVENTVALIDATION

 

So, let us see how to load test in this scenario.

 

I am leaving out basic installation & use of Jmeter as there are many articles covering it. One of the good ones with a very detailed explanation for basic testing can be found here https://www.roseindia.net/jmeter/using-jmeter.shtml

 

Open Jmeter. Add a thread group. Add a HTTP request to this thread group (Right click the thread group -> add -> sampler -> HTTP Request). Let us assume this page, let’s say login.aspx sets the viewstate and eventvalidation parameter. You need to extract the 2 parameters and pass it on as part of your next request. You need to explicitly do this when using a load test tool but obviously, when browsing the site, all this happens in the background and is taken care of by your browser.

 

To extract the viewstate and eventvalidation parameters:
1. right click on the HTTP request of the login page (the page that served you the 2 variables)
2. Add -> Post Processor -> Regular Expression Extractor

 

Fill up as follows:
Reference name: viewstate1
Regular Expression: id=”__VIEWSTATE” value=”(.+?)”
Template: $1$
Match no: 1
Default Value: False

 

What happens when you do this:
– The login page is served
– The post-processor (which aptly goes to work ‘post’ the serving of the page) goes to work and the value of __VIEWSTATE is now stored in the variable viewstate1

 

After you login, let us say there is a page ‘change password’ and you want to click on this and change your password. The viewstate parameter is to be sent to the server as part of this request. So, do the following:
– Add a HTTP request
– In the Box “Send parameters with request”, in addition to the regular POST data that you want to send, add the following
– __VIEWSTATE = ${viewstate1} where viewstate1 is the reference name set as above

 

The important thing to note is that every time a viewstate (or any other variable) is to be extracted and sent to the server, the above process has to be repeated. Let’s say you are testing the shopping cart. You define a series of requests that form the logical transaction. Along with every request in this series, you have to send the viewstate extracted in the previous request.

 

For eg. login.aspx -> extract viewstate1
select “buy 4GB pen drive” -> send viewstate1 & extract viewstate2
select “buy book” -> send viewstate2, extract viewstate3
checkout -> send viewstate3 & extract viewstate4
and so on…

 

To view the results, you can right click on the thread group -> Add -> Listener -> View Results Tree or any of the other options available for viewing results.

Comments are closed.