SlideShare a Scribd company logo
Java Garbage Collection: 
A Performance Impact 
Blynov Viacheslav 
Lead Software Developer 
24 November 2014 
www.luxoft.com
Introduction 
www.luxoft.com
Introduction 
Agenda 
 Garbage Collection Overview 
 Java GC Algorithms 
 Basic GC Tuning 
www.luxoft.com
www.luxoft.com
GC Purpose 
Objects that are referenced are said to be live 
Objects that are no longer referenced are considered dead and termed garbage 
Garbage collector is responsible for: 
 allocating memory 
 ensuring that any referenced objects remain in memory 
 recovering memory used by objects that are no longer reachable from references in 
executing code 
www.luxoft.com
www.luxoft.com
GC performance impact 
 Collector needs computational resources (CPU cycles) to perform garbage collection 
 As garbage collection involves moving objects in memory a collector must ensure that no 
thread is using these objects 
www.luxoft.com 
The pauses when all application threads are stopped are called 
stop-the-world pauses 
These pauses generally have the greatest impact on the performance of an application, and 
minimizing those pauses is the key consideration when tuning GC.
Generational model 
www.luxoft.com
Generational model 
www.luxoft.com
Generational model 
www.luxoft.com
Generational model 
www.luxoft.com
Generational model 
www.luxoft.com
Generational model 
www.luxoft.com
Summary 
 all GC algorithms divide the heap into old and young generation 
 all GC algorithm employ stop-the-world approach to clearing objects from 
young generation, which is usually a very quick operation 
www.luxoft.com
www.luxoft.com
“Client” and “Server” JVM types 
Depending on underlying hardware platform and version 
JVM can act as “client” of “server” VM. This affect the 
choice of JIT compiler and default GC algorithm. 
 “client” platform is usually 32-bit and has 1 CPU 
 “server” platform is usually 64-bit (but 32-bit is also 
possible) and has several CPUs 
www.luxoft.com
GC Algorithms 
 Serial garbage collector (-XX:+UseSerialGC) 
 Throughput collector (-XX:+UseParallelGC , -XX:+UseParallelOldGC) 
 CMS collector (-XX:+UseConcMarkSweepGC, -XX:+UseParNewGC) 
 G1 collector (-XX:+UseG1GC) 
www.luxoft.com
Serial garbage collector 
 default collector for client-class platforms (32-bit JVMs on Windows or single-processor 
www.luxoft.com 
machines) 
 uses single thread to process heap 
 stops all application threads for both minor and full GC 
Usage cases: 
 no low-pause requirements 
 “client-style” single-CPU environment 
 very small heap (few hundred MBs) 
 several JVMs running on single platform (number of JVM > number of 
available CPUs)
Throughput (parallel) garbage collector 
 default collector for server-class machines (multi-CPU Unix machines or any 64-bit JVM) 
 utilizes multiple threads for garbage collection to gain speed and minimize pauses 
 stops all application threads for both minor and full GC 
 -XX:+UseParallelGC enables multi-threaded collection of young generation and single-threaded 
www.luxoft.com 
old-generation collection/compaction 
 -XX:+UseParallelOldGC enables multi-threaded collection of young generation and multi-threaded 
old-generation collection/compaction 
Usage cases: 
 multi-CPU are available 
 large heap size and many object created/discarded
CMS (Concurrent Mark Sweep) collector 
 designed to eliminate long pauses associated with full GC cycles 
 stops all application threads during minor GC 
 uses different algorithm to collect young generation (-XX:+UseParNewGC) 
 uses one or more background threads to periodically scan through the old generation and discard 
unused objects. This makes CMS a low-paused collector 
 do not perform any compaction 
 in case of CPU unavailability and/or heap fragmentation – fallback to serial collector 
 by default does not collect permgen 
Usage cases: 
 low pause requirement and available CPU resources 
 in case of single-CPU machine can be used with -XX:+CMSIncrementalMode (deprecated in Java 
8) 
www.luxoft.com
G1 (Garbage First) garbage collector 
 designed to process large heaps (more than 4 Gb) with minimal pauses 
 divides the heap into separate regions 
 performs incremental compaction of old generation by copying data between 
