This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Profiler hell Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Profiler hell" Watch "Profiler hell" New topic
Author

Profiler hell

Manny Garcia
Greenhorn

Joined: Apr 04, 2007
Posts: 28
Howdy,

I'm looking at a memory issue in some code in a few classes that run in a web app. I'm using Glassfish3.1 and have a fairly straight forward REST web app with some Java EE elements (it uses JMS to do some offline processing, etc). The problem is that when I test a part of the app under stress and monitor the server (a Linux server) using top I see the CPU usage at nice acceptable levels for about 20 minutes them BAM! 98-100% levels for ever after. I need to profile the app to figure out what is owning the CPU but I've never used a profiler before and am baffled by all of the online documentation I've found so far. I was hoping to use HPROF since it's built-in but I can not figure out the correct steps to use it.

Is there a plain English document that explains (with examples) how to use HPROF on a web app running in a server (in my case Glassfish 3.1) and read the CPU profile data?

I will accept another solution so long as I can get it easily for free (i.e. I can't use jProfiler because the license costs money), though my preference would be to use hprof.

Regards,

Manny
Badal Chowdhary
Ranch Hand

Joined: Apr 26, 2011
Posts: 34

VisualVM is a free Java profiling tool. I did use this to play around and got a basic Java program attached to this profiler. What is the state of your heap memory?


Blog: http://badalchowdhary.wordpress.com/
Twitter: http://twitter.com/badalrocks
Manny Garcia
Greenhorn

Joined: Apr 04, 2007
Posts: 28
Badal Chowdhary wrote:VisualVM is a free Java profiling tool. I did use this to play around and got a basic Java program attached to this profiler. What is the state of your heap memory?


Howdy Badal,

I have a web application with one Restful web service that blows out memory. It happens in a single thread that's grabbing messages off a JMS queue, turning them into Java objects and then storing them in a MySQL db. It runs great for about a half hour (when I'm stress testing) with mem usage not climbing up more that when that thread in the app isn't running and then without warning, BLAM! mem usage ramps up and inside a 3-5 second window I start seeing heap errors.

I've seen other profiling tools that look easy to hook up to a simple Java app but I need to attach this to a web app that's running inside glassfish. How easy is it to do that with VisualVM? I've had no luck finding any instructions on a free profiler that can do that.


Regards,

Manny
Badal Chowdhary
Ranch Hand

Joined: Apr 26, 2011
Posts: 34

If you are getting heap memory error, that means objects are being created but are not de-referenced when not needed. As a result, Java garbage collector cannot free up memory on heap. There are quite a few tools to analyze heap. All you have to do is set up a JVM parameter to do a heap dump on first occurance of OutOfMemoryError. I had written a post that does this using Eclipse Memory Analyzer. Check out if this is helpful:
http://badalchowdhary.wordpress.com/2011/11/09/java-heap-memory-analyzer/


Thanks,
Badal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Profiler hell