JProfiler: Your Java Code Could be Running Faster in Under Two Hours
At the end of the day, I managed to cut the execution time of some processes by 50% and more, by using JProfiler form ej-technologies.
The Performance Zone is presented by AppDynamics. Scalability and better performance are constant concerns for the developer and operations manager. Try AppDynamics' fully-featured performance tool for Java, .NET, PHP, & Node.js.
A couple of weeks ago I found myself in a position which is well known to any professional Java developer: my software was simply too slow. After tackling some obvious pain-points, I had to turn to help of a profiler. At the end of the day, I managed to cut the execution time of some processes by 50% and more, by using JProfiler form ej-technologies.
The Open Source Alternatives
As an Eclipse user and a strong OSS supporter, I first started searching for the open source alternatives. In the past, I have used the Eclipse Test & Performance Tools Platform, aka TPTP. However, TPTP is no longer an option for me since it does not support Mac OS X. TPTP is a good, solid, tool but it is not a simple one to install and use. Just to be clear: a simple tool would be a tool I can install and use without reading a manual. TPTP comes with a complex setup process.
I searched for some other free tools. I found this list of open source Java profilers and wasted about 3-4 hours running through it. None of them worked well. Most of them were buggy, some eventually worked but did not produce enough information or produced too much information, which is just as bad. Most of the tools are focused on memory analysis, while I needed execution time analysis. I had to look elsewhere.
My Experience with JProfiler
I'll start from the bottom line. JProfiler is not the prettiest tool you can find. Its' integration with Eclipse leaves much to be desired. However, it has many advantages:
- Very simple to use, compared to tools in its' class.
- Provides all the information you will desire with extensive views and predefined filters to make sure you'll get just the information you need.
- Relatively low execution overhead with many profiling options (instrumentation, sampling, etc.) and highly configurable settings.
- It displays the information while the program is running, as opposed to other tools I've used, where you have to stop the analysis to get some results.
I downloaded JProfiler and installed it using the provided installer. Like other profilers, JProfiler integrates with the IDE, supporting Eclipse and IntelliJ. In Eclipse, you use the "Profile" command, which uses the same "Launch Configurations" as the "Run" and "Debug" commands. At this point, you'll be transferred to JProfiler to start the profiling session. It took me less than half an hour to start profiling (including the download and installation), without any prior knowledge of the product and without reading any documentation. It took me another half an hour to explore all the views and understand where I can start cutting execution time. About half an hour later, I was running much faster. As I wrote earlier, about 50% faster with a couple more fixes I did that day.
Since then, I had a chance to use JProfiler on a number of occasions and it just works: profile, find the problem, fix and retest. I don't need any special preparation or setup: I just launch JProfiler using my existing launch configuration and a couple of minutes later I have the results. I even tried it on Windows, as well and it works exactly the same. You don't need to buy an additional license for that: you can remotely profile your application across the supported platforms (Windows, Mac, Linux, Solaris, AIX and HP-UX) without running JProfiler on the remote machine.
JProfiler in Action
I'm not an expert user and my experience with JProfiler is limited. I took a few screenshots to show how simple yet powerful is JProfiler. The first screen is the Session Startup, which is the first dialog you get when you launch a new profiling session.
What I like most about this window is the two lower bars that give you an estimate on how intensive this profiling session is going to be in terms of memory and CPU usage. If you change any of the profiling parameters, these bars will reflect the change. Going into the profile settings, you get an assortment of configuration options:
You can choose from predefined settings or use a custom settings. Once you select an option you'll see some explanation in the dialog itself, so there's no need to start looking for documentation. Once you get the hang of it, you can start exploring the custom options, but I found the predefined settings totally sufficient for my needs.
My focus was on execution time of a simple Java program, so the default option worked best for me. When analyzing my execution time, the most helpful tool was the "Hot Spots" view:
In this view, the most expensive calls are sorted in a descending order. You can expand the call and see which methods invoked it and, for each of those methods, what was its' share in the overall performance cost. This graph is updated every 5 seconds while the program executes.
You may also choose to see it as a call graph:
In this graph, each method gets a color according to its' contribution to the overall performance. The more expensive the call, the darker it will be. For each method you can expand the callers and methods being invoked. This makes it a good tool for identifying the critical path. All of these views can be exported to a readable HTML format, including the graphs.
It is my opinion that every professional developer should know how to profile code. I don't believe profiling is an art which should be left to dedicated performance teams (my former employer took that approach), mostly because it is the combination of knowing the code and mastering the profiling technique which yields the best results. In an ideal situation, every developer should have a profiler in his or her arsenal, ready to be launched at any given time.
Should you buy a profiler? Even if TPTP works on your platform, it is still behind the commercial tools. It seems that profilers are one of the few segments in the development tools market, where open source tools are not catching up with their commercial counterparts. It is more of a question of how you value your time. You can read my related post of the subject from one year ago: When saving a buck actually costs you more. JProfiler will simply provide the results faster.