Java Memory Usage Monitoring Without Profiling Tools

Over the years, I have been involved in some projects involving web development in J2ee. JAVA memory usage is an issue that’s common among all.

Following are some of the questions that come across to a developer regarding the JAVA memory:

  1. Memory Usage Statistics.
  2. Trending of Memory statistics.
  3. Memory Leak.
  4. Performance optimization in case memory leaks occur.

When it comes to answering the above, the most common suggestion is to enable heap dumps and analyze it using a heap analyzer tool. However, there are times and projects where these options are not approved off and developer is always asked to review code again and again. This is again a frustrating option for all and specially for someone who has just joined a maintenance project and reading through code is not a feasible option. It has happened to me and I did the following to solve some of my problems and eventually all.

Instead of analyzing heap dumps, I decided to do the following:

  1. Add a request filter to my J2EE application. This is a standard approach where in you can define a filter for your application by configuring it in web.xml. You can do a internet search for details on this.
  2. Add following log statements in the filter:
    1.  URL fired.
    2. Runtime.getRuntime().freeMemory()
    3. Runtime.getRuntime().totalMemory()
    4. Runtime.getRuntime().maxMemory()
  3. Gather data from daily app usage and build some trending statistics.

Not only were we able to decide an optimum memory setting for our server, we were able to detect leaks as well. However, I agree detecting leaks wasn’t as simple as it’s with other tools considering the debugging effort that’s involved.It is not a conventional approach but comes in handy when projects don’t want to involve costs and maintain equilibrium at production systems as well.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>