Friday, October 2, 2009

Load testing Seam application using JMeter







Here are a few links to explain the term mentioned in the title;
1. Seam - JBoss Seam -
Fairly new web framework as an answer to Ruby on Rails from the Java community. Built in support for Web 2.0 technologies like AJAX, Jquery etc.
2. JMeter -
Open Source Load testing application from Apache. Very powerful but not very user friendly, slightly higher learning curve than it should be.

If you are interested in Load Testing a Seam Framework application using JMeter and you google'd for it? You are likely to get several useful hits. This blog post is an attempt to group some of this knowledge in one place and some added finding while trying to do this.

Assumptions:

- Existing seam appliction that needs to be load tested.
- Basic knowledge of JMeter and its functionality.

Lets Begin:
Generally, load testing usingn JMeter is pretty straight forward, but when attempting to load test a web application, thinks get pretty complicated and involved. Creating the page hits manually within JMeter almost become impossible. The easiest way I found to do this is to have JMeter record your actions on a web browser while you browser the application and capture all the necessary information for you automatically.

To do this you will need to use a feature called HTTP Proxy Server in JMeter. Here is screen shot of what my proxy server looks like when it is ready with all the setting for Seam.

Follow these steps to get your HTTP Proxy Server setup correctly and recording your web app;
1. Add a Thread Group to your Test Plan and give it an appropriate name
2. Add a Recording Controller to the Thread Group you just added.
3. Add a Http Default Request to Record Controller
4. Add a Cookie Manager to the Record Controller as well
5. Add a Graphic Results or some other results viewer to the Record Controller, so that you can see the output later.
6. Now to the workbench on the bottom, add a new HTTP Proxy Server and configure it so that it looks like the image above.

Your Test Plan will look something like the image below. If it does not look exactly like it don't worry, it is possible you are on a different version of JMeter and the icons or naming convention has changed.



Time to Record:
If you followed the step thus far, you should be able to START you HTTP Proxy Server and open your browser leaving JMeter open and while you move around in your application watch the JMeter record all your actions into the Record Controller.

When you are done recording a few pages or actions, shutdown you browser and return to JMeter, now you can Stop the HTTP Proxy Server.

The recorded page will appear something like the image below. There are some extra elements in the image below that will be explained later, but general structure should be similar.

If you have made it this far, great, hang on we are almost there.

CID:
If you are working with JBoss Seam, you should be exposed the concept of a Conversation and a ConversationID (CID) for that matter. If you don't please refer to the Seam documentation, because this is out of scope for this post.

If you don't have conversations in your application, you can skip this section and move on to the ViewState section now.

You will have to go thru each record page in your Test Plan, when you find one that has a request parameter of "cid = j_id4", the page just before this one is of importance to you. Remember, the page that is right above this one, if this is X then X-1 is the one that you need, because the response of that page would have created a cid and passed it in the body.

Extraction Step: To the page X-1 add a "Regular Expression Extractor" and setup it up to look something like the image below.

This Regular Expression Extractor will extract the cid from the X-1 page response and store into a variable CID at runtime. For the rest of the page that follow this one, you will need to change "cid=j_id4" to "cid=${CID}", so that the CID is correct for the pages when the script runs during load testing. Continue this conversion until the page that does not have cid in its parameters anymore. This means that the conversation has ended and new conversation is beginning possibly. At this point, you start the 'Extraction Step' and repeat the process.

ViewState:

When I first started to create attempting to create a load test for Seam app, I was sure that CID is the only important parameter to be passed around, but boy was I wrong. Conversation or no conversation, you will still need to handle the ViewState, for your Load Test to work correctly.

You will have to go thru each record page in your Test Plan, when you find one that has a request parameter of "javax.faces.ViewState = j_id3", the page just before this one is of importance to you. Remember, the page that is right above this one, if this is X then X-1 is the one that you need, because the response of that page would have created a viewState id and passed it in the body.



Extraction Step: To the page X-1 add a "Regular Expression Extractor" and setup it up to look something like the image below.

This Regular Expression Extractor will extract the cid from the X-1 page response and store into a variable VIEWSTATE at runtime. For the rest of the page that follow this one, you will need to change "javax.faces.ViewState=j_id4" to "javax.faces.ViewState=${VIEWSTATE}", so that the VIEWSTATE is correct for the pages when the script runs during load testing. Continue this conversion until the page that does not have cid in its parameters anymore. This means that the conversation has ended and new conversation is beginning possibly. At this point, you start the 'Extraction Step' and repeat the process.

That is it:

You are done, now setup your Thread Group one user for one cycle and add a "View Result Tree" to the Record Controller, this will enable your to examine the results and all the contents of the pages when the script runs. You will want to do this just for the first run to make sure it runs thru without any problems. Once you are sure it is running without any problem, you can right click on the View Result Tree and disable it while running the script for load testing with multi users/threads.

Hey you made it! Happy Testing.

14 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Kalyan,
    I sent you a message at digitalart.org .

    ReplyDelete
  3. Hi Mustafa,

    Sorry, I have been busy with work and did not get a chance to check comments. I checked you message on digitalart I will take a look at the post again and make any modification necessary. I will try to send you a note soon.

    Kal

    ReplyDelete
  4. Hi Kalyan,

    could you please also post your .jmx file according the above test plan.


    thanks and regards,
    Hira

    ReplyDelete
  5. Hi Kalyan

    Thanks, your solution worked like a charm.

    Great post on jmeter and seam

    ReplyDelete
  6. Very nice article, you save my life :-)

    ReplyDelete
  7. Great work, saved me a bunch of time!

    ReplyDelete
  8. Great work , saved huge time for me. looking forward for some good stuff related to seam

    ReplyDelete
  9. In JMeter 2.9 there were some updates in HTTP Proxy.
    Now you can pre-configure "Excludes" patterns in jmeter.properties adding the following entry:
    proxy.excludes.suggested=.*\.js;.*\.css;.*\.swf;.*\.gif;.*\.png;.*\.jpg;.*\.bmp
    Full review will be published in JMeter blog.

    ReplyDelete
  10. This link works for me in a JSF application without seam http://wiki.apache.org/myfaces/PerformanceTestingWithJMeter

    ReplyDelete
  11. The blog is so interactive and Informative , you should write more blogs like this Ruby on rails Online Training Bangalore

    ReplyDelete