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

What's hot (20)

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

Viewers also liked (9)

PDF
CTG-AnnualReport-2014_LR
Barbara Toorens
 
PDF
PLANO DE ENSINO 2014.2 (1).pdf
filipe3636
 
PDF
M Jouni_Achievments report
Mohammad Jouni
 
PPTX
Presentación1festival
Jorge Afanador
 
PDF
Lessons and Challenges from Mining Retail E-Commerce Data
Kun Le
 
PPTX
Ganglios y nervios cervicales veterinaria
Eve Arii
 
PPTX
Fissura lábio palatina
Adhonias Moura
 
PPTX
Vida y obra
MaFe Diaz
 
CTG-AnnualReport-2014_LR
Barbara Toorens
 
PLANO DE ENSINO 2014.2 (1).pdf
filipe3636
 
M Jouni_Achievments report
Mohammad Jouni
 
Presentación1festival
Jorge Afanador
 
Lessons and Challenges from Mining Retail E-Commerce Data
Kun Le
 
Ganglios y nervios cervicales veterinaria
Eve Arii
 
Fissura lábio palatina
Adhonias Moura
 
Vida y obra
MaFe Diaz
 
Ad

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

PDF
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
Jelastic Multi-Cloud PaaS
 
PPTX
Jvm Architecture
ThirupathiReddy Vajjala
 
PDF
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
PDF
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
 
PPT
Performance tuning jvm
Prem Kuppumani
 
PPT
Jvm Performance Tunning
Terry Cho
 
PPT
Jvm Performance Tunning
guest1f2740
 
PDF
Software Profiling: Java Performance, Profiling and Flamegraphs
Isuru Perera
 
PDF
Mastering java in containers - MadridJUG
Jorge Morales
 
PPTX
Java 어플리케이션 성능튜닝 Part1
상욱 송
 
PPTX
JVM Magic
Baruch Sadogursky
 
PPTX
7-JVM-arguments-JaxLondon-2023.pptx
Tier1 app
 
PDF
OpenDS_Jazoon2010
Ludovic Poitou
 
PDF
JVM Performance Tuning
Jeremy Leisy
 
PDF
Basics of JVM Tuning
Vladislav Gangan
 
PPTX
7 jvm-arguments-Confoo
Tier1 app
 
PPTX
Java performance tuning
Mohammed Fazuluddin
 
PDF
Software Profiling: Understanding Java Performance and how to profile in Java
Isuru Perera
 
PDF
DevoxxUK: Optimizating Application Performance on Kubernetes
Dinakar Guniguntala
 
DOC
weblogic perfomence tuning
prathap kumar
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
Jelastic Multi-Cloud PaaS
 
Jvm Architecture
ThirupathiReddy Vajjala
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
 
Performance tuning jvm
Prem Kuppumani
 
Jvm Performance Tunning
Terry Cho
 
Jvm Performance Tunning
guest1f2740
 
Software Profiling: Java Performance, Profiling and Flamegraphs
Isuru Perera
 
Mastering java in containers - MadridJUG
Jorge Morales
 
Java 어플리케이션 성능튜닝 Part1
상욱 송
 
7-JVM-arguments-JaxLondon-2023.pptx
Tier1 app
 
OpenDS_Jazoon2010
Ludovic Poitou
 
JVM Performance Tuning
Jeremy Leisy
 
Basics of JVM Tuning
Vladislav Gangan
 
7 jvm-arguments-Confoo
Tier1 app
 
Java performance tuning
Mohammed Fazuluddin
 
Software Profiling: Understanding Java Performance and how to profile in Java
Isuru Perera
 
DevoxxUK: Optimizating Application Performance on Kubernetes
Dinakar Guniguntala
 
weblogic perfomence tuning
prathap kumar
 
Ad

More from Anna Shymchenko (20)

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

Recently uploaded (20)

PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally software_Introduction_Presentation
AditiBansal54083
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 

Вячеслав Блинов «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