Life, code and stuff
Posted by Marc Sturlese

31 May 09 Performance measurement with JMeter 2.3.3

Last week was launched a new release of JMeter. JMeter 2.3.3 is a powerful java application designed to do web application functionality testing and performance measurement, allowing you to do powerful server stress tests.
I have been doing some practices with it and I really liked the easy way you can set up a test plan and start stressing your machines to check response times when lot’s of threads are doing requests.

You just need to create a .jmx file wich will contain all the information needed to do the requests. Host name, port number, protocol, method, url path, url variables… You can actually tell JMeter to read the url variables from an external .dat file. It will allow you to give different values to the variables for each request.
The .jmx can be written manually but it’s much easier to create it via the JMeter’s GUI.

You will have to tell JMeter the number of threads that must be executing requests and the number of requests per thread. It allows you to leave the threads making requests indefinitely.
Once a test is launched you can see in real time the number of samples that have been executed and the Deviation, Throughput, Average and Median of the requests done by the threads (think of a thread as a user doing a request via browser).

This is just how to do a basic test plan but the application is really more complete than this and has much more interesting features.

Tags: , ,

Posted by Marc Sturlese

09 May 09 Analyzing java heaps with jmap and jhat

Jmap and jhat are a couple of tools really useful to analyze the memory consume of a java program. Both are included in the JVM 1.6 so there is no need to install any extra stuff.

Jmap allows you to create a dump of the java memory heap at any moment in the life of your running application. It will contain all the live objects and classes at that moment. To create the heap dump it’s as easy as:

jmap -dump:file=my_stack.bin 4365

Where my_stack.bin is the name of the file where you want the dump and 4365 is the pid of the java application process.

If you are running a servlet application under a java server and it ends with a:

java.lang.OutOfMemoryError: Java heap space

You can trigger a dump of the java heap at the OutOfMemory moment specifying these parameters to the server:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/sturlese/stack_test/

This will create a .hprof file (named with the pid’s process) containing the dump in the specified path.
HeapDumpPath param is not compulsory. If we don’t specify it the dump will be created in the folder where Tomcat launches the webapps.

Now we have the dump of the java heap. To analyze it we will use jhat. Once we launch jhat specifying the dump to analyze it will start an HTTP server (in the port 7000 by default) and will let you surf along all the classes and objects. You will be able to check how many instances of each class where alive in the moment the heap was created. To launch jhat:

jhat my_stack.bin

It’s easy to get an OutOfMememory exception when opening the java heap. The dump file can be very memory consuming if you app was in the moment it was taken. If you experience the problem you should give to the JVM as much memory as you can:

jhat -J-mx2000m my_stack.bin

Now is the moment to point your web browser to http://localhost:7000 and start analyzing the heap!

Tags: , , ,