Profiling Server Applications

Profiling a Server Application

This tutorial provides a brief introduction to the AppPerfect Java Profiler product of the AppPerfect Java Profiler using a set of hands-on practice exercises. This tutorial assumes you have successfully downloaded and installed AppPerfect Profiler on your machine with the default options. Apart from this pre-requisite, this tutorial is self contained. Instructions given below are Windows-specific; if you are using a non-Windows machine, please use equivalent commands/instructions.

This document is divided into following sections

  1. Creating Project
  2. AppPerfect Java Profiler

Within each section, multiple exercises are listed. Each exercise forms a logical unit which is expected to take no more than a few minutes to perform. All exercises use the PetStore demo application running inside Apache Tomcat. The modified PetStore application and Tomcat are both bundled with this product.

All exercises assume you have installed the product in C:\AppPerfect\Profiler folder and will be referred as Profiler_HOME henceforth in tutorial. If you have installed the product in some other folder, modify the instructions below appropriately.

This tutorial is not intended as a comprehensive training guide. Please refer to the product documentation for detailed information. However, this tutorial will give you a very good overview of the products and substantially improve your productivity with the product.

Creating Project
Exercise 1: Launch AppPerfect Java Profiler
  1. Click on Start -> Programs ->AppPerfect Profiler x.x.x -> AppPerfect Java Profiler
  2. On launching AppPerfect Java Profiler a Welcome page will be displayed. Go through the brief description given for product.
    NB: Welcome page is displayed only when Profiler x.x.x is launched and last time no project was opened.
Exercise 2: Creating a Project
  1. Launch the Project Wizard by clicking File ->New... menu option. The New Project wizard will be launched.
  2. Go through the instruction provided on top of the General tab.
  3. Keep the default project name and location for the purpose of this exercise. We don't have to provide "Notification" settings or "Target Application's Machine" settings for this exercise. Click on the Next button.
  4. We dont have to import any existing project so click Next on Import Tab.
  5. In the Source tab click on the "Add File" button on the r.h.s., select "Files of type:" as *.jsp in the Open dialog and add jsp files from the location "Profiler_HOME\tomcat\webapps\petstore"
  6. Now click on the "Add Folder" button on the r.h.s. and select the folder "Profiler_HOME\tomcat\webapps\petstore\src". Click the Next button.
  7. Use the default JDK which is bundled with AppPerfect Java Profiler and click on the Next button.
  8. In the "Environment" tab we will provide the classpath for the sources added in the project.
  9. Click on the "Add File" button on the r.h.s. and navigate to the location - "Profiler_HOME\tomcat\webapps\petstore\WEB-INF\lib" - select all the jars present in the "lib" folder.
  10. Click on the "Add File" button on the r.h.s. and navigate to the location - "Profiler_HOME\tomcat\lib" - select "ant.jar", "el-api.jar", "jsp-api.jar" and "servlet-api.jar" jars and add them to classpath.
  11. Click on "Verify Classpath" button to validate the classpath.
  12. Classpath validation dialog will be launched and the classpath will be verified. A message saying that the classpath specified is correct should be displayed. Click on the "OK" button. Click on the Next button.
  13. In the "Target" tab select "Target Application type" as "Server/ Web Application".
  14. Keep the default URL in the "Starting URL" field i.e., "http://localhost:8384/petstore". Select the "AppServer Settings" tab.
  15. Select the "Specify AppServer Settings" checkbox and select "Tomcat_5.x/6.x" from the drop down menu.
  16. Specify the Server Home path - "Profiler_HOME\tomcat" and the "Startup file" for the server - "Profiler_HOME\tomcat\bin\catalina.bat".
  17. Select the "Launch server automatically (When required)" checkbox. Click on the Finish button.
  18. If applications asks for Starting URL validation, click on 'No' button. Normally Confirmation for Starting URL validation is not asked when "Launch server automatically (When required)" is checked. A confirmation message saying that the project is saved will be displayed. Click on the OK button.

Now using this Project we will create tests to demonstrate the functionalities of AppPerfect Java Profilfer product.

AppPerfect Java Profiler

NB:Please follow the steps provided in the "Creating Project" section to first create a Project, then proceed further.

Exercise 1: Define a Java Profiler project
  1. Once the Project is successfully created another dialog - Define Project Properties dialog - will be displayed.
  2. Read the instructions at top of each tab.
  3. Go through the descriptions for Profiling Types. Keep the default Development Mode Profiling and select Profiling Options tab.
  4. Study the descriptions of the three profiling options. You can configure Filters using Customize Filters... option. Use default values.
  5. Study the descriptions of Instrumentation Options. Use the default: Dynamic Instrumentation enabled.
  6. Study the changes indicated in the Launch Instructions tab. AppPerfect Java Profiler must modify your application server's startup file to add instructions to load the profiling agent, etc. This tab shows the exact changes that needs to be made to the startup script. AppPerfect Java Profiler understands how to configure startup scripts for most commonly available application servers. Also, since it does not modify the original file and instead makes a copy to store the modifications, it is almost always desirable to let AppPerfect Java Profiler make the changes. Click OK button.
  7. Click through all the menu items to familiarize yourself with the available features and how to access them. Viewing through all menu items will provide a reasonable overview of the application.
  8. Click on Tools ->Options... menu item. Click on the "Browsers, JDKs & DBs" node and ensure that the JDK path has been set correctly. This is the path provided for JDK during installation of AppPerfect Java Profiler. You may modify the path or add new JDK through this dialog box. It is critical that a correct version of JDK is available for AppPerfect Java Profiler to perform correctly.
  9. Click Help -> Table of Contents menu item to see AppPerfect Java Profiler product documentation.
