Random Thoughts

Raj Rajendran’s Blog

Detecting Client’s timezone in Java Web Apps

I wish I can enter it here, but keep getting errors when I try to save..

Sheesh!

May 6, 2008 Posted by Raj | Uncategorized | | No Comments Yet

Load Testing Web Applications

Last couple of days I spent on Load Testing the S2T2 application, and wanted to share my experience.

In evaluating a good load testing tool, I tried commercial products like e-Tester/e-Load, and Open source tools like JMeter, Selenium and Grinder.

Empirix e-Tester/e-Load: Too complicated, results inaccurate. (A test setup to simulate 100 users would show that a lot more than 100 sessions were created in the server)

Selenium: Great for functional testing, lacks load testing capabilities by itself

Grinder: Requires recording with Selenium, and a Python/Jython script to create load/run the test. While Python was easy to learn for the basic stuff, the level of knowledge needed to write a load testing script requires a steep learning curve.

In the end, the best choice was Apache JMeter. It is free, open-source, has great manuals, and support from user groups.

http://jakarta.apache.org/jmeter/index.html

I had tried JMeter in the past, but was it was lacking recording feature to develop a test script. Ideally, a load testing tool should be able to record the users action of logging in, performing different actions on the applications, and logging out etc. Even better would be a master script which would have sub tests with different users (with different roles) using the application. JMeter was perfect for these requirements.

An excellent tutorial to start is here:

http://jakarta.apache.org/jmeter/usermanual/jmeter_proxy_step_by_step.pdf

Now, a few gotchas on JMeter:

  • To record multiple scripts as multiple users:For each user, add a new Thread Group. (Right Click on “Test Plan”, “Add”, New Thread Group”. You can then use the proxy server to record the actions.Do the same for multiple different logins.

For the test plan, add “Listeners” (“Summary Report”, “Graph Results” etc)

You can choose the option to run Thread Groups consecutively, or all at once. I chose to run them at once.

  • If you are simulating 100 users (Threads), there is no way in JMeter to know how many threads it has created so far, while the test is executing. The top right shows how many tests are remaining but doesn’t tell how many threads have been created. You can do it programmatically in your webapp by adding a SessionListener and registering it in web.xml

import javax.servlet.http.HttpSessionEvent;

import javax.servlet.http.HttpSessionListener;

public class SessionListener implements HttpSessionListener {

private static int activeSessions = 0;

public void sessionCreated(HttpSessionEvent arg0) {

activeSessions++;

System.out.println(“NEW SESSION CREATED.”);

System.out.println(“Current # of Active Users : “ + getActiveSessions());

}

public void sessionDestroyed(HttpSessionEvent arg0) {

if(activeSessions > 0) activeSessions–;

System.out.println(“SESSION DESTROYED.”);

System.out.println(“Current # of Active Users : “ + getActiveSessions());

}

public static int getActiveSessions() {

return activeSessions;

}

}

And in web.xml

<listener>

<listener-class>com.sybase.it.class2.SessionListener</listener-class>

</listener>

Now you can see in the server log how many sessions have been created.

  • Web applications usually use cookies for session tracking. When concurrent tests are running, each for a different user, and hence a different JSESSIONID cookie, how do we make sure that this cookie is used by all the tests for the same user. The trick is to use “Cookie Manager”. After the test is recorded, the login page link would show a URL with an appended “?JESSIONID=xxxxxxx”. Because servers have no idea if the client browser has cookies enabled or not, they rely on URL rewriting to ensure Session tracking. We can take this Session ID and use Cookie Manager (Right click on Thread Group, Add -> Config Element -> Cookie Manager)

Be sure to do this for all the Thread Groups with their corresponding cookie value.

  • For JSF applications, there is another tweak needed. The JSF View State has to be passed as a request parameter in all the requests. It is a hidden input that has the name “javax.faces.ViewState” and will have a unique value for a Session. You can handle this in JMeter by RegEx Extractor. The detailed instructions on this can be found at http://wiki.apache.org/myfaces/PerformanceTestingWithJMeter
  • To monitor the hardware itself when the load test is running, there is the “top” command (/usr/global/opt/bin/top) which is really handy. The amount of memory allocated to the JVM, memory used, CPU usage etc can be obtained.
  • Another tip learnt was to keep the JVM Min Heap Size and Max Heap size the same, which would save cycles when more memory needs to be allocated to the JVM.
  • One thing that I miss in JMeter was a Response Time Vs No. Of Threads graph.

From the Graph results, we can get Average Time Vs # of Samples, but you cannot get the # of threads in that graph.

These were just scratching the surface. There is still so much that can be done with this excellent Open source tool.

May 5, 2008 Posted by Raj | JSF | , , | 2 Comments

Santosh Subramaniyam

If “Bommarillu” was dumb, this movie is DUMB. period.

Weak story line with no plot, Jayam Ravi as usual as with the nasal voice, and a shrieking Genelia. Admit it, there is no girl in real life like this one portrayed as “innocent”. The behaviour is comparable to a mentally retarded, or at best to a 6 year old. Blame Mani Rathnam who started this, with Amala’s character in Agni Natchathram, and what’s-her-name in Idhayathai Thirudaathey. The most hilarious scene is the climax, where Genelia gets to “act”.

The lesser said about the movie, the better.

May 5, 2008 Posted by Raj | Movies | | No Comments Yet