regions 
www.luxoft.com
G1 (Garbage First) garbage collector 
www.luxoft.com
Summary (choosing GC algorithm) 
 Serial GC is best only for application with heap <= 100 Mb 
 Batch jobs which consume all available CPUs will get better performance 
with concurrent collector 
 Batch jobs which DON’T consume all CPUs could get better performance 
with throughput collector 
 When measuring response time the choice between throughput and 
concurrent collectors depends on CPU availability 
 Most of the time CMS should overperform G1 for heaps < 4 Gb 
 For large heaps G1 is better because of the way it can divide work between 
different threads and heap regions 
www.luxoft.com
www.luxoft.com
Sizing the heap 
 Too small heap -> too much time spent in GC 
 Main rule – never to specify heap more than the amount of available physical 
memory 
 -Xms – initial heap size 
 -Xmx – maximum heap size 
www.luxoft.com
Sizing the Generations 
 -XX:NewRatio=N – sets the ration of young generation to old 
 -XX:NewSize=N – sets the size of young generation 
 -XX:MaxNewSize=N – maximum size for young generation 
www.luxoft.com
Sizing Permgen and Metaspace 
Java 7: 
 -XX:PermSize=N 
 -XX:MaxPermSize=N 
Java 8: 
 -XX:MetaspaceSize=N 
 -XX:MaxMetaspaceSize=N 
www.luxoft.com
Adaptive Sizing 
JVM can try to find optimal performance according to its policies and configuration 
 Adaptive sizing controls how the JVM alters the ratio of young generation to old 
 Adjusting generation sizes is base on GC algorithms attempts to meet their pause goals 
 Adaptive tuning can be disabled for small performance boost (usually not recommended) 
 Command line argument differs for different GC algorithms. For, example for throughput collector: 
-XX:+UseAdaptiveSizePolicy – whether to use adaptive policy (true by default) 
-XX:MaxGCPauseMillis=nnn – maximal GC pause we can tolerate 
-XX:GCTimeRatio=nnn - hint to the virtual machine that it's desirable that not more than 1 / (1 + nnn) of the 
application execution time be spent in the collector 
www.luxoft.com
THANK YOU 
www.luxoft.com

More Related Content

PPTX
Java gc and JVM optimization
PPTX
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
ODP
Java GC, Off-heap workshop
PDF
JVM Tuning and Profiling
PDF
Scaling Islandora
PPTX
JVM memory management & Diagnostics
ODP
Hotspot gc
PDF
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Java gc and JVM optimization
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Java GC, Off-heap workshop
JVM Tuning and Profiling
Scaling Islandora
JVM memory management & Diagnostics
Hotspot gc
Keeping Latency Low and Throughput High with Application-level Priority Manag...

What's hot (20)

PPT
Taming Java Garbage Collector
PDF
Scaling Apache Pulsar to 10 Petabytes/Day
PDF
Revisão: Forwarding Metamorphosis: Fast Programmable Match-Action Processing ...
PPT
Health Check Your DB2 UDB For Z/OS System
PDF
Distributed scheduler hell (MicroXChg 2017 Berlin)
PPTX
Building a Better JVM
PDF
Taming The JVM
PDF
Tools for Metaspace
PPTX
HotSpot JVM Tuning
PDF
DB Latency Using DRAM + PMem in App Direct & Memory Modes
PPT
Linux kernel memory allocators
PDF
JVM and Garbage Collection Tuning
PDF
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
PDF
Continuous Go Profiling & Observability
PPTX
Jvm problem diagnostics
KEY
Jvm gc那点事
PDF
OSNoise Tracer: Who Is Stealing My CPU Time?
PDF
Data Structures for High Resolution, Real-time Telemetry at Scale
PPT
CRAMM: Virtual Memory Support for Garbage-Collected Applications
PDF
Where Did All These Cycles Go?
Taming Java Garbage Collector
Scaling Apache Pulsar to 10 Petabytes/Day
Revisão: Forwarding Metamorphosis: Fast Programmable Match-Action Processing ...
Health Check Your DB2 UDB For Z/OS System
Distributed scheduler hell (MicroXChg 2017 Berlin)
Building a Better JVM
Taming The JVM
Tools for Metaspace
HotSpot JVM Tuning
DB Latency Using DRAM + PMem in App Direct & Memory Modes
Linux kernel memory allocators
JVM and Garbage Collection Tuning
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Continuous Go Profiling & Observability
Jvm problem diagnostics
Jvm gc那点事
OSNoise Tracer: Who Is Stealing My CPU Time?
Data Structures for High Resolution, Real-time Telemetry at Scale
CRAMM: Virtual Memory Support for Garbage-Collected Applications
Where Did All These Cycles Go?
Ad

