Xms, Xmx, XX: MaxPermSize, XX: PermSize - what's the difference?

I need to improve the performance and availability of my Glassfish application server which from time to time causes the application to throw OutOfMemory error. Searching the internet, I checked that I must change the following parameters:

Xms
Xmx
XX:MaxPermSize
XX:PermSize

What I could not find clearly was what the difference between these parameters, what the purpose of each, so that I can decide correctly which values to set in each of them.

Author: electus, 2014-10-23

1 answers

Dynamic Memory

The parameter Xmx sets the bad amountxima of dynamic memory that the java Virtual Machine will allocate to store instances of objects, variable values, among others.

It is important to set a value that is reasonably higher than the application needs on average to avoid not only OutOfMemory errors but also memory shortages, otherwise Garbage Collector will run very often and cause pauses unwanted in the program.

O Xms sets the initial amount of dynamic memory allocated at the start of the JVM.

It is important to check how much your application uses on average and set a value close to that. This way, your application will not need pauses to allocate memory, resulting in higher startup performance to the point where the application is running at a stable level.

Permanent memory

Java also has another part of the memory called "static" or "permanent", used to load your classes (files .class), internalize Strings (pool), among other things.

As a general rule, permanent memory cannot be deallocated. This implies that if your application has too many Jars and classes, at some point an error of PermGen space will occur.

The error occurs because Java cannot load new classes when there is no space in permanent memory, because you can not discard already loaded classes to give way to new ones.

Here enter the other two parameters. O XX:MaxPermSize sets the maximum amount of permanent memory that the Virtual Machine can use. O XX:PermSize sets the initial size of it.

Example

The following image illustrates the above concepts:

JVM Memory

Note that in the dynamic memory part (left) there is still a difference between "new" and " old " generation, which are used, respectively, to store newly created objects that are candidates and be quickly deallocated from objects created longer, with less chance of deallocation.

 18
Author: utluiz, 2014-10-23 13:49:40