Thursday, June 25, 2009

Load Testing ASP.NET Sites with JMeter

Following my previous post about using JMeter to test MOSS, I tried to figure out what are the bare minimum requirements of using JMeter against a plain ASP.NET website.

I wrote a very simple ASP.NET web application with just a button, a text fields and a static label. This application displays the content of a text file in the static label when it loads and write content of the text field back to the file when the button is clicked.

image

I found all I need to do in order to script this using JMeter is to extract __VIEWSTATE and __EVENTVALIDATION fields then send them back in the update request. My JMeter test plain looks like this:

image

image

image

image

Tuesday, June 23, 2009

Load Testing SharePoint (MOSS) Sites with JMeter

I have used JMeter for load testing few non-ASP.NET web sites before, however I could not get it to work with ASP.NET web sites. This is mainly due to ASP.NET ViewState and event validations, which stops a recorded JMeter script from being played back.

Recently I worked on a MOSS project and we were looking for tools to perform load testing on the server. Many people said the load testing tool in Microsoft Team System for Testers works well with MOSS. However, it is quite expensive so I decided to give JMeter another go. After several hours of hacking, I actually got it to work and here’s how I did it.

My test page is the pretty standard MOSS edit document property screen with few extra text fields added and the goal here is to use a JMeter script to change the document properties. Once I have a working script, I can configure JMeter to fire hundreds of instances of this script simultaneously to simulate the user workload.

image

As shown in the screenshot below, the test plan contains two HTTP requests recorded using the JMeter HTTP Proxy component and four JMeter Regular Expression Extractors in between them.:

image

The main trick here is to capture four key MOSS fields from the HTTP response of the “Load Edit Property From” HTTP request and send them back to the server AS IS in the “Submit Edit Property From” HTTP request along with new property values. These key fields are:

  1. __EVENTVALIDATION
  2. __VIEWSTATE
  3. __REQUESTDIGEST
  4. <control ID>_owshiddenversion 

Load Edit Property Form

The Load Edit Property Form step is a simple JMeter HTTP Sampler generated by running the JMeter HTTP Proxy component and recording the HTTP request created by click on the Edit Properties menu item in the SharePoint drop down.

 image

The response from the MOSS server will contains the four key fields that can be captured using JMeter Regular Expression Extractors.

Extract Event Validation

Regular Expression:

id="__EVENTVALIDATION" value="(.+?)"

Screenshot:

image

Extract View State

Regular Expression:

id="__VIEWSTATE" value="(.+?)"

Screenshot:

image

Extract Request Digest

Regular Expression:

id="__REQUESTDIGEST" value="(.+?)"

Screenshot:

image

Extract Hidden Version

This one is not so straight forward as the other three because the <Control ID> changes from page to page depending on the layout. It can be found by simply searching the string “owshiddenversion” in the HTML source for the edit property page. The HTML tag should look something like this:

<input id="ctl00_m_g_026c19e0_cd4b_48c9_a4b3_9e7409f252ac_ctl00_ctl02_ctl00_ctl05_ctl00_owshiddenversion" type="hidden" value="15" name="ctl00$m$g_026c19e0_cd4b_48c9_a4b3_9e7409f252ac$ctl00$ctl02$ctl00$ctl05$ctl00$owshiddenversion" />

Hence, the regular expression in this case is:

id="ctl00_m_g_026c19e0_cd4b_48c9_a4b3_9e7409f252ac_ctl00_ctl02_ctl00_ctl05_ctl00_owshiddenversion" value="(.+?)"

and the screenshot:

image

Submit Edit Property Form

The “Submit Edit Property Form” JMeter HTTP sampler is generated by recording the Submit button click using the JMeter HTTP Proxy component. JMeter displays all POST parameters contained in this request.

image

The Reference Names of the four keys fields (e.g. ${viewState} as shown in screenshot above) captured previously need to be entered into their corresponding parameter value fields. My test script also updates other parameters such as author and title for my testing purpose.

Monday, June 15, 2009

Installing VMware Server 2.0.1 on Ubuntu 9.04

I use Ubuntu on daily basis and I can live without Windows most of the time. However, once in a while I need to use Windows for things like accessing the iTunes store and editing Microsoft Word documents (yes I know OpenOffice.org works but it messes up the style from time to time). I created a WIndows VM image under VirtualBox, which worked quite well except that I noticed the constant high CPU load as mentioned by several other users. I tried their suggestions such as using nohz=off and turn off ACPI, which did reduce the CPU load to 50% on one core but didn't get rid of the problem completely.

I eventually decided to give the free VMware Server a try. Setting it up on Windows was pretty simple, just double click and then click through the Wizard. However, installing it on Ubuntu 9.04 is a non-trivial task and took me a little while to complete.
  1. Launch Synaptic package manager and make sure you have linux-header, linux-source, gcc and binutils installed.
  2. Download the .tar.gz package from VMware web site (VMware-server-2.0.1-156745.x86_64.tar.gz in my case).
  3. Extract the files then run the the installation script as super user
    sudo vmware-install.pl
  4. The installer will prompt you with half a thousand questions, I just use the default value for most of them.
  5. Eventually the installer will start compiling and loading kernel modules, most of them will go through fine but the VSOCK module installation will fail with the following error message.
    Unable to make a vsock module that can be loaded in the running kernel:
    insmod: error inserting '/tmp/vmware-config0/vsock.o': -1 Unknown symbol in module
    Ignore this insmod error for now and continue to finish the installation.
  6. Apply the following patch to vmware-config.pl, this fixes the insmod error above so we can re-run it to complete the VSOCK module installation.
    +++ /usr/bin/vmware-config-tools.pl 2008-12-01 16:55:59.000000000 +0100
    @@ -4121,6 +4121,11 @@
         return 'no';
       }
     
    +  if ($name eq 'vsock') {
    +    print wrap("VMWare config patch VSOCK!\n");
    +    system(shell_string($gHelper{'mv'}) . ' -vi ' . shell_string($build_dir . '/../Module.symvers') . ' ' . shell_string($build_dir . '/vsock-only/' ));
    +  }
    +
       print wrap('Building the ' . $name . ' module.' . "\n\n", 0);
       if (system(shell_string($gHelper{'make'}) . ' -C '
                  . shell_string($build_dir . '/' . $name . '-only')
    @@ -4143,6 +4148,12 @@
         if (try_module($name, $build_dir . '/' . $name . '.o', 0, 1)) {
           print wrap('The ' . $name . ' module loads perfectly into the running kernel.'
                      . "\n\n", 0);
    +
    +      if ($name eq 'vmci') {
    +        print wrap("VMWare config patch VMCI!\n");
    +        system(shell_string($gHelper{'cp'}) . ' -vi ' . shell_string($build_dir.'/vmci-only/Module.symvers') . ' ' . shell_string($build_dir . '/../'));
    +      } 
    +
           remove_tmp_dir($build_dir);
           return 'yes';
         }
  7. Now run the vmware-config.pl script as super user and the VSOCK module should compile and install fine now.
    sudo vmware-config.pl
  8. Now run vmware from the command prompt to launch vmware UI in your browser. You will see following error message as shown below:
  9. Click on "Add Exception", which will pop up another dialog. Click on "Get Certificate" and then "Confirm Security Exception" to add the VMware URL to the exception list.

  10. Finally, you should see the login screen. You need to login as the root user but Ubuntu does not set password for root user by default. Therefore, you first need to set the password by executing
    sudo passwd root
    after setting the password just login as root and enjoy.