Viewers also liked (9)

PDF
CTG-AnnualReport-2014_LR
PDF
PLANO DE ENSINO 2014.2 (1).pdf
PDF
M Jouni_Achievments report
PPTX
Presentación1festival
PDF
Lessons and Challenges from Mining Retail E-Commerce Data
PPTX
Ganglios y nervios cervicales veterinaria
PPTX
Fissura lábio palatina
PPTX
Vida y obra
CTG-AnnualReport-2014_LR
PLANO DE ENSINO 2014.2 (1).pdf
M Jouni_Achievments report
Presentación1festival
Lessons and Challenges from Mining Retail E-Commerce Data
Ganglios y nervios cervicales veterinaria
Fissura lábio palatina
Vida y obra
Ad

Similar to Вячеслав Блинов «Java Garbage Collection: A Performance Impact» (20)

PDF
Performance Tuning - Understanding Garbage Collection
PDF
[BGOUG] Java GC - Friend or Foe
PDF
Java Garbage Collection - How it works
PDF
Let's talk about Garbage Collection
ODP
Garbage collection
PDF
[Jbcn 2016] Garbage Collectors WTF!?
PDF
HBaseCon 2015: Taming GC Pauses for Large Java Heap in HBase
PPTX
PDF
GC Tuning Confessions Of A Performance Engineer
PDF
Introduction to Garbage Collection
PDF
Java at Scale, Dallas JUG, October 2013
PDF
Low latency Java apps
PPTX
G1 Garbage Collector - Big Heaps and Low Pauses?
PDF
Introduction of Java GC Tuning and Java Java Mission Control
PDF
JVM Garbage Collection Tuning
PDF
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
PPTX
Memory Management in the Java Virtual Machine(Garbage collection)
PDF
What you need to know about GC
PDF
Jvm is-your-friend
PDF
The JVM is your friend
Performance Tuning - Understanding Garbage Collection
[BGOUG] Java GC - Friend or Foe
Java Garbage Collection - How it works
Let's talk about Garbage Collection
Garbage collection
[Jbcn 2016] Garbage Collectors WTF!?
HBaseCon 2015: Taming GC Pauses for Large Java Heap in HBase
GC Tuning Confessions Of A Performance Engineer
Introduction to Garbage Collection
Java at Scale, Dallas JUG, October 2013
Low latency Java apps
G1 Garbage Collector - Big Heaps and Low Pauses?
Introduction of Java GC Tuning and Java Java Mission Control
JVM Garbage Collection Tuning
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Memory Management in the Java Virtual Machine(Garbage collection)
What you need to know about GC
Jvm is-your-friend
The JVM is your friend

More from Anna Shymchenko (20)

