Xms, Xmx, XX:Maxpermsize, XX:Permsize - What’s the difference?

Asked

Viewed 37,878 times

15

I need to improve the performance and availability of my Glassfish application server that from time to time causes the application to launch Outofmemory error. Searching the internet, I checked that I should change the following parameters:

Xms
Xmx
XX:MaxPermSize
XX:PermSize

What I could not find in a clear way was what the difference between these parameters, what the goal of each one, so that I can decide correctly what values to set in each of them.

1 answer

19


Dynamic memory

The parameter Xmx defines the bad amountxDynamic memory ima that the Java Virtual Machine will allocate to store object instances, variable values, among others.

It is important to define a value reasonably higher than the application needs on average to avoid not only errors of OutOfMemory as well as lack of memory, otherwise the Garbage Collector will perform very often and cause unwanted breaks in the program.

The Xms sets the initial amount of dynamic memory allocated at the beginning 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 a higher boot performance to the point where the application is running on a stable plateau.

Permanent memory

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

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

The error occurs because it is not possible for Java to load new classes when there is no space in the permanent memory, as it is not possible to discard already loaded classes to make room for new ones.

Here are the other two parameters. The XX:MaxPermSize sets the maximum amount of permanent memory the Virtual Machine can use. The XX:PermSize sets its initial size.

Example

The following image illustrates the above concepts:

JVM Memory

Note that in the dynamic part of memory (on the 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 displaced from objects created longer ago, with less chance of displacement.

  • Great, very explanatory. I only had one other question: on the same server I have Jboss and Glassfish installed. Each application server with a running Java application. Jboss already configured this part of memory. If I set it up in Glassfish, will it interfere with the configuration that was made in Jboss? You may have some configuration conflict or the JVM behaves differently for each application server?

  • @Electus Each instance of the JVM is independent and does not interfere with the others, except in the dispute for resources such as CPU and disk. Also be careful that the sum of the memory configured in the two does not exceed the amount of RAM, otherwise you may end up with disk memory paging.

  • 1

    I think it’s worth mentioning that the permanent memory has been removed in Java 8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.