SlideShare uma empresa Scribd logo
1 de 23
Taming The
Java
garbage
ColleCTor
Daya Atapattu
Why Learn Garbage Collection?
To select a GC algorithm
To performance debug applications
To become a better programmer
Summary
How Java garbage collectors work
How to monitor and tune GC
How to write GC friendly Java code
Dynamic Memory Allocation
Fortran77: No Dynamic Memory
C:

Dynamic Memory managed by
programmer. malloc() / free()

Java:

Dynamic Memory managed
by JVM, i.e. Java GC
Weak Generational Hypothesis
Most objects die young.
Only few references from old objects
to young objects.
All Apples in One Basket?
GC Regions
Young Generation Collection
Old Gen and Compaction
Stop The World (STW)
Concurrent Mark-Sweep (CMS)
Old gen is collected concurrently
1. STW, Mark roots
2. Mark concurrently with application
3. STW, mark again to catch up
4. Sweep
CMS
CMS Pros and Cons
Reduces pause
Does not collect all garbage.
Leaves the heap fragmented so allocation
is more expensive.
CMS failures.
Needs more heap.
Steals threads and CPU from application.
G1 Collector
GC Tuning
Use GC logging options with JVM
-Xloggc:gc.log
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamp
GC Tuning
6.255: [GC [PSYoungGen: 132532K-16412K(278912K)]
141408K->25289K(453696K), 0.013 secs]
[Times: user=0.08 sys=0.01, real=0.01 secs]
6.269: [Full GC (System)
[PSYoungGen: 16412K->0K(278912K)]
[PSOldGen: 8876K->24956K(174784K)]
25289K->24956K(453696K)
[PSPermGen: 60341K->60341K(120960K)], 0.153 secs]
[Times: user=0.16 sys=0.00, real=0.16 secs]
GC Monitoring
Use tools to visualize GC activity
Some such tools:
JConsole
JStat
VisualVM (with GC extension)
Some Important Parameters
GC - The garbage collector in use.
Size of the Java heap.
Size of the young and old generation spaces.
Duration of minor garbage collections.
Frequency of minor garbage collections.
Duration of full garbage collections.
Frequency of full garbage collections.
What initiates full GC; old gen or perm space.
Attributes of Java Performance
Pause Time: Minimal pause time due to
GC
Throughput: Overall performance of user
process ignoring pauses due to GC
Footprint: Amount of memory required for
GC to run efficiently
GC Friendly Coding
GCs love small, immutable, short-lived objects
Object pooling is usually bad
Large objects are expensive to allocate,
expensive to initialize and may fragment CMS
Nulling references is usually bad
Avoid finalize()
Avoid calling System.gc()
Avoid memory Leaks
Some sources: Objects in the wrong scope
Instances of inner classes
Thank You!
&
Questions?

Mais conteúdo relacionado

Mais procurados

JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
Kai Koenig
 
Inferring Types by Mining Class Usage Frequency from Inline Caches
Inferring Types by Mining Class Usage Frequency from Inline CachesInferring Types by Mining Class Usage Frequency from Inline Caches
Inferring Types by Mining Class Usage Frequency from Inline Caches
ESUG
 

Mais procurados (18)

Gc algorithms
Gc algorithmsGc algorithms
Gc algorithms
 
Garbage Collection of Java VM
Garbage Collection of Java VMGarbage Collection of Java VM
Garbage Collection of Java VM
 
Lab 12 08_15
Lab 12 08_15Lab 12 08_15
Lab 12 08_15
 
Progress_190213
Progress_190213Progress_190213
Progress_190213
 
Solving Multi-tenancy and G1GC in Apache HBase
Solving Multi-tenancy and G1GC in Apache HBase Solving Multi-tenancy and G1GC in Apache HBase
Solving Multi-tenancy and G1GC in Apache HBase
 
Scaling Islandora
Scaling IslandoraScaling Islandora
Scaling Islandora
 
Test for 'Libre Office' format support
Test for 'Libre Office' format supportTest for 'Libre Office' format support
Test for 'Libre Office' format support
 
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
 
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
 
Mario on spark
Mario on sparkMario on spark
Mario on spark
 
Java at Scale, Dallas JUG, October 2013
Java at Scale, Dallas JUG, October 2013Java at Scale, Dallas JUG, October 2013
Java at Scale, Dallas JUG, October 2013
 
Inferring Types by Mining Class Usage Frequency from Inline Caches
Inferring Types by Mining Class Usage Frequency from Inline CachesInferring Types by Mining Class Usage Frequency from Inline Caches
Inferring Types by Mining Class Usage Frequency from Inline Caches
 
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...
 
J9 Balanced GC
J9 Balanced GCJ9 Balanced GC
J9 Balanced GC
 

Destaque

Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and Tuning
Carol McDonald
 

Destaque (16)

