Amazon

Monday, May 15, 2017

Java - Heap Size - Configuration Options

Java Heap Size - Place to store objects created by your Java application, this is where Garbage Collection takes place, the memory used by your Java application.

-Xms - Set initial Java heap size
-Xmx - Set maximum Java heap size

$ java -Xms512m -Xmx1024m JavaApp

Young Generation - Consist of Eden, S0 and S1 Space
-Xmn - Set the size of young generation.

$java -Xmn512m MyJavaProgram
$java -Xmn1g MyJavaProgram 


Some more switches for Young generation memory configuration are:
  1.   -XX:NewSize - Set the minimum size of young generation which is allocated at initialization of JVM.
  2.    -XX:MaxNewSize - Set the maximum size of young generation that JVM can use.
  3.    -XX:SurvivorRatio - used to tune the size of the survivor spaces. For example -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6.In other words, each survivor space will be one eighth of the young generation (not one seventh, because there are two survivor spaces).
  4.  -XX:NewRatio : NewRatio controls the size of young and old generation.  For example -XX:NewRatio=3 means that the ratio between the young and old/tenured generation is 1:3. In other words, the combined size of the eden and survivor spaces will be one fourth of the total heap size.


Perm Gen Size - Place to store your loaded class definition and metadata.

XX:PermSize - Set initial PermGen Size.
-XX:MaxPermSize - Set the maximum PermGen Size.

$ java -XX:PermSize=64m -XX:MaxPermSize=128m JavaApp

Note:
PermGen space is replaced by MetaSpace in Java 8. The PermSize and MaxPermSize JVM arguments are ignored and a warning is issued if present at start-up.
Most allocations for the class metadata are now allocated out of native memory. * The classes that were used to describe class metadata have been removed.
Main difference between old PermGen and new MetaSpace is, you don't have to mandatory define upper limit of memory usage. You can keep MetaSpace space limit unbounded. Thus when memory usage increases you will not get OutOfMemoryError error. Instead the reserved native memory is increased to full-fill the increase memory usage.
You can define the max limit of space for MetaSpace, and then it will throw OutOfMemoryError : Metadata space. Thus it is important to define this limit cautiously, so that we can avoid memory waste.

Java Stack Size -Size of a Java thread. If a project has a lot of threads processing, try reduce this stack size to avoid running out of memory.

-Xss = set java thread stack size


$ java -Xss512k JavaApp

No comments:

Post a Comment

Amazon Best Sellors

Weblogic - Server Creation - Issues

Datasource creation using python script.  Python Script was failing after creating Datasource. From UI Admin Console, if I try to activat...