Well, "JVM runs out of memory" could have any of several meanings,
because it has several different pools of memory and any one of them
could have been exhausted.  You need more information.  Is it running
out of heap, of PermGen, something else?  These answers will inform
your search for the problem.

Employ a monitoring tool (I use PsiProbe) and watch the memory
behavior as you approach and hit the wall.

You don't really run out of memory by having lots of garbage; your
app.'s performance begins to "stutter" as GC occasionally becomes a
larger part of the load.  No, you run out of memory by accumulating
uncollectable objects -- they aren't recognized as garbage and so
can't be reclaimed.  It may be that the design of your application
requires such a large accumumlation, or it may be that it is leaking
objects which are no longer useful but can't be collected because they
are referenced by other objects which are still live.

Because memory is organized in multiple pools, you can overfill one of
them (and crash) while having plenty in the others.  It may be that
you just need to redistribute the memory you have.  You'll need to
continue monitoring and adjusting until you discover the necessary
proportions, with each pool well filled yet having comfortable
headroom for traffic spikes.

BTW early in my Java work I found myself just throwing memory at such
problems until they (sometimes) went away.  I eventually realized that
it's possible to give a long-running Java app. *too much* memory --
that a better approach is to keep the pools small enough that GC is
somewhat frequent and never has a huge amount of garbage to deal
with.  I don't want GC to run all the time, but neither do I want to
see it going dormant for ages and then dominating for thousands of
milliseconds.  I want each pool kept, on average, with free space in
the minority but not too scanty.  Mostly what I want is that the main
heap doesn't vary greatly in fill factor under steady load, which
usually means that utilization is somewhat near maximum size but with
room for occasional surges.

Tweaking out unwelcome memory behavior takes a long time and a lot of
staring and thinking.

-- 
Mark H. Wood, Lead System Programmer   mw...@iupui.edu
Asking whether markets are efficient is like asking whether people are smart.

Attachment: pgpwlwQgRrmWs.pgp
Description: PGP signature

Reply via email to