Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |
Tools: | GC log analysers| Multi-tenancy tools| Books| SizeOf| Thread analysers|

Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks! 

Tool Report: Enterprise Application Profiler in Sun's Java Studio Enterprise

JProfiler
Get rid of your performance problems and memory leaks!


Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:



JProfiler
Get rid of your performance problems and memory leaks!


Published January 2006

The JavaPerformanceTuning.com Tool Reports are designed to help readers make informed choices about the tools they may wish to use. JavaPerformanceTuning.com provides these reports as a service to our readers; JavaPerformanceTuning.com is not responsible for the information provided by the tool author or vendor, nor do we necessarily endorse the products mentioned. JavaPerformanceTuning.com is not responsible for any additional resources provided from the article (such as downloadable files or other accessible material), even where we host such material.

Introduction

The Enterprise Application Profiler is a feature in Sun's Java Studio Enterprise. It provides developers functionality that addresses their critical design-time performance tuning requirements. You can use this profiler to analyze applications that you develop with Sun Java Studio Enterprise (IDE - Integrated Development Environment) and deploy to the Sun Java Application Server. Using the Enterprise Application Profiler, you can observe component level performance for the Java Enterprise System. You can also selectively profile the methods that are included in the applications deployed in the Sun Java Application Server container. There is a load generator that is included with the IDE. Using this you can generate load on a system and observe the performance profile of a loaded system.

This paper provides an introduction to the Enterprise Application Profiler (Profiler for short) and describes its capabilities.

Downloading and Installing Java Studio Enterprise 8

  1. Download the IDE for your platform from the Java Studio Enterprise home page.
  2. Launch the downloaded installer
  3. Proceed through the steps of the installer to install the IDE
  4. Start the IDE

Getting Started

