Monday, January 16, 2017

JVM Memory model and Garbage Collection

JVM Memory model and Garbage Collection (GC) is explained well in

http://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java

Java JVM flags explained

Java Heap Space vs Stack – Memory Allocation in Java

The difference between Java Heap Space and Stack is explained well in the link

http://www.journaldev.com/4098/java-heap-space-vs-stack-memory

Why to set -Xms and -Xmx to the same value?

This query is answered well in

https://developer.jboss.org/thread/149559?_sscc=t

In a production environment, if you monitor the GC data, you will notice that is a relatively short period of time (usually less than an hour), the JVM will eventually increase the heap size to the -Xmx setting. Each time the JVM increases the heap size it must ask the OS for additional memory, which takes time (and thus adds to the response time of any requests that were is process when the GC hit). And usually the JVM will never let go of that memory. Therefore, since the JVM will eventually grab the -Xmx memory, you might as well set it to that at the beginning.

Another point is that with a smaller heap size (starting with -Xms), GCs will happen more often. So by starting with a larger heap initially the GCs will happen not as often.

Finally, in a production environment, you usually run only one app server per OS (or per VM). So since the app server is not competing for memory with other apps you might as well give it the memory up front.

Sunday, January 8, 2017

Thursday, January 5, 2017