This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java Memory Monitoring in Web Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Memory Monitoring in Web Application" Watch "Java Memory Monitoring in Web Application" New topic
Author

Java Memory Monitoring in Web Application

Tarun Trehan
Ranch Hand

Joined: Mar 16, 2012
Posts: 48

Hi All,

Request you to please review the below mentioned suggestion and provide inputs:

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

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

  • Memory Usage Statistics.
  • Trending of Memory statistics.
  • Memory Leak.
  • 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 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:

    Add a request filter to my J2EE application.
    Add following log statements in the filter:
  • URL fired.
  • Runtime.getRuntime().freeMemory()
  • Runtime.getRuntime().totalMemory()
  • Runtime.getRuntime().maxMemory()
  • 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 come sin handy when projects don't want to involve costs and maintain equilibrium at production systems as well.


    Thanks,
    Tarun Trehan (http://allzhere.in)
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39578
        
      27
    I think those stats will only give you a very cursory picture of what's going on. If that was sufficient for your purposes - great. But if you're looking for some alternative approaches, here are some options you may wish to explore:
  • JavaMonitor lets you monitor distributed servlet containers remotely
  • If you can hook up a JMX client to your JVM, then VisualVM (which comes with the JDK) lets you delve deeply into all kinds of statistics.
  • JaMon API is a combination of servlet filter (for basic monitoring) and API (for more detailed monitoring) for monitoring web apps.


  • Ping & DNS - updated with new look and Ping home screen widget
    Tarun Trehan
    Ranch Hand

    Joined: Mar 16, 2012
    Posts: 48

    Thanks for your inputs.
    I 2nd you on the inputs.

    just posted my review and process at the following link.
    The approach can come handy in typical situations.

    http://allzhere.wordpress.com/2013/02/16/java-memory-usage-monitoring-without-profiling-tools/

    Thanks again for your inputs. Appreciate it !!!
    J. Kevin Robbins
    Ranch Hand

    Joined: Dec 16, 2010
    Posts: 634
        
        7

    Psi Probe is another tool worth considering, and NetBeans has an excellent memory profiler tool.


    "There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39578
        
      27
    I'm not following - you decided not to use any of the tools I recommended? Your write-up seems to be identical to your question here.

    The numbers you get from the System class are really crude; JamonApi can do much better than that, and tallies it up for you as well.

    I second that PSI-Probe is a great tool.
    Tarun Trehan
    Ranch Hand

    Joined: Mar 16, 2012
    Posts: 48

    Hi,

    I work in IT deptt of a financial firm and see a lot of resistance to introduction of new api,etc.
    However, i went through the api and will try to implement in my local practice project that i work on.
    Appreciate your inputs...
    Thanks a lot !!!


    Regarding the post : It was just a information sharing that can be used in some scenarios.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Java Memory Monitoring in Web Application
     
    Similar Threads
    Applet with Jre1.5 will be slow after 4 hours
    Getting a heap dump
    Detecting Crashes in JBoss 4.0.2
    Garbage collection?
    Test 252: Mock exam