You need to enable the Profiler collector first. To enable Profiler collection, ensure that the Enterprise Application is set as the Main Project within the IDE (indicated by a bold label in the IDE's Explorer). If it is not set as the Main Project, right-click the application's project in the Explorer and select "Set Main Project".

Using the menu to set a project as the Main Project
Figure 1: Setting a project as the Main Project

Next, click the "Run" menu and select "Profile -> Enable Collection". If the items in the Profile menu are disabled, the main project is either not set or the project is not an Enterprise Application.

Enabling Profiler Collection on the Main Project
Figure 2: Enabling Profiler Collection on the Main Project

By enabling profiler collection, a bytecode-preprocessor tag gets added to the Application Server Instance's configuration file ("domain.xml"). This also adds the necessary classpath information and adds filters to the Web application's configuration file ("web.xml").

To disable collection, click the "Run" menu and select "Profile -> Disable Collection".

Launching the Profiler from the IDE

Launch the Profiler from the IDE by choosing "Profile-> Open Profiler" from the "Run" menu. The IDE displays the Profiler pane.

Components used by the Profiler

The Profiler contains four major components that work together to obtain performance data for applications deployed on the Application Server:

You invoke each of these components through the tabs at the bottom of the Profiler screens. The Profiler tools are invoked through the icons at the upper left of the Profiler screens.

The next four sections examine the component tabs and show you how to use the components to analyze performance.

HTTP Transactions Component

The HTTP Transactions component performs two important tasks:

When you use this component, you can trace an HTTP request in its entirety. You can then save, record, replay, or edit the request or transaction by modifying certain parameters and replaying the request.

The graphical overview of Java Enterprise System that is presented here contains the following elements.

HTTP overview panel showing transactions that consume large amounts of resources
Figure 3: HTTP overview panel showing transactions that consume large amounts of resources

The left pane in Figure 3 displays all HTTP transactions in chronological order. The chart on the right pane shows an overview of time spent in various types of transactions.

To examine the details of a specific transaction, select the transaction in the Current Records tree on the left panel. This highlights the corresponding row in the Runtimes Table.

HTTP Transactions sorted by execution time
Figure 4: HTTP Transactions sorted by execution time

In Figure 4, the table on the right lists the wall clock time for the execution of each transaction. You can sort this table using one of three metrics:

You can save, modify, and replay these transactions. To perform any of these functions, right-click on the transaction in the left pane and choose the appropriate function.

You can obtain additional details about a transaction that is highlighted by choosing the corresponding tab at the bottom of the right panel. These details include request, cookies, session, context, client and server, and headers information.

Using the Load Generator

You initiate load generation by choosing the Load icon from any of the Profiler panels (except the Memory panel). The Profiler performs load generation by using an internal HTTP client capable of generating HTTP and HTTPS traffic.

HTTP requests from the created agenda are fed back to the server until you stop load generation by choosing the Stop icon.

To initiate load generation, supply two input parameters to the Load Generator:

The Profiler automatically creates a Load Generation agenda when you choose the Load button. You can also create the agenda by copying all the records from the Current Records folder into the agenda.

EJB Container Statistics Component

The EJB Container Statistics component gathers performance statistics at various levels of an application's structure. The EJB Container Statistics component specifically performs the following tasks:

To access the EJB Container Statistics component and its panel, select the EJB Container Statistics tab in the Profiler. See the example in Figure 5.

In Figure 5, the tree in the left panel represents the available statistics from the container. Right-clicking any node in this tree and choosing View creates a panel showing the statistics for that node.

The charts on the right panel show the system usage by execution time and call counts. They provide a high-level view of system performance.

EJB Container Overview
Figure 5: EJB Container Overview

You can also choose to watch a specific node, referred to as “adding a watch to a node.” By adding a watch to a node, you set its individual refresh rate. The Profiler refreshes all the nodes globally according to the initial setting defined in the connection dialog box. When a watch is set on a node (thus changing the refresh rate) all children of that node inherit the new refresh period.

Methods Component

The Methods component provides the application's view of the data at the method level. You can use the Methods component in conjunction with your analysis of transactions and load-testing or you can use it by itself. Using method-level profiling, you can do the following:

Methods panel with method data in a Tree format
Figure 6: Methods panel with method data in a Tree format

The left pane holds a data tree that displays the deployed applications from which you select an application for profiling. The right pane displays performance data in a Tree format sorted by wall clock time.

Instrumenting Methods
When the Methods tab is first selected, it appears with the deployment tree on the left panel. Expanding this tree displays the applications deployed in the Application Server instance for which the profiler is collecting data. To specify the methods to examine - also referred to as “instrumenting” selected methods, select the Instrumentation button (indicated by a red check mark). This action brings up a writable copy of the deployment tree. After selecting the methods to instrument, select OK. Note that if a node in the deployment tree is selected for instrumentation, the children of that node are also selected. You have the option to deselect the child nodes. This selective instrumentation is unique to this Profiler. Selective instrumentation reduces profiler overhead and thus leads to more accurate results.

Writable deployment tree to select methods for instrumentation
Figure 7 is an example of a writable deployment tree from which you can select methods.

Figure 7: Writable deployment tree to select methods for instrumentation

Generating Method-Level Performance Data
Once you have completed method and application selection for performance profiling, you can generate method-level performance data by one of two methods:

The performance data is displayed in a table by default. It can also be viewed as a tree, or in a call graph. Figure 8 shows the performance data in tabular form. If the source code is available, double-clicking on a row shows the source. You can also right-click on the method name and select "Warp to Source".

Methods Panel with Execution Times table
Figure8: Methods Panel with Execution Times table

The Call Stack Graphical representation of this performance data is shown in Figure 9. If the application were complicated, the entire call stack would fit on one screen. This is important to determine the accuracy of the call stack.

Methods Panel with a Call Stack
Figure 9: Methods Panel with a Call Stack

Memory Monitor Component

The data for the Memory Monitor is extracted from the Application Server and sent to the Profiler – which is run on a different Java Virtual Machine. As a result, you must allow initialization time (of a few seconds) for the Memory Monitor before the plot shows correct data.

The Memory Monitor component measures the maximum allocable, free, and used memory in the Application Server. It correlates these values to inform you when memory limitations are being reached. The Memory Monitor component probes the Application Server for memory data and displays it over time.

You access the Memory Monitor component by choosing the "Memory" tab in the Profiler. The Memory Monitor panel is shown in FIGURE 10.

Memory Monitor panel that shows the HEAP usage of the JVM that controls the Application Server
Figure 10: Memory Monitor panel that shows the HEAP usage of the JVM that controls the Application Server

From this panel, you can select the Run Garbage Collection button to enable the Application Server to perform garbage collection and thus free necessary memory resources.

Profiling a Sample Application

Let us now follow a complete example of profiling and tuning a sample application, "Speed Reader. Through this example, you will learn how to:

Follow these steps to use the "SpeedReader Demo.

  1. Download and install Java Studio Enterprise 8 from the Sun Download Center, or install it from your CD.
  2. Download "SpeedReaderDemo from the Sun Java Studio Enterprise Developer Resource site (provided in the Referenced section). Extract the demo from its zip file into a location you specify with the $DEMO_HOME variable on your machine.
  3. Start the Java Studio Enterprise 8 IDE.
  4. Open the "SpeedReader Project.
  5. Set the "SpeedReader project as the main project. Note that the IDE might already have set the "SpeedReader Project as the Main Project, (as indicated by a label in bold in the IDE)

Open the SpeedReaderDemo project and set it as the Main project
Figure 11: Open the SpeedReaderDemo project and set it as the Main project

  1. Enable Profiler collection by choosing "Run -> "Profile -> Enable Collection. A dialog appears informing you that the next time you deploy or run the application, the Application Server will restart.
  2. Deploy "SpeedReader to the Application Server.
  3. Open the Profiler feature in the IDE, by choosing "Run -> Profile -> Open Profiler command. A message on the right panel of the Profiler states that the SpeedReader Demo has not generated any transactions. If you get a message saying that the Application Server is not running, you can check the Application Server's status from the Runtime tab in the main IDE Explorer panel, and restart the Application Server.
  4. If the Application Server is running properly, you can run the SpeedReader Demo. To run the Demo, select appropriate fields in the SpeedReader application. For demo purposes, do not select the "Finish button on the last page at this time.
  5. Examine the results obtained by running the SpeedReader Demo on the HTTP Transactions Panel. The Overview panel provides a snapshot of HTTP traffic.
  6. Choose the Runtimes Table in the HTTP Transactions Panel. Notice that the "TextProcessServlet dominates execution time. You can also examine the data provided in the Per Transaction Details panel.
  7. Now choose the EJB Container Stats Panel. If the right chart panel does not contain two pie charts that provide an overview of the container's performance, choose the "Update EJB Tree button on the upper left corner.
  8. Expand the "Applications tree; right-click "TextProcessBean and select "View. Details of the EJB appear in the data panel. Notice that all program execution is occurring in the business method "getNextLine.
  9. Now choose the Methods panel. Expand the "Applications tree to view the deployment structure of applications in the Application Server. This tree is read-only.
  10. Select the Instrumentation (red check mark) button to display a copy of the deployment tree. Choose the methods you want to examine. For the purposes of this example, choose all displayed methods by checking the top level node in the deployment tree and select "OK.
  11. Select the "Load button located on the right above the tree in the Methods Panel to load the application methods with the Load Generator. Wait one minute, and choose the "Stop button.
  12. Choose the "Get Method Trace button to display the method data in the Profiler.
  13. Examine the data panels. Notice that the bulk of time is spent in the "processRequest method in "TextProcessServlet.
  14. Save the Methods Tree to establish a base for providing a comparison after you finish tuning the application.
  15. On the Execution Times Table, double click on "TextProcessServlet.processRequest(...) to examine the source.
  16. Find the call in this "processRequest method that calls "getNextLine("int). This is a business method of "TextProcessBean.
  17. Find the call to "getNextLine("int) by pressing control-click on the "getNextLine method.
  18. Right-click the interface class name ("TextProcessLocalBusiness) and select "Find Usages. A panel appears at the bottom of the screen with the places in the code where this interface is named. Double-click on the implementation of this interface to obtain the source.
  19. Use the navigation panel or scroll down, find the "getNextLine("int) method.
  20. The call to "worseMethod is in the "getNextLine method. You can see that the method is doing I/O in an expensive way. This is the reason the application is performing poorly.
  21. Change this call to "betterMethod by commenting the "worseMethod and uncommenting "betterMethod.
  22. Compile the SpeedReader Project by right-clicking the SpeedReader Project node and choose "Clean and Build Project.
  23. Deploy the SpeedReader Project by right-clicking the SpeedReader Project node and choosing "Deploy.
  24. Use the Load Generator to generate a load on the Application Server.
  25. After stopping the load generator, examine the data. Notice a marked improvement in the application's performance.

References

The following product pages offer a wealth of additional developer-oriented resources:

Conclusion

In this article, you learned how to use the Enterprise Application Profiler in Sun's Java Studio Enterprise 8 to address critical design-time performance tuning requirements. You also saw this in action through an example code. Note that there is a separate Java Profiler available as a plugin to the NetBeans IDE. This lets you track thread state, CPU performance and memory usage of a Java application. There is a separate article on the NetBeans Profiler that is available.

About the Author

Prakash Narayan has worked at Sun Microsystems for over 15 years. He initially worked in the area of high performance computing, and he now devotes his time to enterprise Java. He is currently a senior engineering manager in the Sun Java Studio Enterprise team with responsibility for components in the life cycle of enterprise application development.


Last Updated: 2017-11-28
Copyright © 2000-2017 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/tools/EAProfiler/index.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us