TS-9555: Quick and Easy Profiling with Integrated Tools
Threading issues (having too many or not enough threads, or having threads waiting too long), slow performance (developers are often surprised to find where most of the CPU time is actually spent), and memory leaks (the application crashes because it runs out of heap space) are typical problems which can be solved by using a profiler during production. NetBeans IDE engineers Jiri Sedlacek and Jaroslav Bachorik, and NetBeans evangelist Gregg Sporar talked about what additional advantages you gain from a profiler that is well-integrated into your IDE.
What makes an integrated profiler easier to use than an external one? When the Profiler is part of the IDE, the project structure is already known to the IDE, and you do not have to bother with starting another tool and setting it up. Developers also often need to test applications which display performance problems only under certain circumstances. Running a profiler generally slows down the application's execution, and the live results collected can be very extensive and thus hard to read. This happens when too many methods are being watched.
If, however, you know that you want to profile only a particular subset of methods, the NetBeans Profiler now allows you to only instrument interesting methods. The profiled application is unencumbered and runs with normal speed, the results are more concise, and much easier to read. When a result grabs your attention, you can jump directly to the corresponding line in the source code to investigate further.
Apart from selecting a subset of code to profile, you can monitor an application's active and waiting threads. You can switch to CPU usage profiling in order to see hot spots and the call tree in context. You can analyze code fragment performance and determine the time spend in a method. You can monitor memory usage by recording object creation and lifecycle. These predefined tasks cover the majority of usecases -- if you need more control, the Profiler also allows for custom profiling. You get all that for Java SE as well as Java EE applications without extra configuration.
Sporar announced that for the 6.0 release of NetBeans IDE, the Profiler add-on pack will disappear. Instead, the Profiler will be part of the standard download. The NetBeans Profiler 6.0 will include new features, such as profiling points (e.g. "reset results" and "make snapshot" Profiling Points can be placed into sourcecode like breakpoints, allowing you to save and compare snapshots over time), a jMeter load generator, heap walking and identification of the nearest GC root, areas of interest (a project type specific high-level overview), and dynamic attachment (allowing to profile the application without restarting, e.g. on production environment).
Sporar told the audience how he once tried to fix a web application that had grown until a major leak occurred in the live production system. Since the problem was seemingly random and hard to reproduce, the only workaround was to increase the heap-space -- which of course didn't fix the problem. An analysis of live results gathered by the NetBeans Profiler finally showed a conspicuous trend in one kind of object's object generation count. By gaining insight into the application's actual runtime behavior, the cause of the leak was detected in a forgotten background process, and fixed.
There was also a blogger web application that was successfully optimized using the NetBeans Profiler. Instrumentation was restricted to only one JSP page that was suspected of being the root cause. The load generator was used to simulate the creation of blog entries, while the engineers kept an eye on the performance hot spots. Since the algorithm used in the guilty method could not be sped up, the engineers instead decided to lower the number of invocations of this method. A comparison of old and new snapshots showed that the optimized version of the code indeed ran twice as fast as the original.
In the following QA segment it was made clear that the NetBeans Profiler only watches Java methods (including session and entity beans), but no native methods. Another user was glad to learn that although JDK 1.4.2 is not supported, a special JVM exists for profiling purposes. For Eclipse users it is interesting to hear that they can import an Eclipse project into NetBeans to take advantage of the NetBeans Profiler; alternatively, the NetBeans Profiler can be attached to the running Eclipse-created application (a few features like jumping to the source will not be available then). Also, if your application comes with a custom build.xml file, no worries, there is a tutorial showing how to add a custom ant target to integrate the Profiler.
Learn more on http://profiler.netbeans.org, and read the article about memory leaks in the Software Test & Performance magazine (PDF).
|