Memory Utilization & Garbage Collection Analysis

Memory Utilization & Garbage Collection Analysis
  • The goal should be to optimize garbage collection (GC) in such way that its impact on application response time or CPU usage is minimized.
  • Monitor the utilization of different memory pools (young, survivor and old). Memory shortage is the number-one reason for the increased GC activity
  • The young generation should be big enough to ensure that all temporary objects die there
  • If overall memory utilization is growing continuously despite garbage collection, it is an indication of memory leak and requires heap analysis
  • Monitor the churn rate (number of object allocation per interval) at the younger generation. The high number of young collection can cause high response time. It can cause unnecessarily copying of objects from young generation to old generation
  • Free tools that can be used for GC analysis are:
    • JConsole, jStat, Java VisualVM, JRockit Mission Control, verbose:gc flag of the JVM
  • A high GC activity generally has a negative effect on CPU usage and not necessarily the response time of application, whereas only suspensions affects directly the response time of application. JVM suspensions should be monitored to find out whether the root causes lie in:
    • The younger generation, Object churn, Old generation, wrong sizing or memory leak
  • Case where old generation utilization rises continuously but come back to normal after GC, indicates the high churn rate. It might not be enough to increase the young generation's size, which will be accommodating more live objects, which in turn will lead to longer GC cycles. The best optimization is always to reduce the number of allocations and the overall memory requirement
  • It is important to differentiate between young and old generation GC and equally important is noticing frequency and duration of those GC. For the young generation, duration might be low but frequency might be higher due to frequent allocation of objects. The high GC of young generation can be result of either too small memory allocation for young generation or high churn (allocation) rate. The root cause for higher allocation need to be analyzed
  • The GC time should never take up more than 10% of the total CPU time used by the application
  • Optimize algorithm by unnecessary allocations or allocating the same objects multiple time e.g. Creating same temporary objects in a loop.
  • JVVisualVM can be used to find out the root cause of high allocation (churn rate)
  • High memory utilization is a cause for excessive garbage collection. Increasing the heap size of JVM might solve the problem. But increasing the heap size not always solves the problem but delays the problem and in that case GC takes more time.
  • Memory usage can be analyzed using Heap dump. Multiple tools that can be used for analyzing heap dumps are - jmap, jhat, VisualVM, JRockit Mission Control
  • Analysis of memory results are - a) Identification of memory leak b) Identification of memory eaters
  • Multiple heap dumps are needed and compared against trends to find objects that are leaking. For analysis, It is advisable to stick to classes that are created by your application
  • The purpose of heap dump analysis is to find out memory leak or whether cache (e.g. HashMap) is using too much memory

Comments

Popular posts from this blog

Performance Test Run Report Template

Understanding Blockchain

Bugs Management in Agile Project