JVM Profiling Disclosures

May 2013 · 4 minute read

Well, I’ve never actually given importance to the term ”profiling” till a few days ago. The real deal was that I was just too lazy to actually run a profiler and then to try interpret the stats and hopefully find the bottleneck in the code. So to avoid all this hassle, I tried to be careful while writing code to make sure I don’t leave any open doors for memory leaks or poor CPU utilization.

But a few days back, I stumbled into a performance issue in my code at work, leaving both me and my project lead puzzled about the culprit. Atlast desperation lead us to setup YourKit profiling in our server to have a peak under the hood of the JVM. And in the process, we happened to learn some new terms and functionalities of the profiler and I must say that I’m slowly beginning to like the idea of profiling code. I was really surprised at what we could learn about our code just by looking at the profiler stats. So here below, I’ve merged in some of our learnings along the whole process.

JVM Memory Structure

It’s important to first understand the structure of the JVM memory itself. Simply put:

JVM Memory = Heap Memory + Non-Heap Memory + Other

Other: (JVM code itself, JVM internal structures, loaded profiler agent code and data, etc.)

Profiling Terms

Next, lets look at a few terms you need to know in order to make some sense out of all those weird graphs.

Things to watch out for while profiling

From the above, you probably should understand most of the important stats, when you look into your profiler output next time. Now comes the important question:

How do I generally find/prevent bottlenecks in my code

I’ve tried to provide a few ideas below:

This should help out.

comments powered by Disqus