Hi All,
Jay SenSharma

Jay SenSharma

NOTE : Prerequisite of this post is that u are aware of the JVM Architecture and different generations of it…If not then Please refer to:  http://middlewaremagic.com/weblogic/?p=4464
And
.
Middleware performance is directly related to the JVM Tuning. Due to incorrect JVM Tuning we may face OutOfMemory, High CPU, StuckThread, Server Crash kind of issues. There is no standard value available for JVM Tuning which can be suggested so that a JVM can be called as 100% tuned because the JVM tuning totally depends on the Platform (Operating System), The Number of CPUs, The nature of Application (Like how many objects it creates? How Many Long Living Objects? How it implements Caching of Objects? …etc). But if we will keep following  things in mind while tuning the JVM then it may be really helpful.
.
Here are some very basic tips of tuning the JVM. Whatever Values of different JVM tuning parameters we are going to see and discuss in this Article is not an absolute value, it may vary according to your environmental setup and requirement.

Tip-1).  If Observed the GC time is Very Long.

If we observe that the Full Garbage Collection is taking a longer duration (Healthy JVM Usually takes around 2 to 2.5 Seconds for Full GC) then we must try following things:
.
Point-1). -Xincgc: Applying the “-Xincgc” JVM Option instructs the JVM to use the incremental Garbage Collection Strategy. Due to this option the Garbage Collector starts Garbage Collecting a fraction of heap at a time rather than Garbage Collecting the whole Heap space at once. So it reduces the long GC pauses.
.
Point-2). Apart from above we can even decide to decrease the Max Heap Size (If a very large heap is not required for us). Because if the Heap Size is very large then the Garbage Collector will take little longer duration to perform a full GC.
.
Point-3). Suppose if we dont have an option to decrease the Heap Memory then we can even think of adjusting the -XX:MaxNewSize (in JDK1.3 and JDK1.4) or  -Xmn (new name of Young Generation flag from JDK1.4 onwards). Increasing the -Xmn (Young Generation Area) helps in scenarios where the Application creates short living objects (less caching Applications). Because it inceases the time of minor GC, most of the application objects dies early.
.
Example-1:
Suppose the Maximum Heap is -Xmx1024m then we can choose the Young Generation EdenSpace as -Xmn340m… It means the 1/3 (one third of the Max Heap) Or in other way we can say that the Eden Space is One Third of the Maximum Heap.
Example-2:
It can also be achieved by setting the -XX:NewRatio. Because  -XX:NewRatio=2 means that 2:1 ratio of Tenured and Young Generation(Eden)

Tip-2).  Full GC Is Happening Very Frequently?

Many times some application calls System.gc() or Runtime.gc() to perform explicit Garbage Collection (Which is not recommended). Apart from this if an Application uses many Remote Method Invocation calls then in that case as well there are chances that the full GC may happen very frequently.  In this case we can try disabling the Explicit Garbage Collection statements using the JVM Option:  -XX:+DisableExplicitGC
Similarly If we dont require a very frequent RMI garbage collection then we can use the JVM Option:  –Dsun.rmi.dgc.client.gcInterval=1800000 ……     It means now the Explicit RMI Garbage collection will happen in 30 Minutes.

Tip-3).  OutOfMemoryError: unable to create new native thread?

If you see very frequently “java.lang.OutOfMemoryError: unable to create new native thread”. It usually happens if the -Xss Stack size is very large. Thread Stack size is a memory area where the Threads places their local variables and maintains the stack. Many applications which creates a lots of Threads which requires less memory for their local variables, still the JVM allocates a large memory StackSize for those threads…so after a certain number of thread creation JVM will not be allocate some more space for new Thread creation.
.
So it is recommended for these kind of environments that we decrease the StackSize because Sparc 32-bit JVM has -Xss512k as default value and 1024k Stack Size on Sparc 64-bit JVM. So if we want to create some more threads and if the Threads requires less memory stack then in that case we should try to decrease the StackSize.

Tip-4). How To Preserve Memory ?

We must disable loading some libraries in the memory of JVM if our application does not require them. Like if our Application does not require the JVMs Graphic Library then in that case we must diasble loading of Graphic libraries using the JVM Option  “-Djava.awt.headless=true”

Some More Tips….Keep Visiting Middleware Magic….
.
.
Thanks
Jay SenSharma
If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.