PPTX
Константин Маркович: "Creating modular application using Spring Boot "
PPTX
Евгений Бова: "Modularity in Java: introduction to Jigsaw through the prism o...
PPTX
Евгений Руднев: "Programmers Approach to Error Handling"
PPTX
Александр Куцан: "Static Code Analysis in C++"
PPTX
Алесей Решта: “Robotics Sport & Luxoft Open Robotics Club”
PPTX
Орхан Гасимов: "Reactive Applications in Java with Akka"
PPTX
Евгений Хыст: "Server-Side Geo-Clustering Based on Geohash"
PPTX
Денис Прокопюк: “JMX in Java EE applications”
PDF
Роман Яворский "Introduction to DevOps"
PDF
Максим Сабарня “NoSQL: Not only SQL in developer’s life”
PDF
Андрей Лисниченко "SQL Injection"
PPTX
Светлана Мухина "Metrics on agile projects"
PPTX
Андрей Слободяник "Test driven development using mockito"
PPTX
Евгений Хыст "Application performance database related problems"
PPTX
Даурен Муса “IBM WebSphere - expensive but effective”
PPTX
Александр Пашинский "Reinventing Design Patterns with Java 8"
PPTX
Евгений Капинос "Advanced JPA (Java Persistent API)"
PPTX
Event-driven architecture with Java technology stack
PPTX
Do we need SOLID principles during software development?
PPTX
Guava - Elements of Functional Programming
Константин Маркович: "Creating modular application using Spring Boot "
Евгений Бова: "Modularity in Java: introduction to Jigsaw through the prism o...
Евгений Руднев: "Programmers Approach to Error Handling"
Александр Куцан: "Static Code Analysis in C++"
Алесей Решта: “Robotics Sport & Luxoft Open Robotics Club”
Орхан Гасимов: "Reactive Applications in Java with Akka"
Евгений Хыст: "Server-Side Geo-Clustering Based on Geohash"
Денис Прокопюк: “JMX in Java EE applications”
Роман Яворский "Introduction to DevOps"
Максим Сабарня “NoSQL: Not only SQL in developer’s life”
Андрей Лисниченко "SQL Injection"
Светлана Мухина "Metrics on agile projects"
Андрей Слободяник "Test driven development using mockito"
Евгений Хыст "Application performance database related problems"
Даурен Муса “IBM WebSphere - expensive but effective”
Александр Пашинский "Reinventing Design Patterns with Java 8"
Евгений Капинос "Advanced JPA (Java Persistent API)"
Event-driven architecture with Java technology stack
Do we need SOLID principles during software development?
Guava - Elements of Functional Programming

Recently uploaded (20)

PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Nekopoi APK 2025 free lastest update
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
medical staffing services at VALiNTRY
PDF
AI in Product Development-omnex systems
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
L1 - Introduction to python Backend.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
System and Network Administraation Chapter 3
PPTX
Introduction to Artificial Intelligence
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PTS Company Brochure 2025 (1).pdf.......
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Nekopoi APK 2025 free lastest update
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
AI in Product Development-omnex systems
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Reimagine Home Health with the Power of Agentic AI​
L1 - Introduction to python Backend.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
System and Network Administraation Chapter 3
Introduction to Artificial Intelligence
Internet Downloader Manager (IDM) Crack 6.42 Build 41

