Wednesday, September 3, 2014

Heap size and Perm size

The GC document on Sun's site showed the Perm generation to be part of the Heap size. It seems that the Perm size is

different from the Heap size.The total memory used by the JVM process will be = Memory used by the JVM for internal management + memory allocated in native code + memory allocated for the permanent space.
This is the memory that U see in Task-Manager in Windows or 'top' on Solaris.

A quick definition of the "permanent generation":

"The permanent generation is used to hold reflective data of the VM itself such as class objects and method objects. These

reflective objects are allocated directly into the permanent generation, and it is sized independently from the other

generations."

In other words, this is where class definitions go (and this explains why you may get the message OutOfMemoryError:

PermGen space if an application loads a large number of classes and/or on redeployment).



Java's  Heap Size

Java has a couple of settings that help control how much memory it uses:

-Xmx sets the maximum memory heap size
-Xms sets the minimum memory heap size.

Keep -Xms Small

For a server with a 'small' amount of memory, then we recommend that -Xms is kept as small as possible.  e.g. -Xms 16m.

Some  set this higher, but that can lead to issues.  e.g. the command that restarts tomcat runs a java process.

That Java process picks up the same -Xms setting as the actual Tomcat process.  So you will effectively be using two times

-Xms when doing a restart.  If you set -Xms too high, then you may run out of memory.

Don't Let -Xmx Be Too Low

When setting the -Xmx setting you should consider a few things...  -Xmx has to be enough for you to run your app.  If it is set too low then you may get Java OutOfMemory exceptions (even when there is sufficient spare memory on the server).

If your application is throwing an OutOfMemoryError then it could be because the PermSize is full, rather than the heap size. HERE IS ANOTHER POST TO SOLVE THIS PROBLEM


0 comments:

Post a Comment