[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Jvm internals 2015 - CorkJUG
Jvm internals 2015 - CorkJUGJvm internals 2015 - CorkJUG
Jvm internals 2015 - CorkJUG
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
Java Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
Java Garbage Collectors – Moving to Java7 Garbage First (G1) CollectorJava Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
Java Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
 
Java Garbage Collection
Java Garbage CollectionJava Garbage Collection
Java Garbage Collection
 
Notes for xx_use_serialgc
Notes for xx_use_serialgcNotes for xx_use_serialgc
Notes for xx_use_serialgc
 
DC JUG: Understanding Java Garbage Collection
DC JUG: Understanding Java Garbage CollectionDC JUG: Understanding Java Garbage Collection
DC JUG: Understanding Java Garbage Collection
 
An efficient memory system for java Garbage Collection
An efficient memory system for java Garbage CollectionAn efficient memory system for java Garbage Collection
An efficient memory system for java Garbage Collection
 
JVM Internals (2015)
JVM Internals (2015)JVM Internals (2015)
JVM Internals (2015)
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About It
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage Collection
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
3장. Garbage Collection
3장. Garbage Collection3장. Garbage Collection
3장. Garbage Collection
 
Understanding JVM
Understanding JVMUnderstanding JVM
Understanding JVM
 
Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and Tuning
 
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
Concurrent Mark-Sweep Garbage Collection #jjug_cccConcurrent Mark-Sweep Garbage Collection #jjug_ccc
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
 

Semelhante a Taming Java Garbage Collector

Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
Tier1 App
 
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Jayesh Thakrar
 

Semelhante a Taming Java Garbage Collector (20)

Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
this-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptxthis-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptx
 
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...
 
JVM Magic
JVM MagicJVM Magic
JVM Magic
 
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
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?
 
millions-gc-jax-2022.pptx
millions-gc-jax-2022.pptxmillions-gc-jax-2022.pptx
millions-gc-jax-2022.pptx
 
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!
 
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
 
Temadag om-java-jamaica vm-2013-09
Temadag om-java-jamaica vm-2013-09Temadag om-java-jamaica vm-2013-09
Temadag om-java-jamaica vm-2013-09
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimization
 
Software Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and FlamegraphsSoftware Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and Flamegraphs
 
Java Performance and Using Java Flight Recorder
Java Performance and Using Java Flight RecorderJava Performance and Using Java Flight Recorder
Java Performance and Using Java Flight Recorder
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
 
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
 
Use Ruby GC in full..
Use Ruby GC in full..Use Ruby GC in full..
Use Ruby GC in full..
 
DIY Java Profiler
DIY Java ProfilerDIY Java Profiler
DIY Java Profiler
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Taming Java Garbage Collector

  • 2.
  • 3. Why Learn Garbage Collection? To select a GC algorithm To performance debug applications To become a better programmer
  • 4. Summary How Java garbage collectors work How to monitor and tune GC How to write GC friendly Java code
  • 5. Dynamic Memory Allocation Fortran77: No Dynamic Memory C: Dynamic Memory managed by programmer. malloc() / free() Java: Dynamic Memory managed by JVM, i.e. Java GC
  • 6.
  • 7. Weak Generational Hypothesis Most objects die young. Only few references from old objects to young objects.
  • 8. All Apples in One Basket?
  • 11. Old Gen and Compaction
  • 12. Stop The World (STW)
  • 13. Concurrent Mark-Sweep (CMS) Old gen is collected concurrently 1. STW, Mark roots 2. Mark concurrently with application 3. STW, mark again to catch up 4. Sweep
  • 14. CMS
  • 15. CMS Pros and Cons Reduces pause Does not collect all garbage. Leaves the heap fragmented so allocation is more expensive. CMS failures. Needs more heap. Steals threads and CPU from application.
  • 17. GC Tuning Use GC logging options with JVM -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamp
  • 18. GC Tuning 6.255: [GC [PSYoungGen: 132532K-16412K(278912K)] 141408K->25289K(453696K), 0.013 secs] [Times: user=0.08 sys=0.01, real=0.01 secs] 6.269: [Full GC (System) [PSYoungGen: 16412K->0K(278912K)] [PSOldGen: 8876K->24956K(174784K)] 25289K->24956K(453696K) [PSPermGen: 60341K->60341K(120960K)], 0.153 secs] [Times: user=0.16 sys=0.00, real=0.16 secs]
  • 19. GC Monitoring Use tools to visualize GC activity Some such tools: JConsole JStat VisualVM (with GC extension)
  • 20. Some Important Parameters GC - The garbage collector in use. Size of the Java heap. Size of the young and old generation spaces. Duration of minor garbage collections. Frequency of minor garbage collections. Duration of full garbage collections. Frequency of full garbage collections. What initiates full GC; old gen or perm space.
  • 21. Attributes of Java Performance Pause Time: Minimal pause time due to GC Throughput: Overall performance of user process ignoring pauses due to GC Footprint: Amount of memory required for GC to run efficiently
  • 22. GC Friendly Coding GCs love small, immutable, short-lived objects Object pooling is usually bad Large objects are expensive to allocate, expensive to initialize and may fragment CMS Nulling references is usually bad Avoid finalize() Avoid calling System.gc() Avoid memory Leaks Some sources: Objects in the wrong scope Instances of inner classes