We all know
setting the JVM heap space is important and it has options to set Max and Min.
I was wondering for some time why I need min value? I can say the Max value
which was more sensible and min seems to be not very important for me before I
come across a real time scenario. After the below scenario I realized this is
very important.
Basic details of JVM heap setting:
-Xms => mininum heap value which the jvm will pick when its starts. Other important details is, when GC kicks in, it will try to free memory to the Min setting and the GC will kick in only if the used memory is greater than min.
-Xmx => Maximum heap the jvm can reach. The GC will kick on or before it reaches the max as per the GC's algorithm.
Knowing the above details, here is why it’s not recommended to set the jvm min and max the same value when you need to set bigger memory size.
Assume you have set -Xmx and -Xms as 2 gb. Now when the jvm running and GC is waiting for the jvm used heap to reach higher value than the min heap value which is equal to max setting in this case. So GC needs to wait till the jvm just reaches the 2gb heap which is the max size and it has no other option and kicks in the GC. When GC is kicked in whole jvm operations are freezes till it finishes it work.. I have seen the GC has freezes the application for more than 10 secs in this scenario. In this freeze time the number of live threads in the jvm increases. I used to print the live thread count along with each request information. This thread count helped me to debug this scenario. If the application has defined response sla and all of those request will fail in meeting the sla if the freeze time was more than the response sla.
Basic details of JVM heap setting:
-Xms => mininum heap value which the jvm will pick when its starts. Other important details is, when GC kicks in, it will try to free memory to the Min setting and the GC will kick in only if the used memory is greater than min.
-Xmx => Maximum heap the jvm can reach. The GC will kick on or before it reaches the max as per the GC's algorithm.
Knowing the above details, here is why it’s not recommended to set the jvm min and max the same value when you need to set bigger memory size.
Assume you have set -Xmx and -Xms as 2 gb. Now when the jvm running and GC is waiting for the jvm used heap to reach higher value than the min heap value which is equal to max setting in this case. So GC needs to wait till the jvm just reaches the 2gb heap which is the max size and it has no other option and kicks in the GC. When GC is kicked in whole jvm operations are freezes till it finishes it work.. I have seen the GC has freezes the application for more than 10 secs in this scenario. In this freeze time the number of live threads in the jvm increases. I used to print the live thread count along with each request information. This thread count helped me to debug this scenario. If the application has defined response sla and all of those request will fail in meeting the sla if the freeze time was more than the response sla.
No comments:
Post a Comment