GlassFish and Netbeans Profiler
By bhavani on Jan 30, 2006
Analyzing the Performance of Java EE application running on GlassFish server using Netbeans Profiler
This blog explains how to profile a Java EE application running on GlassFish server using Netbeans Profiler. To profile an application in the way I explained in this blog there is no need to have the source code of the application. The only requirement is that the Java EE application that is intended to be profiled should have been compiled with -g option.
Setting up the environment:
Install JDK1.5 available @ http://java.sun.com/j2se/1.5.0/download.jsp
Install Netbeans Platform 5.0 (either nightly or latest RC or Java EE version of it) available @ http://www.netbeans.org/downloads/index.html. I used Netbeans 5.0 RC2 for my experiment.
Install the latest and greatest Netbeans Profiler available @ http://profiler.netbeans.org/download/index.html. I used RC2.
Install latest GlassFish server available @ http://glassfish.dev.java.net
Deploy your Java EE application on GlassFish server. Make sure your application was compiled with -g option so that all the debug information are generated. Profiler makes use of these debug informations.
Brief description of the application we are profiling:
The sample application is a stateless session bean which comes bundled as part of SJSAS samples. The application has the following main components:
This is how the application works : When the application is accessed, GreeterView.jsp brings up a form wherein one can enter the name and click “Process” button. On clicking the “Process” button the form posts the name to GreeterServlet. GreeterServlet invokes GreeterEJB's getGreeting() method and a personalized greeting returned from the EJB is presented to the user.
Steps for profiling the application:
1. Start Netbeans
2. Select Profiler > Attach Profiler. This opens up "Selecting Profiling Task" window.
3. In "Selecting Profiling Task" window specify the the values as appropriate. Here are the values for my sample.
Project : <Global Attach>
Part of Application > Select > Add Manual
Class Name : samples.ejb.stateless.simple.servlet.GreeterServlet
Method Name : doPost
Method VM Signature : (Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V
Note : This adds GreeterServlet's doPost(....) method as a root method. If the application has some more servlets then all the servlet's doGet/doPost methods should be added as the "Selected Root Methods". Profiler shows only the call stack starting from the root method(s) you specify here.
Filter > Quick Filter
Filter type : Inclusive
Filter value : samples
Note : With this filter, the call stack will include only the methods of the classes belonging to the package samples.\*\*.
4. In "Selecting Profiling Task" window click "Attach Wizard". Specify the appropriate values in the wizard. For the GlassFish server I am using here are the values:
Target Type : J2EE Web/App Server (or Java EE Server)
Server Type : Sun Application Server 8.1 PE (or GlassFish)
Select Server Location : Local
Select Attach Method : Direct
Choose automatic or manual integration : Automatic
SunAS Installation : GlassFish installation basedir
Domain : domain1 (auto detected when you specify SunAS Installation dir)
Server VM : JDK 1.5 (Default)
Before you click "Finish" button select "Automatically start the server after the wizard finishes"
When you click "Finish" button, it brings up a 'asadmin' window. Watch the messages on this window. When there is "Profiler Agent : Waiting for connection on port 5140 (Protocol Version : 2)" message on this window, proceed to next step.
5. In "Selecting Profiling Task" window click "Attach" button. Now the Profiler gets attached to the profiler agent running on GlassFish server. Wait for "Application server startup complete." message on 'asadmin' window before proceeding to next step.
6. Access your Java EE application. In my case I access http://localhost:8080/helloworld using Firefox and type my name on the form and click "Process" button and wait for the greeting.
7. We are done with profiling the application. Now, to see the results click on "Take Snapshot" on Profiler window. In my case, this is what I can see:
Needless to mention, the profiler window clearly shows CPU usage of the application's individual methods. One can clearly see the callflow and the methods which have performance bottlenecks.
Netbeans Profiler with its performance, usability, light weight and small memory footprint along with very light weight GlassFish server is the good combination to profile an enterprise Java EE application.
In my experiment I used a very small subset of Netbeans Profiler's features. A lot more stuff such as memory usage patterns, thread management, GC characteristics, etc, etc... can be analyzed using the Netbeans Profiler. More detailed documentations on Netbeans Profiler are here.
Technorati Tags: glassfish