Вячеслав Блинов «Java Garbage Collection: A Performance Impact»

  • 1. Java Garbage Collection: A Performance Impact Blynov Viacheslav Lead Software Developer 24 November 2014 www.luxoft.com
  • 3. Introduction Agenda  Garbage Collection Overview  Java GC Algorithms  Basic GC Tuning www.luxoft.com
  • 5. GC Purpose Objects that are referenced are said to be live Objects that are no longer referenced are considered dead and termed garbage Garbage collector is responsible for:  allocating memory  ensuring that any referenced objects remain in memory  recovering memory used by objects that are no longer reachable from references in executing code www.luxoft.com
  • 7. GC performance impact  Collector needs computational resources (CPU cycles) to perform garbage collection  As garbage collection involves moving objects in memory a collector must ensure that no thread is using these objects www.luxoft.com The pauses when all application threads are stopped are called stop-the-world pauses These pauses generally have the greatest impact on the performance of an application, and minimizing those pauses is the key consideration when tuning GC.
  • 14. Summary  all GC algorithms divide the heap into old and young generation  all GC algorithm employ stop-the-world approach to clearing objects from young generation, which is usually a very quick operation www.luxoft.com
  • 16. “Client” and “Server” JVM types Depending on underlying hardware platform and version JVM can act as “client” of “server” VM. This affect the choice of JIT compiler and default GC algorithm.  “client” platform is usually 32-bit and has 1 CPU  “server” platform is usually 64-bit (but 32-bit is also possible) and has several CPUs www.luxoft.com
  • 17. GC Algorithms  Serial garbage collector (-XX:+UseSerialGC)  Throughput collector (-XX:+UseParallelGC , -XX:+UseParallelOldGC)  CMS collector (-XX:+UseConcMarkSweepGC, -XX:+UseParNewGC)  G1 collector (-XX:+UseG1GC) www.luxoft.com
  • 18. Serial garbage collector  default collector for client-class platforms (32-bit JVMs on Windows or single-processor www.luxoft.com machines)  uses single thread to process heap  stops all application threads for both minor and full GC Usage cases:  no low-pause requirements  “client-style” single-CPU environment  very small heap (few hundred MBs)  several JVMs running on single platform (number of JVM > number of available CPUs)
  • 19. Throughput (parallel) garbage collector  default collector for server-class machines (multi-CPU Unix machines or any 64-bit JVM)  utilizes multiple threads for garbage collection to gain speed and minimize pauses  stops all application threads for both minor and full GC  -XX:+UseParallelGC enables multi-threaded collection of young generation and single-threaded www.luxoft.com old-generation collection/compaction  -XX:+UseParallelOldGC enables multi-threaded collection of young generation and multi-threaded old-generation collection/compaction Usage cases:  multi-CPU are available  large heap size and many object created/discarded
  • 20. CMS (Concurrent Mark Sweep) collector  designed to eliminate long pauses associated with full GC cycles  stops all application threads during minor GC  uses different algorithm to collect young generation (-XX:+UseParNewGC)  uses one or more background threads to periodically scan through the old generation and discard unused objects. This makes CMS a low-paused collector  do not perform any compaction  in case of CPU unavailability and/or heap fragmentation – fallback to serial collector  by default does not collect permgen Usage cases:  low pause requirement and available CPU resources  in case of single-CPU machine can be used with -XX:+CMSIncrementalMode (deprecated in Java 8) www.luxoft.com
  • 21. G1 (Garbage First) garbage collector  designed to process large heaps (more than 4 Gb) with minimal pauses  divides the heap into separate regions  performs incremental compaction of old generation by copying data between regions www.luxoft.com
  • 22. G1 (Garbage First) garbage collector www.luxoft.com
  • 23. Summary (choosing GC algorithm)  Serial GC is best only for application with heap <= 100 Mb  Batch jobs which consume all available CPUs will get better performance with concurrent collector  Batch jobs which DON’T consume all CPUs could get better performance with throughput collector  When measuring response time the choice between throughput and concurrent collectors depends on CPU availability  Most of the time CMS should overperform G1 for heaps < 4 Gb  For large heaps G1 is better because of the way it can divide work between different threads and heap regions www.luxoft.com
  • 25. Sizing the heap  Too small heap -> too much time spent in GC  Main rule – never to specify heap more than the amount of available physical memory  -Xms – initial heap size  -Xmx – maximum heap size www.luxoft.com
  • 26. Sizing the Generations  -XX:NewRatio=N – sets the ration of young generation to old  -XX:NewSize=N – sets the size of young generation  -XX:MaxNewSize=N – maximum size for young generation www.luxoft.com
  • 27. Sizing Permgen and Metaspace Java 7:  -XX:PermSize=N  -XX:MaxPermSize=N Java 8:  -XX:MetaspaceSize=N  -XX:MaxMetaspaceSize=N www.luxoft.com
  • 28. Adaptive Sizing JVM can try to find optimal performance according to its policies and configuration  Adaptive sizing controls how the JVM alters the ratio of young generation to old  Adjusting generation sizes is base on GC algorithms attempts to meet their pause goals  Adaptive tuning can be disabled for small performance boost (usually not recommended)  Command line argument differs for different GC algorithms. For, example for throughput collector: -XX:+UseAdaptiveSizePolicy – whether to use adaptive policy (true by default) -XX:MaxGCPauseMillis=nnn – maximal GC pause we can tolerate -XX:GCTimeRatio=nnn - hint to the virtual machine that it's desirable that not more than 1 / (1 + nnn) of the application execution time be spent in the collector www.luxoft.com