tags:

views:

73

answers:

3

Hi, I've written a pretty complex java application that is doing a lot of calculations on price data from the markets in real time and from looking at the task manager in windows this sucker is taking close to 1MEG every 30 seconds and the performance is fine until it gets closer to the memory limit around 300MEG and then the g-collector really kicks in and spikes my CPU to around 50% and the UI performance rapidly degrades from all I've written so far it sounds like I have some bad code going on because the nature of my program is CPU intensive but by design stores very little data in memory.

I need some help on what might be some good next steps to take to see how I can figure out what the problem is, I think if I can see what objects are getting stored in memory that would help as maybe I have some lousy code but I am heart broken with Java as I thought these are problems I would not have to worry about. Thanks for any answers. - Duncan

+3  A: 
  1. Identify some reasonable performance targets (memory usage, throughput, latency).
  2. Put together some repeatable performance tests, the closer you can get these to real life scenarios the better.
  3. Get a hold of a good profiler. I've used YourKit with a lot of success, the Netbeans and Eclipse profilers are not bad either. Most decent profilers will be able to identify memory usage, GC and performance hotspots.
  4. Identify the biggest culprits and start fixing the issues beginning at the TOP of the list.
Michael Barker
+1  A: 

Check out VisualMV. It's in the current JDK bin directory as jvisualvm. If you don't have a memory leak, the heap usage should go down when you run the garbage collector, and you can see which objects may be holding memory by calculating the retained sizes of objects in the heap.

http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/intro.html

Fly
What I'm implying is to make sure it's not a memory issue by making sure the garbage collector is reclaiming memory.
Fly
Thank you for the reply, I will take a look and see if I can link this with launching my program from within eclipse if all it involves is JVM arguments then I think this is the easiest solution instead of at first trying to get the eclipse profiling tools downloaded and working in my IDE - Duncan
Duncan Krebs
A: 

Like others say, use a profiler to find what is consuming the memory.

If you don't know already, the garbage collector can only release memory on objects that are out of scope. That is, don't have any references to them. Just make sure it goes out of scope when your done with it. It sounds like your locking it up in a way were it's still referenced some where.

Also, if you want to suggest to the GC that it cleans up, try this:

System.gc();
System.runFinalization();

Again, that is only a suggestion to the gc; but I've found it really helps if you run it after a lot of objects go out of scope.

Lastly, you can tweak your vm arguments. There are settings for min/max heap size settings. If it's a critical application set them to the same and set it high (that way it doesn't have to keep allocating/deallocating - it just grabs one big chunk at startup). This isn't a fix, just a workaround.

dime