0% found this document useful (0 votes)
59 views

JVM Tuning in Containers

This document discusses JVM GC tuning in containerized environments. It covers common issues like application zombie state, OOM errors, and increased latency. It recommends enabling GC logging and metrics collection to monitor metrics like GC pause time and memory usage. Based on these metrics, GC settings may need to be tuned if there are long GC pauses, frequent full GCs, or OOM errors. The goals of GC optimization are application throughput, latency, and memory footprint. The document also discusses different GC algorithms like Serial, Parallel, G1, Z, and Epsilon GC and when each would be appropriate.

Uploaded by

Vinayak Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

JVM Tuning in Containers

This document discusses JVM GC tuning in containerized environments. It covers common issues like application zombie state, OOM errors, and increased latency. It recommends enabling GC logging and metrics collection to monitor metrics like GC pause time and memory usage. Based on these metrics, GC settings may need to be tuned if there are long GC pauses, frequent full GCs, or OOM errors. The goals of GC optimization are application throughput, latency, and memory footprint. The document also discusses different GC algorithms like Serial, Parallel, G1, Z, and Epsilon GC and when each would be appropriate.

Uploaded by

Vinayak Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

JVM GC Tuning in Containerised

Environment

Inspiring Brilliance
Garbage Collection

● Manages allocation and deallocation of the objects


JVM Memory Layout
GC Operations

● Mark

● Sweep

● Scavenge

● Compact
Commonly Faced Issues In Container Environment

● Application in zombie state


● OOM / Container OOM
● Unpredictable workload
● Sudden increase in latency
Prerequisite To The Tuning

● Exiting on Out of Memory (-XX:+ExitOnOutOfMemoryError)


● Print flags (-XX:+PrintFlagsFinal)
● GC logs
(-Xlog:gc=debug:file=/tmp/gc.log:time,uptime,level,tags:filecoun

t=5,filesize=100m)

● Making sure container has tools to support debugging (jmap)


Monitoring The Metrics

● Prometheus metrics
○ jvm_gc_pause_seconds
○ jvm_gc_memory_allocated_bytes_total
○ jvm_gc_memory_promoted_bytes_total
Tune GC Settings If

● Long pause of GC
● Frequent Full GC
● Frequent OOM
GC Optimization Goals

● Application Throughput
● Latency
● Memory Footprint
JVM Ergonomics

● Depending on where JVM is running it auto-tunes itself


● Tries to maximize one of the two goals pause time and throughput
● Target environment could be a lot different from local environment
Collecting Heap Dump
● Collect while application is running
● Collect when application gets crashed due to OOM - -XX:
+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps

● Retrieving the dump


○ kubectl cp / docker cp
○ copy from the node which is running the container
Monitoring the application

● Enable remote connections


● Tools to connect to running VM
○ Jconsole
○ VisualVM
○ Java Flight Recorder
Choosing Garbage Collector
Serial Collector

● Single threaded garbage collector


● Suitable for applications which are single core and have memory 100MB -
300MB
Parallel Collector (Throughput)

● Behaviour Tuning
● Latency -XX:MaxGCPauseMillis - No default value
● Throughput -XX:GCTimeRatio 1 / (1 + GCTimeRatio) - Default 12 (8%)
● Footprint -Xmx
● Additional Tuning
○ -XX:MinHeapFreeRatio
○ -XX:MaxHeapFreeRatio
○ -XX:AdaptiveSizePolicyWeight
Garbage First (G1GC)
Garbage First (G1GC)

● Throughput - -XX:MaxGCPauseMillis (Higher value)


● Latency - -XX:MaxGCPauseMillis (Lower value)
● Incurs overhead in application threads and space reclamation
● Meant for heaps larger than 10G
Z GC

● Non-generational and Concurrent (-XX:ConcGCThreads)


● GC pause doesn’t increase with the size of the heap
● Intended for low latency applications
● Also returns unused memory back to OS (-XX:-ZUncommit)
Epsilon

● NO OP Garbage collector (-XX:+UseEpsilonGC)


● Handles memory allocation but doesn’t implement
reclamation
Heap Sizing

● Law of diminishing returns


References
● https://www.oreilly.com/library/view/java-performance-the/9781449363512/
● https://docs.oracle.com/en/java/javase/17/gctuning/introduction-garbage-collection-tuning.ht
ml#GUID-326EB4CF-8C8C-4267-8355-21AB04F0D304
Thanks!

Contact

You might also like