• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about GC.

 
Roland Benedek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I recently ran into a problem with a webservice leaking memory badly when its hammered with request.
After some research it seems that the garbage collector cannot keep up?
The webservice itself it a java wrapper*(axis and some custom code) around a pl/sql procedure.
And yes all connection and jdbc objects are closed/freed.

It is my believe that the GC cannot keep up near the end.
I try to create a testcase to reproduce this. I cam up with the following but I cannot understand why I get out of memory errors.


There are hardly any references kept by classes. All objects instanciated should be ready for garbage collection right after they have been created, why does it run out of memory?

In the log I can see the number of instances increase but hardly any finalizers being called near the end.
At the start a fair number of finalizers gets called but this stops.
In terms of memory usage I see the expansion at first and when its getting close to the 64M mark (yes I know this is implicitly set and I can increase this) the finalers stop being called and memory stops being freed.

It was I was afraid the object creation in simpleobject was keeping the object on the method stack so I removed the instantiation to its own method. But I�m not sure if this helps.

I know this program is ridiculous and I�m not even sure if it represent the problem in the webservice but I just cannot understand what is going on. I have like NO references why aren�t all simpleobjects being finalized? Near the end (60secs) I see around 1.000.000 open instances not being gc�d.

I have read:
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
But this does very little.
I can increase the programs life to 120 seconds but the processes comes to a near stop from 70-120secs
I used the parameters:

Note that the guide lists �XX(+)CMSIncrementalDutyCycle=10
With an extra (+) this is wrong and not accepted by the JVM

Another thing which I have noticed and which I cannot believe is that when I compile my source as 1.2 instead of 1.4 it crashes even earlier and GC behaviour seems even more out of control, releasing even less objects.

Anyone got a clue what is going on?
[ June 06, 2008: Message edited by: Anton Gerdessen ]
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you are experiencing a JVM bug, you will never get an OutOfMemoryError when there is memory that could be freed by GC. Java guarantees this. There is never a case when the GC "can't keep up".

I haven't time to look at the detail of the code, right now, but just thought I'd nip that misunderstanding in the bud.
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you are using the CMS collector. If your code is generating large amounts of garbage quickly, there is the possibility that the CMS collector will not be able to keep up with the garbage being created. At that time, the JVM should halt the app and run a regular serial collector pass on the tenured generation to clean up the heap. This collection pass is usually very expensive (I have seen 5 minute pauses on a 1GB heap).

Therefore, you never want the CMS collector to get behind in its task. If your app is truly creating too much garbage too fast, then stick with the default serial collector.
[ June 06, 2008: Message edited by: Peter Johnson ]
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thought.

CMS by default sets the tenuring threshold to 0 and minimizes the size of the survivor spaces. The idea being that if the object survives the minor collection then it immediately goes into the tenured generation for possible later collection by the CMS collector when it dies. Personally, i have found this behavior to be counter-productive. I usually set -XX:TenuringThreshold=32 -XX:SurvivorRatio=8 (or some other number, depending on the young gen size - larger young gens can have higher ratios) after setting the CMS options.

And another thought. How many CPUs (or cores) do you have? I would not run with CMS unless I had 2 CPUs, but I would prefer 4. Running on a single CPU is asking for trouble.
 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is for the OutOfMemoryError is most likely due to the stack space for the 500 threads. See "Java Concurrency in Practice" by Goetz, page 116.
 
Roland Benedek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies all.

No CMS when there is a lot of ‘young’ generation. Ok point taken.

Dropped the CMS collector all together.

Out of memory due to the maximum number of threads, no cant be it reduced it to 100 and I still get it.

I found a very good whitepaper though:
http://java.sun.com/performance/reference/whitepapers/tuning.html#section4.2.6

This way I decided to try:


-Anton
[ June 09, 2008: Message edited by: Anton Gerdessen ]
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
Unless you are experiencing a JVM bug, you will never get an OutOfMemoryError when there is memory that could be freed by GC.


I should qualify this.

You'll never get an OutOfMemoryError due to lack of heap when there is enough memory that could be freed by GC.

However, you might get an OutOfMemoryError due to lack of some other resource.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your objects are finalizable and finalize() needs to acquire lock, so finalization does not keep up with object creation.

This badly slow down the whole OS (Windows XP) and creates OutofMemoryError, but not without the Thread.yield():

[ June 09, 2008: Message edited by: Vlado Zajac ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!