SlideShare une entreprise Scribd logo
1  sur  58
Télécharger pour lire hors ligne
(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

Contenu connexe

Tendances

GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
Ludovic Poitou
 
10 Devops-Friendly Database Must-Haves - Dor Laor, ScyllaDB - DevOpsDays Tel ...
10 Devops-Friendly Database Must-Haves - Dor Laor, ScyllaDB - DevOpsDays Tel ...10 Devops-Friendly Database Must-Haves - Dor Laor, ScyllaDB - DevOpsDays Tel ...
10 Devops-Friendly Database Must-Haves - Dor Laor, ScyllaDB - DevOpsDays Tel ...
DevOpsDays Tel Aviv
 

Tendances (20)

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

En vedette

Employment reference INGlife (JP)
Employment reference INGlife (JP)Employment reference INGlife (JP)
Employment reference INGlife (JP)
Cheol Shin
 
Bachelor Of Engineering 1st Class hons Certificate
Bachelor Of Engineering 1st Class hons CertificateBachelor Of Engineering 1st Class hons Certificate
Bachelor Of Engineering 1st Class hons Certificate
martin wheeler
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
nastya_sha
 
Employment references KOI (JP)
Employment references KOI (JP)Employment references KOI (JP)
Employment references KOI (JP)
Cheol Shin
 
Academic Awards Macquarie University (JP)
Academic Awards Macquarie University (JP)Academic Awards Macquarie University (JP)
Academic Awards Macquarie University (JP)
Cheol Shin
 

En vedette (16)

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

Similaire à (JVM) Garbage Collection - Brown Bag Session

Similaire à (JVM) Garbage Collection - Brown Bag Session (20)

Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
 
JVM Magic
JVM MagicJVM Magic
JVM Magic
 
Introduction to Garbage Collection
Introduction to Garbage CollectionIntroduction to Garbage Collection
Introduction to Garbage Collection
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage Collector
 
Understanding Garbage Collection Using Automatic Memory Management
Understanding Garbage Collection Using Automatic Memory ManagementUnderstanding Garbage Collection Using Automatic Memory Management
Understanding Garbage Collection Using Automatic Memory Management
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnostics
 
this-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptxthis-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptx
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
 
«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java
 
Gopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracowGopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracow
 

Plus de Jens Hadlich

Plus de Jens Hadlich (7)

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

Dernier

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Dernier (20)

Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 

(JVM) Garbage Collection - Brown Bag Session