Exercise 2: Start Profiling
  1. To start profiling click on Project -> Run from the menubar.
  2. A message will be displayed confirming that a modified appserver startup file called catalina_AppPerfect.bat has been created.
  3. This will launch Tomcat with PetStore running. The status of Tomcat startup could be seen in the Server Console window. Once Tomcat is fully started and available for servicing requests, you will see a message similar to: "INFO: Server startup in XXX ms" where XXX will be a number.
  4. Observe the dynamic updation of data in the default Project Summary view. You can see various profiling metrics such as heap memory usage, object instance count and Thread count.
Exercise 3: Memory Profiling
  1. AppPerfect Java Profiler provides detailed information about the profiled JVM's heap memory. Since memory allocation/de-allocation is a key determinant of performance, understanding the heap memory composition and behavior is critical in designing high performance Java applications.
  2. Click on Memory Profiling to view summary of Memory Profiling
  3. Click on Memory->  Garbage Collection node in the tree on the left. Four charts are displayed showing details on each call to the Garbage Collector. For additional details on GC, click on the GC Details tab at the top of the screen.
  4. Click on Memory ->Class-wise Allocation node in the tree on the left. A tree-table with all the packages/classes loaded will be displayed. Double clicking on a Package or a class will take you to the Allocations Tree tab which will show you allocation tree of selected class. Expand the tree to needed depth to see the allocation hierarchy.
  5. Click on Memory ->Method-wise Allocations node. Method-wise Allocations shows details of methods where allocations of objects has happened, here you can get details of what all classes were instantiated from a particular method. This is useful to find method where max allocation is happening.
Exercise 4: CPU Profiling
  1. CPU Profiling helps you understand the breakdown of how time is used by the CPU when an action is processed
  2. Click on CPU Profiling node to view CPU Profiling summary.
  3. Click on CPU -> Method Details node in the tree on the left. A table is displayed with details on all classes and their methods, including the number of invocations, CPU time consumed, etc. At the bottom you can see incoming and outgoing invocation trees with respect to selected method. You can filter view to see hotspot methods by providing desired hotspot threshold value. Here methods that take more than the "Threshold Value", as specified when the project was created, are displayed. Hotspot views are very helpful in identifying classes and methods that take the bulk of the processing time.
  4. Click on CPU ->Invocation Tree node in the tree on the left. The view might take a few moments to refresh or click on the Refresh button on l.h.s top. Once refreshed, you will see a tree table with each thread displayed along with the time it took. Expand the node "Thread - main" to view details on how your application's processing breaks down for CPU usage.
Exercise 5: Thread Profiling
  1. The process of identifying, monitoring and debugging issues related to the various threads in your multi-threaded application is called Thread Profiling.
  2. Click on Threads Profiling node to view thread profiling summary.
  3. Click on Thread Profiling-> Threads node in the tree on the left. A chart displaying the state of each thread started by the target application are displayed. Note that the left edge of each bar represents the start time of the application and right edge represents the current time. During this time, the state of any of the threads may have changed. This view helps graphically identify any threads that may be blocked or waiting.
  4. Click on Status tab in the Threads view. This table displays the current status and other information about each thread. If there are too many threads, you may sort the data based on any of the columns.
  5. Click on Thread Profiling-> Monitors node in the tree on the left. A monitor is a resource (an object, system resource, etc.) which two are more threads attempt to access concurrently. Concurrent access forces all the other threads except for one accessing the monitor to wait for the monitor. This view details all such monitors and details about them. Higher the monitor contention rate, the more likely your application is not properly multithreaded and will perform poorly.
  6. Click on Thread Profiling-> Deadlocks node in the tree on the left. Click on the Detect Dead Lock button on the r.h.s. If a deadlock condition was detected (a cyclical waiting of two or more threads), it would be graphically displayed in this view.
Exercise 6: Detecting Memory Leaks
  1. Detecting memory leaks is a key function of the AppPerfect Java Profiler. A memory leak is defined as an application error in which objects that were thought to have been disposed are not disposed because of a reference to that object from somewhere in the application. Over time, if such objects continue being created without getting garbage collected, they will grow to consume all available memory, leading to application shutdown. Memory leak detection requires significant knowledge of the underlying application being profiled.
  2. Start a browser and connect to the PetStore application (http://localhost:8384/petstore). Click on "enter the store".
  3. Select "Memory Leaks" node in the l.h.s. tree and click on "Start Scenario..." button.
  4. AppPerfect Java Profiler will force a Garbage Collection and register all live objects present in memory after the GC.
  5. A message asking to execute the test scenario in your application will be displayed. Click on the OK button.
  6. Now go through the action of ordering "Adult Amazon Parrot". Check out, and then log out. Close the browser.
  7. Click on "Stop Scenario" button.
  8. A message will be displayed informing that Memory leak detection scenario has been completed and do you want to take a heap snapshot to view the allocations and reference details of the reported leak objects. Click on the Yes button.
  9. Now the focus will move to Heap Browser node. A dialog will be displayed asking whether you want to view details for any specific class. For the sake of this exercise will not specify any particular class. Click on the OK button to take snapshot. This will take a few seconds.
  10. As soon as the snapshot is taken, the 'Packages' tab will be in view. Double click on a Class to view "Allocation Tree" view. Expand the tree to needed depth to see the allocation hierarchy. Further details such as each instance of the class can be obtained by right-clicking on a class and selecting the option "Show Object Instances" or by selecting the tab Object Instances.
Library z-lib
We use cookies for analytics, advertising and to improve our site. By continuing to use our site, you accept to our Privacy policy and allow us to store cookies.