GlassFish and Netbeans Profiler

Analyzing the Performance of Java EE application running on GlassFish server using Netbeans Profiler

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:

  1. Install JDK1.5 available @ http://java.sun.com/j2se/1.5.0/download.jsp

  2. 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.

  3. Install the latest and greatest Netbeans Profiler available @ http://profiler.netbeans.org/download/index.html. I used RC2.

  4. Install latest GlassFish server available @ http://glassfish.dev.java.net

  5. 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:

  • GreeterView.jsp

  • samples.ejb.stateless.simple.servlet.GreeterServlet

  • samples.ejb.stateless.simple.ejb.GreeterEJB

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>

Analyze Performance

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.


Conclusion:

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:

Comments:

Nice article. I would love to see the number of steps being reduced. I guess that must be in the minds of NB team. -- Sahoo

Posted by Sahoo on January 30, 2006 at 02:55 PM IST #

Well, I would say that this is the most complicated approach for profiling J2EE app on GlassFish that works with NetBeans Profiler.

The preferred way how to profile the app if you have appropriate project is to select this project in Select Profiling Task dialog's combo (instead of <Global Attach>) and choose Analyze CPU Performance - Entire Application (+ inclusive QuickFilter 'samples.'). This will automatically choose all application's methods as root methods, leading to all doGet()/doPost() calls and related call trees being profiled.

Moreover, if you register GlassFish in the IDE as SJSAS 8.1 PE (probably not supported, but works fine for me - NetBeans with Profiler shouldn't be installed in path containing spaces on Windows for this configuration), you can use Profile Main Project on related Web Project instead of Attach Profiler, which will start the server automatically for profiling and also selects all doGet()/doPost() as root methods.

The last important thing is to run your servlet/ejb several times before collecting reasonable profiling data. Ideally, you should invoke doGet()/doPost() 5-10 times, then reset collected results and AFTER THEN collect real data. This will avoid profiling initial servlet processing and allow possible JIT compilation that speeds up the application. As you can see on the screenshot, doGet() took almost 22secs, which is very unlikely the standard servlet's behavior.

-Jiri

Posted by Jiri Sedlacek on January 31, 2006 at 11:15 AM IST #

Hi Jiri,

I posted this writeup targeting at those audience who do not have the source code and want to analyze the performance of their application running on GlassFish. I clearly stated that in the beginning of my writeup. With that in mind and as NB Profiler stands today, I am sure what I explained is correct and there is no other easier alternative way to do profiling other than what I explained.

I know that there are various easier ways to use NetBeans Profiler when someone has a source code. I completely agree with you on that. But, one issue is Profile Main Project works only for Web Project, it does not work for a Enterprise Application/EJB Project.

If the one's intention is only to profile their application then there is no need to register GlassFish in the IDE. One can follow step (4) above. Moreover the "Attach Wizard" remembers the information provided for the first time.

I completely agree with you on the last point. Yes, to truly see the perf of an app it should be accessed several times for various reasons. It is a general guideline on analyzing any app's performance.

-Bhavani.

Posted by Bhavani on February 03, 2006 at 12:28 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

bhavani

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today