Sunday, April 29, 2012

JVM heap size [ missed concepts ]

This is regarding the  concept of JVM heap size when running on  machines having larger  RAM .The primary advantage of running Java in a 64-bit environment is the larger address space. This allows for a larger Java heap size and an increased maximum number of Java Threads. It's important to note that 64-bit implementation doesn't mean that that built-in Java types (such as integers) are doubled in size from 32 to 64.

However, addressing larger amounts of memory come with a small performance loss in 64-bit VMs (compared to a 32-bit VM) because every reference takes 8 bytes instead of 4.
Loading these extra 4 bytes per reference impacts the memory usage, which causes slightly slower execution (depending on how many pointers get loaded during the Java program's execution).

64-bit Java implementation enables to create and use more Java objects, thus breaking the 1.5-1.6 GB heap limit we have in 32 bit.

below is the command that will set minimum and maximum  heap size for application

java -d64 -Xms2g -Xmx80g MyApp

The above JVM args does not create a process with 80g heap. It only creates a process with 2g of Heap and will only grow till 80g if required and if RAM is available.
by specifying Xmx80g, one is only restricting the maximum heap size that the Java process can use.
When the heap size exceeds the limit specified memory , the behavior of  allocating memory to java process depends on OS.OS can allocate more memory from with in the RAM ( if there is any free space not being used by other user processes or it can allocate memory from disk ) . If heap size size exceeds physical memory then the heap begins swapping to disk which causes Java performance to drastically decrease. It has been observed that after a threshold  memory reaches the performance of application wont  increase considerably by increasing heap size.
For more details on this study click at below link
http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/5/html/Performance_Tuning_Guide/chap-Performance_Tuning_Guide-Java_Virtual_Machine_Tuning.html

The bigger the heap size slower (after a threshold value ) will be performance because it will make GC to be a hazardous task to run.Because the more of time spent on GC. The performance of the application highly depends on how one size the heap generations and GC parameters.

Sun recommends to enable either the Parallel or Concurrent garbage collectors when running with heaps larger than 2 GB.These collectors attempt to minimize the overhead of collection time by either of the following:
-       collecting garbage concurrent with the execution of your Java application
-       utilizing multiple CPUs during collections

Here is good link  providing some info about how to improve performance in multi processor environment.
http://www.jroller.com/imeshev/entry/effect_of_jvm_heap_size

If a web server like jboss is running .it will have its separate heap space than any web application deployed on it .
any webservice deployed and running in it will use its own address space by explicitly giving jvm args to it .

No comments: