SlideShare a Scribd company logo
(JVM) Garbage Collection & Co.
Brown Bag Session
Jens Hadlich
2015-12-08
Garbage Collection
2
Why should I care?
Garbage Collection
4
Can have a huge impact
30 seconds
20 seconds
10 seconds
~16 hours
Outline
•  Some Theory
•  Practice & real world examples
•  Tools & live demos
•  Configuration best practices
•  Discussion
5
Some Theory
Garbage Collection
7
Garbage Collection
8
Terminology
Garbage collection
… is a form of automatic memory management.
Garbage
… memory occupied by objects that are no longer used.
9
Pros and Cons
Pros
-  Programmer does not need to worry about memory (de-)allocation
(leading to fewer memory leaks)
Cons
-  Performance overhead
-  Can lead to more complex programming language design
10
More Terminology
Collector
Heap
Mutator
Roots
11
Roots
12
Garbage Collection
Algorithms
13
Tracing Reference Counting
Collection Style Batch Incremental
Cost Per Mutation None High
Throughput High Low
Pause Times Long Short
Real Time? No Yes
Collects Cycles? Yes No
Tracing algorithms
Mark & Sweep
Copying
14
Think of a bookshelf
15
Tracing algorithms
Mark & Sweep
Copying
16
Mark & Sweep
Mark the books you want to keep
17
Mark & Sweep
Throw away the books that you don’t want to keep
18
Mark & Sweep
Problem: Fragmentation
19
This size book won’t fit!
Tracing algorithms
Mark & Sweep
Copying
20
Copying
Need 2 shelves
21
Copying
Move (“copy”) books you want to keep
22
Copying
Throw away books you don’t want to keep
23
Further readings
24
Java
HotSpot JVM Architecture
26
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html
Java
27
Metaspace
(Java 8 and later)
(Java 7 and earlier)
Java
Generational Garbage Collection
28
Hypothesis:
Most objects die young
Generational Garbage Collection
29
Tools & Practice
Garbage Collection
Tools
(Memory Analyzer)
Java VisualVM
jClarity Censum
Grafana
Icinga
31
A little bit of GC Tuning
GC Tuning
Performance Triangle
33
Memory Footprint
Throughput Latency
M
T L
GC Tuning
Better Performance Triangle
34
Compactness
Throughput Responsiveness
C
T R
C x T x R = a
Optimization: Increase a
Responsiveness vs. Throughput
35
Collectors
Collectors (new generation)
-XX:+UseSerialGC (Copy)
-XX:+UseParNewGC
(used together with old gen CMS)
-XX:+UseG1GC
(same for old gen)
36
Collectors
Collectors (old generation)
Throughput:
-XX:+UseSerialGC (MarkSweepCompact)
-XX:+UseParallelGC
-XX:+UseParallelOldGC
Low-pause:
-XX:+UseConcMarkSweepGC
-XX:+UseG1GC
37
Concurrent Mark-Sweep
38
Fun with JVM Options
39
Fun with JVM Options
Most important
-server
Crucial for all long-running server applications.
http://stackoverflow.com/questions/198577/real-differences-between-
java-server-and-java-client
40
Fun with JVM Options
Most important (cont’d)
-Xms (-XX:InitialHeapSize)
-Xmx (-XX:MaxHeapSize)
Setting Xms = Xmx (slightly) saves some overhead.
41
Fun with JVM Options
Enable GC logs
-Xloggc:logs/gc-<app>.log
-XX:+PrintGCCause
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintHeapAtGC
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=2
-XX:GCLogFileSize=128M
42
Fun with JVM Options
Enable JMX remoting
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=<port>
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
43
Think about your program
https://flink.apache.org/news/2015/05/11/Juggling-with-Bits-and-Bytes.html
44
Best practices
Best practices
“Good” JVM options to start with
-server
-Xms1g
-Xmx1g
-XX:+AlwaysPreTouch
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:+DisableExplicitGC
46
Best practices
Notes on G1GC
-XX:+UseG1GC
http://www.oracle.com/technetwork/articles/java/
g1gc-1984535.html
(G1GC shall become the default collector in Java 9)
47
Best practices
“Good” JVM options to start with (G1GC)
-server
-Xms1g
-Xmx1g
-XX:+AlwaysPreTouch
-XX:+UseG1GC
-XX:+DisableExplicitGC
48
Best practices
Keep the heap size below 30 GB if possible.
Why? Compressed oops.
https://wiki.openjdk.java.net/display/HotSpot/
CompressedOops
http://docs.oracle.com/javase/7/docs/technotes/guides/vm/
performance-enhancements-7.html
(enabled by default since Java 7 for 64-bit)
49
Best practices
Look out for specific tuning guides /
recommendations.
https://www.elastic.co/guide/en/elasticsearch/guide/
current/heap-sizing.html
50
The End?
The End?
Other things that can go wrong.
Linux OOM Killer
53
System (3GB memory)
JVM (Xmx=2g)
/var/log/kern.log
jvm.memory.total.used
OOM
54
hs_err_pid<pid>.log
Questions?
Add-on slides
Go
57
Java Profiling
58

More Related Content

PDF
Understanding Garbage Collection
PDF
Garbage collection in JVM
PDF
Let's talk about Garbage Collection
PDF
JVM Garbage Collection Tuning
PPTX
HotSpot JVM Tuning
PDF
How long can you afford to Stop The World?
PDF
On heap cache vs off-heap cache
PDF
Intorduce to Ceph
Understanding Garbage Collection
Garbage collection in JVM
Let's talk about Garbage Collection
JVM Garbage Collection Tuning
HotSpot JVM Tuning
How long can you afford to Stop The World?
On heap cache vs off-heap cache
Intorduce to Ceph

What's hot (20)

PDF
Introduction of Java GC Tuning and Java Java Mission Control
PDF
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
PDF
"Metrics: Where and How", Vsevolod Polyakov
PDF
Time Series Processing with Solr and Spark
PPT
Garbage collection in JVM
PDF
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
PDF
Мониторинг. Опять, rootconf 2016
PPTX
Metrics: where and how
PPT
An Introduction to JVM Internals and Garbage Collection in Java
PDF
Ceph Object Storage Performance Secrets and Ceph Data Lake Solution
PDF
10 Devops-Friendly Database Must-Haves - Dor Laor, ScyllaDB - DevOpsDays Tel ...
PDF
Debugging Your Production JVM
PDF
Chronix Poster for the Poster Session FAST 2017
PDF
Basics of JVM Tuning
PPTX
Tuning Java GC to resolve performance issues
PDF
Aerospike Go Language Client
PDF
The new time series kid on the block
PDF
ELK: Moose-ively scaling your log system
PDF
Gnocchi v3 brownbag
PDF
A Fast and Efficient Time Series Storage Based on Apache Solr
Introduction of Java GC Tuning and Java Java Mission Control
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
"Metrics: Where and How", Vsevolod Polyakov
Time Series Processing with Solr and Spark
Garbage collection in JVM
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Мониторинг. Опять, rootconf 2016
Metrics: where and how
An Introduction to JVM Internals and Garbage Collection in Java
Ceph Object Storage Performance Secrets and Ceph Data Lake Solution
10 Devops-Friendly Database Must-Haves - Dor Laor, ScyllaDB - DevOpsDays Tel ...
Debugging Your Production JVM
Chronix Poster for the Poster Session FAST 2017
Basics of JVM Tuning
Tuning Java GC to resolve performance issues
Aerospike Go Language Client
The new time series kid on the block
ELK: Moose-ively scaling your log system
Gnocchi v3 brownbag
A Fast and Efficient Time Series Storage Based on Apache Solr
Ad

Viewers also liked (16)

PDF
3.Personal Performace
DOCX
EGHOBOR OGBE GIDEON
PDF
Employment reference INGlife (JP)
DOCX
Practica 10
PDF
Work Cert
PDF
Bachelor Of Engineering 1st Class hons Certificate
PDF
Untitled Presentation
PDF
Channels of distribution
PDF
Employment references KOI (JP)
DOCX
ёлка
PDF
Academic Awards Macquarie University (JP)
PPTX
Gabay consumer loyalty
PDF
Jonathan gabay resume
PPTX
Defense mechanisms
PDF
GSHSS5_2014_v3n1_50
PDF
Es obligatoria la circuncisión para celebrar pesaj?
3.Personal Performace
EGHOBOR OGBE GIDEON
Employment reference INGlife (JP)
Practica 10
Work Cert
Bachelor Of Engineering 1st Class hons Certificate
Untitled Presentation
Channels of distribution
Employment references KOI (JP)
ёлка
Academic Awards Macquarie University (JP)
Gabay consumer loyalty
Jonathan gabay resume
Defense mechanisms
GSHSS5_2014_v3n1_50
Es obligatoria la circuncisión para celebrar pesaj?
Ad

Similar to (JVM) Garbage Collection - Brown Bag Session (20)

PDF
Jvm is-your-friend
PDF
The JVM is your friend
PDF
JVM Performance Tuning
PDF
[BGOUG] Java GC - Friend or Foe
PPTX
Memory Management in the Java Virtual Machine(Garbage collection)
PPTX
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
DOC
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
PDF
Garbage Collection in Java.pdf
ODP
Garbage Collection in Hotspot JVM
PDF
JVM Memory Management Details
PPTX
Garbage collection
PDF
Introduction to Garbage Collection
PPT
«Большие объёмы данных и сборка мусора в Java
PPTX
An efficient memory system for java Garbage Collection
PPT
Taming Java Garbage Collector
PDF
Memory Management in the Java HotSpot Virtual Machine
PPTX
Intro to Garbage Collection
PPT
Gc in android
PDF
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
ODP
Garbage collection
Jvm is-your-friend
The JVM is your friend
JVM Performance Tuning
[BGOUG] Java GC - Friend or Foe
Memory Management in the Java Virtual Machine(Garbage collection)
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection in Java.pdf
Garbage Collection in Hotspot JVM
JVM Memory Management Details
Garbage collection
Introduction to Garbage Collection
«Большие объёмы данных и сборка мусора в Java
An efficient memory system for java Garbage Collection
Taming Java Garbage Collector
Memory Management in the Java HotSpot Virtual Machine
Intro to Garbage Collection
Gc in android
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
Garbage collection

More from Jens Hadlich (7)

PDF
Spreadshirt Architecture Overview (2018)
PDF
Spreadshirt Platform - An Architectural Overview (2017)
PPTX
Kubernetes at Spreadshirt - First steps to production
PDF
Ceph at Spreadshirt (June 2016)
PDF
Ceph Object Storage at Spreadshirt (July 2015, Ceph Berlin Meetup)
PDF
Spreadshirt Platform - An Architectural Overview
PDF
Ceph Object Storage at Spreadshirt
Spreadshirt Architecture Overview (2018)
Spreadshirt Platform - An Architectural Overview (2017)
Kubernetes at Spreadshirt - First steps to production
Ceph at Spreadshirt (June 2016)
Ceph Object Storage at Spreadshirt (July 2015, Ceph Berlin Meetup)
Spreadshirt Platform - An Architectural Overview
Ceph Object Storage at Spreadshirt

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Modernizing your data center with Dell and AMD
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25 Week I
The AUB Centre for AI in Media Proposal.docx
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Big Data Technologies - Introduction.pptx
Modernizing your data center with Dell and AMD
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

(JVM) Garbage Collection - Brown Bag Session