SlideShare uma empresa Scribd logo
1 de 47
Baixar para ler offline
What you need to know about
GC
Java SE 6 HotSpot™ VM
K e l u m S e n a n a y a k e
High Level Agenda
• Introduction
• Generations
• Collectors
• Other Considerations
Introduction
Java is everywhere…
• Java™ Platform, Standard Edition (Java SE™) is
used for a wide variety of applications.
• JVM provides multiple garbage collectors,
each designed to satisfy different
requirements
Why memory?
• One strength of the J2SE platform is that it
shields the developer from the complexity of
memory allocation and garbage collection.
• However, once garbage collection is the
principal bottleneck, it is worth understanding
some aspects of this hidden implementation.
• When does the choice of a garbage collector
matter?
– For some applications, the answer is never
• Application can perform well in the presence of
garbage collection with pauses of modest frequency
and duration
– However, this is not the case for a large class of
applications
Generations
Garbage ?
Garbage Collection… How?
• The most straightforward garbage collection
algorithms simply iterate over every reachable
object.
– The time this approach takes is proportional to
the number of live objects
• “Weak generational hypothesis”
– “most objects survive for only a short period of
time”
Weak generational hypothesis
• Memory is managed in Generations
• Memory pools holding objects of different
ages
JVM Heap Layout
JVM Heap Layout
JVM Heap Layout
JVM Heap Layout
Performance Considerations
• Throughput
– is the percentage of total time not spent in
garbage collection, considered over long periods
of time
• Pauses
– are the times when an application appears
unresponsive because garbage collection is
occurring.
• A web server vs an interactive graphics
program
Performance…
• Footprint
– is the working set of a process, measured in pages and
cache lines
• Promptness
– is the time between when an object becomes dead
and when the memory becomes available
• In general, a particular generation sizing chooses
a trade-off between these considerations.
Performance…
• A very large young generation
– maximize throughput
– at the expense of footprint, promptness and
pause times.
• A small young generation
– young generation pauses can be minimized
– at the expense of throughput
Measurement
• -verbose:gc
information about the heap and garbage collection
to be printed at each collection.
[GC 325407K->83000K(776768K), 0.2300771 secs]
[GC 325816K->83372K(776768K), 0.2454258 secs]
[Full GC 267628K->83769K(776768K), 1.8479984 secs]
Measurement…
• -XX:+PrintGCDetails
[GC [DefNew: 64575K->959K(64576K), 0.0457646 secs]
196016K->133633K(261184K), 0.0459067 secs]
• -XX:+PrintGCTimeStamps
111.042: [GC 111.042: [DefNew: 8128K->8128K(8128K),
0.0000505 secs]111.042: [Tenured: 18154K->2311K(24576K),
0.1290354 secs] 26282K->2311K(32704K), 0.1293306 secs]
Sizing the Generations
• -Xms : initial sizes of the heap
• -Xmx : maximum sizes of the heap
• Collections occur when generations fill up
– Throughput is inversely proportional to the
amount of memory available
Sizing…
• By default, the virtual machine grows or
shrinks the heap at each collection to try to
keep the proportion of free space to live
objects at each collection within a specific
range
• -XX:MinHeapFreeRatio=<minimum>
• -XX:MaxHeapFreeRatio=<maximum>
Sizing…
MinHeapFreeRatio 40
MaxHeapFreeRatio 70
-Xms 3670k
-Xmx 64m
If the percent of free space in a generation falls below 40%, the generation will be
expanded to maintain 40% free space, up to the maximum allowed size of the
generation.
If the free space exceeds 70%, the generation will be contracted so that only 70% of
the space is free, subject to the minimum size of the generation.
The Young Generation
• The second most influential knob is the
proportion of the heap dedicated to the young
generation.
– The bigger the young generation, the less often
minor collections occur.
– Larger young generation implies a smaller tenured
generation (for a bounded heap size)
– will increase the frequency of major collections
• -XX:NewRatio : Defines the ratio between
the young and tenured generation
ex: -XX:NewRatio=3
• You can even decide the initial and max sizes
of the young space with parameters
NewSize and MaxNewSize
Survivor Space Sizing
• SurvivorRatio : can be used to tune the
size of the survivor spaces
• Sets the ratio between eden and a survivor
space
• This is often not as important for performance
• -XX:SurvivorRatio=6
• If survivor spaces are too small, copying
collection overflows directly into the tenured
generation.
• If survivor spaces are too large, they will be
uselessly empty.
Available Collectors
The serial collector
• Uses a single thread to perform all garbage
collection work
– No communication overhead between threads
– Best-suited to single processor machines
– Multiprocessors for applications with small data
sets (up to approximately 100MB)
• -XX:+UseSerialGC
The parallel collector
• a.k.a throughput collector
• Performs minor collections in parallel
• Medium- to large-sized data sets that are run
on multiprocessor or multi-threaded
hardware.
• -XX:+UseParallelGC
• -XX:+UseParallelOldGC
Parallel collector…
• Select the parallel collector if,
– Peak application performance is the first priority
– There are no pause time requirements or pauses
of one second or longer are acceptable
• On a machine with N processors the parallel
collector uses N garbage collector threads
• -XX:ParallelGCThreads=<N>
• -XX:MaxGCPauseMillis=<N>
– a hint that pause times of <N> milliseconds or less
are desired
• -XX:GCTimeRatio=<N>
– Sets the ratio of garbage collection time to
application time to 1 / (1 + <N>)
– -XX:GCTimeRatio=19 sets a goal of 1/20 or
5% of the total time in garbage collection.
Generation Size Adjustments
• Growing and shrinking are done at different rates
• By default a generation grows in increments of
20% and shrinks in increments of 5%.
-XX:YoungGenerationSizeIncrement=<Y> for the
young generation
-XX:TenuredGenerationSizeIncrement=<T> for the
tenured generation
-XX:AdaptiveSizeDecrementScaleFactor=<D>
If the growth increment is X percent, the decrement for
shrinking is X / D percent
The Concurrent Collector
• Select concurrent collector If
– response time is more important than overall
throughput
– garbage collection pauses must be kept shorter than
approximately one second
• Suitable for
– applications which have a relatively large set of long-
lived data (a large tenured generation)
– run on machines with two or more processors
• -XX:+UseConcMarkSweepGC
Steps of Concurrent Collection
1. Stop all application threads and identify the set of objects
reachable from roots, then resume all application threads
2. Concurrently trace the reachable object graph, using one or more
processors, while the application threads are executing
3. Concurrently retrace sections of the object graph that were
modified since the tracing in the previous step, using one
processor
4. Stop all application threads and retrace sections of the roots and
object graph that may have been modified since they were last
examined, then resume all application threads
5. Concurrently sweep up the unreachable objects to the free lists
used for allocation, using one processor
6. Concurrently resize the heap and prepare the support data
structures for the next collection cycle, using one processor
Starting a Concurrent Collection Cycle
• Serial collector
– A major collection occurs whenever the tenured
generation becomes full
– all application threads are stopped while the
collection is done.
– stop-the-world condition
• concurrent collector
– starts at a time such that the collection can finish
before the tenured generation becomes full
Starting…
• Concurrent collector maintains dynamic
estimates based on recent history
• A concurrent collection will also start if the
occupancy of the tenured generation exceeds
an initiating occupancy
• -XX:CMSInitiatingOccupancyFraction=<N>
– <N> is an integral percentage (0-100) of the
tenured generation size.
Incremental Mode
• Normally, the concurrent collector uses one or
more processors during the entire concurrent
tracing phase, without voluntarily releasing them.
• Also, one processor is used for the entire
concurrent sweep phase, again without releasing
it.
• Incremental mode solves this problem by
breaking up the concurrent phases into short
bursts of activity, which are scheduled to occur
mid-way between minor pauses.
[GC [1 CMS-initial-mark: 13991K(20288K)] 14103K(22400K), 0.0023781 secs]
[GC [DefNew: 2112K->64K(2112K), 0.0837052 secs] 16103K->15476K(22400K), 0.0838519
secs]
...
[GC [DefNew: 2077K->63K(2112K), 0.0126205 secs] 17552K->15855K(22400K), 0.0127482
secs]
[CMS-concurrent-mark: 0.267/0.374 secs]
[GC [DefNew: 2111K->64K(2112K), 0.0190851 secs] 17903K->16154K(22400K), 0.0191903
secs]
[CMS-concurrent-preclean: 0.044/0.064 secs]
[GC [1 CMS-remark: 16090K(20288K)] 17242K(22400K), 0.0210460 secs]
[GC [DefNew: 2112K->63K(2112K), 0.0716116 secs] 18177K->17382K(22400K), 0.0718204
secs]
[GC [DefNew: 2111K->63K(2112K), 0.0830392 secs] 19363K->18757K(22400K), 0.0832943
secs]
...
[GC [DefNew: 2111K->0K(2112K), 0.0035190 secs] 17527K->15479K(22400K), 0.0036052 secs]
[CMS-concurrent-sweep: 0.291/0.662 secs]
[GC [DefNew: 2048K->0K(2112K), 0.0013347 secs] 17527K->15479K(27912K), 0.0014231 secs]
[CMS-concurrent-reset: 0.016/0.016 secs]
[GC [DefNew: 2048K->1K(2112K), 0.0013936 secs] 17527K->15479K(27912K), 0.0014814 secs]
Incremental Mode…
• Recommended Options
– To use i-cms in Java SE 6, use the following
command line options:
-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode
Excessive GC Time and OutOfMemoryError
• Parallel collector and concurrent collectore will
throw an OutOfMemoryError if too much time is
being spent in garbage collection
– If more than 98% of the total time is spent in garbage
collection and less than 2% of the heap is recovered
– Prevents applications from running for an extended
period of time while making little or no progress
• -XX:-UseGCOverheadLimit
– To disable this feature
Other Considerations
Permanent Generation Size
• The permanent generation does not have a
noticeable impact on GC performance
• However, some applications dynamically
generate and load many classes; for example,
some implementations of JavaServer Pages
(JSP) pages.
• -XX:MaxPermSize=<N>
The size of the JVM thread stack
• When Java creates a new thread, it pre-
allocates a fixed-size block of memory for that
thread's stack.
• If you have lots of threads - the memory
saving is the reduction in stack size times the
number of threads.
– May increase the chance of a Stack Overflow error
• On x86 Solaris/Linux it is 320k in the 32-bit
VM and 1024k in the 64-bit VM
JVM thread stack…
• (total RAM used by JVM process) = (heap size)
+ (number of threads)x(thread stack size)
• If application has a lot of threads might be
running out of memory
• You can reduce your stack size by running with
the -Xss option
• Ex : -Xss64k
References
[1] "Java SE 6 HotSpot™ Virtual Machine Garbage
Collection Tuning", [Online]. Available:
http://www.oracle.com/technetwork/java/javase/g
c-tuning-6-140523.html [Accessed 12-May-2014]
[2] "Frequently Asked Questions About the Java
HotSpot VM", [Online]. Available:
http://www.oracle.com/technetwork/java/hotspotf
aq-138619.htm [Accessed 12-May-2014]
Q & A

Mais conteúdo relacionado

Mais procurados

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 SolrQAware GmbH
 
Exactly once with spark streaming
Exactly once with spark streamingExactly once with spark streaming
Exactly once with spark streamingQuentin Ambard
 
Jvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies applicationJvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies applicationQuentin Ambard
 
Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013
Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013
Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013Amazon Web Services
 
“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage CollectionHaim Yadid
 
Efficient and Fast Time Series Storage - The missing link in dynamic software...
Efficient and Fast Time Series Storage - The missing link in dynamic software...Efficient and Fast Time Series Storage - The missing link in dynamic software...
Efficient and Fast Time Series Storage - The missing link in dynamic software...Florian Lautenschlager
 
The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...
The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...
The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...Anis Nasir
 
Predictive Maintenance with Deep Learning and Apache Flink
Predictive Maintenance with Deep Learning and Apache FlinkPredictive Maintenance with Deep Learning and Apache Flink
Predictive Maintenance with Deep Learning and Apache FlinkDongwon Kim
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundMasahiko Sawada
 
DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...
DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...
DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...Deltares
 
Apache Gearpump next-gen streaming engine
Apache Gearpump next-gen streaming engineApache Gearpump next-gen streaming engine
Apache Gearpump next-gen streaming engineTianlun Zhang
 
CRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected ApplicationsCRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected ApplicationsEmery Berger
 

Mais procurados (13)

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
 
Exactly once with spark streaming
Exactly once with spark streamingExactly once with spark streaming
Exactly once with spark streaming
 
Jvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies applicationJvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies application
 
Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013
Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013
Finding New Sub-Atomic Particles on the AWS Cloud (BDT402) | AWS re:Invent 2013
 
“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection
 
Efficient and Fast Time Series Storage - The missing link in dynamic software...
Efficient and Fast Time Series Storage - The missing link in dynamic software...Efficient and Fast Time Series Storage - The missing link in dynamic software...
Efficient and Fast Time Series Storage - The missing link in dynamic software...
 
The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...
The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...
The Power of Both Choices: Practical Load Balancing for Distributed Stream Pr...
 
Aerospike & GCE (LSPE Talk)
Aerospike & GCE (LSPE Talk)Aerospike & GCE (LSPE Talk)
Aerospike & GCE (LSPE Talk)
 
Predictive Maintenance with Deep Learning and Apache Flink
Predictive Maintenance with Deep Learning and Apache FlinkPredictive Maintenance with Deep Learning and Apache Flink
Predictive Maintenance with Deep Learning and Apache Flink
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
 
DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...
DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...
DSD-INT 2017 High Performance Parallel Computing with iMODFLOW-MetaSWAP - Ver...
 
Apache Gearpump next-gen streaming engine
Apache Gearpump next-gen streaming engineApache Gearpump next-gen streaming engine
Apache Gearpump next-gen streaming engine
 
CRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected ApplicationsCRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected Applications
 

Destaque

Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionKelum Senanayake
 
Security Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in SkypeSecurity Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in SkypeKelum Senanayake
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
Java GC - Pause tuning
Java GC - Pause tuningJava GC - Pause tuning
Java GC - Pause tuningekino
 
Java gc
Java gcJava gc
Java gcNiit
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Anna Shymchenko
 
Java Garbage Collection(GC)- Study
Java Garbage Collection(GC)- StudyJava Garbage Collection(GC)- Study
Java Garbage Collection(GC)- StudyDhanu Gupta
 
Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"Ciklum Minsk
 
Java Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextJava Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextTomek Borek
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimizationRajan Jethva
 

Destaque (20)

Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another Introduction
 
Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 
Knight's Tour
Knight's TourKnight's Tour
Knight's Tour
 
Security Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in SkypeSecurity Risks & Vulnerabilities in Skype
Security Risks & Vulnerabilities in Skype
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
Java GC - Pause tuning
Java GC - Pause tuningJava GC - Pause tuning
Java GC - Pause tuning
 
Java gc
Java gcJava gc
Java gc
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Вячеслав Блинов «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 Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Java Garbage Collection(GC)- Study
Java Garbage Collection(GC)- StudyJava Garbage Collection(GC)- Study
Java Garbage Collection(GC)- Study
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"
 
Java Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextJava Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and context
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimization
 
Java memory model
Java memory modelJava memory model
Java memory model
 
The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 

Semelhante a What you need to know about GC

JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
G1 collector and tuning and Cassandra
G1 collector and tuning and CassandraG1 collector and tuning and Cassandra
G1 collector and tuning and CassandraChris Lohfink
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionHaribabu Nandyal Padmanaban
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Anna Shymchenko
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
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) CollectorGurpreet Sachdeva
 
Garbage Collection of Java VM
Garbage Collection of Java VMGarbage Collection of Java VM
Garbage Collection of Java VMYongqiang Li
 
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...DataStax
 
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 2020Jelastic Multi-Cloud PaaS
 
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016DataStax
 
Storing Cassandra Metrics
Storing Cassandra MetricsStoring Cassandra Metrics
Storing Cassandra MetricsChris Lohfink
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scalethelabdude
 
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 PresentationLudovic Poitou
 
Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2ScyllaDB
 
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 UsageJelastic Multi-Cloud PaaS
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentationEdward Capriolo
 
Scaling classical clone detection tools for ultra large datasets
Scaling classical clone detection tools for ultra large datasetsScaling classical clone detection tools for ultra large datasets
Scaling classical clone detection tools for ultra large datasetsimanmahsa
 
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...Jelastic Multi-Cloud PaaS
 

Semelhante a What you need to know about GC (20)

JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
G1 collector and tuning and Cassandra
G1 collector and tuning and CassandraG1 collector and tuning and Cassandra
G1 collector and tuning and Cassandra
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage Collection
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
Basics of JVM Tuning
Basics of JVM TuningBasics of JVM Tuning
Basics of JVM Tuning
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
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
 
Garbage Collection of Java VM
Garbage Collection of Java VMGarbage Collection of Java VM
Garbage Collection of Java VM
 
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
 
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
 
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
 
Storing Cassandra Metrics
Storing Cassandra MetricsStoring Cassandra Metrics
Storing Cassandra Metrics
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scale
 
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
 
Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2
 
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
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentation
 
Scaling classical clone detection tools for ultra large datasets
Scaling classical clone detection tools for ultra large datasetsScaling classical clone detection tools for ultra large datasets
Scaling classical clone detection tools for ultra large datasets
 
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...
 

Último

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 

Último (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

What you need to know about GC

  • 1. What you need to know about GC Java SE 6 HotSpot™ VM K e l u m S e n a n a y a k e
  • 2. High Level Agenda • Introduction • Generations • Collectors • Other Considerations
  • 4. Java is everywhere… • Java™ Platform, Standard Edition (Java SE™) is used for a wide variety of applications. • JVM provides multiple garbage collectors, each designed to satisfy different requirements
  • 5. Why memory? • One strength of the J2SE platform is that it shields the developer from the complexity of memory allocation and garbage collection. • However, once garbage collection is the principal bottleneck, it is worth understanding some aspects of this hidden implementation.
  • 6. • When does the choice of a garbage collector matter? – For some applications, the answer is never • Application can perform well in the presence of garbage collection with pauses of modest frequency and duration – However, this is not the case for a large class of applications
  • 9. Garbage Collection… How? • The most straightforward garbage collection algorithms simply iterate over every reachable object. – The time this approach takes is proportional to the number of live objects • “Weak generational hypothesis” – “most objects survive for only a short period of time”
  • 11. • Memory is managed in Generations • Memory pools holding objects of different ages
  • 16. Performance Considerations • Throughput – is the percentage of total time not spent in garbage collection, considered over long periods of time • Pauses – are the times when an application appears unresponsive because garbage collection is occurring. • A web server vs an interactive graphics program
  • 17. Performance… • Footprint – is the working set of a process, measured in pages and cache lines • Promptness – is the time between when an object becomes dead and when the memory becomes available • In general, a particular generation sizing chooses a trade-off between these considerations.
  • 18. Performance… • A very large young generation – maximize throughput – at the expense of footprint, promptness and pause times. • A small young generation – young generation pauses can be minimized – at the expense of throughput
  • 19. Measurement • -verbose:gc information about the heap and garbage collection to be printed at each collection. [GC 325407K->83000K(776768K), 0.2300771 secs] [GC 325816K->83372K(776768K), 0.2454258 secs] [Full GC 267628K->83769K(776768K), 1.8479984 secs]
  • 20. Measurement… • -XX:+PrintGCDetails [GC [DefNew: 64575K->959K(64576K), 0.0457646 secs] 196016K->133633K(261184K), 0.0459067 secs] • -XX:+PrintGCTimeStamps 111.042: [GC 111.042: [DefNew: 8128K->8128K(8128K), 0.0000505 secs]111.042: [Tenured: 18154K->2311K(24576K), 0.1290354 secs] 26282K->2311K(32704K), 0.1293306 secs]
  • 21. Sizing the Generations • -Xms : initial sizes of the heap • -Xmx : maximum sizes of the heap • Collections occur when generations fill up – Throughput is inversely proportional to the amount of memory available
  • 22. Sizing… • By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range • -XX:MinHeapFreeRatio=<minimum> • -XX:MaxHeapFreeRatio=<maximum>
  • 23. Sizing… MinHeapFreeRatio 40 MaxHeapFreeRatio 70 -Xms 3670k -Xmx 64m If the percent of free space in a generation falls below 40%, the generation will be expanded to maintain 40% free space, up to the maximum allowed size of the generation. If the free space exceeds 70%, the generation will be contracted so that only 70% of the space is free, subject to the minimum size of the generation.
  • 24. The Young Generation • The second most influential knob is the proportion of the heap dedicated to the young generation. – The bigger the young generation, the less often minor collections occur. – Larger young generation implies a smaller tenured generation (for a bounded heap size) – will increase the frequency of major collections
  • 25. • -XX:NewRatio : Defines the ratio between the young and tenured generation ex: -XX:NewRatio=3 • You can even decide the initial and max sizes of the young space with parameters NewSize and MaxNewSize
  • 26. Survivor Space Sizing • SurvivorRatio : can be used to tune the size of the survivor spaces • Sets the ratio between eden and a survivor space • This is often not as important for performance • -XX:SurvivorRatio=6
  • 27. • If survivor spaces are too small, copying collection overflows directly into the tenured generation. • If survivor spaces are too large, they will be uselessly empty.
  • 29. The serial collector • Uses a single thread to perform all garbage collection work – No communication overhead between threads – Best-suited to single processor machines – Multiprocessors for applications with small data sets (up to approximately 100MB) • -XX:+UseSerialGC
  • 30. The parallel collector • a.k.a throughput collector • Performs minor collections in parallel • Medium- to large-sized data sets that are run on multiprocessor or multi-threaded hardware. • -XX:+UseParallelGC • -XX:+UseParallelOldGC
  • 31. Parallel collector… • Select the parallel collector if, – Peak application performance is the first priority – There are no pause time requirements or pauses of one second or longer are acceptable • On a machine with N processors the parallel collector uses N garbage collector threads • -XX:ParallelGCThreads=<N>
  • 32. • -XX:MaxGCPauseMillis=<N> – a hint that pause times of <N> milliseconds or less are desired • -XX:GCTimeRatio=<N> – Sets the ratio of garbage collection time to application time to 1 / (1 + <N>) – -XX:GCTimeRatio=19 sets a goal of 1/20 or 5% of the total time in garbage collection.
  • 33. Generation Size Adjustments • Growing and shrinking are done at different rates • By default a generation grows in increments of 20% and shrinks in increments of 5%. -XX:YoungGenerationSizeIncrement=<Y> for the young generation -XX:TenuredGenerationSizeIncrement=<T> for the tenured generation -XX:AdaptiveSizeDecrementScaleFactor=<D> If the growth increment is X percent, the decrement for shrinking is X / D percent
  • 34. The Concurrent Collector • Select concurrent collector If – response time is more important than overall throughput – garbage collection pauses must be kept shorter than approximately one second • Suitable for – applications which have a relatively large set of long- lived data (a large tenured generation) – run on machines with two or more processors • -XX:+UseConcMarkSweepGC
  • 35. Steps of Concurrent Collection 1. Stop all application threads and identify the set of objects reachable from roots, then resume all application threads 2. Concurrently trace the reachable object graph, using one or more processors, while the application threads are executing 3. Concurrently retrace sections of the object graph that were modified since the tracing in the previous step, using one processor 4. Stop all application threads and retrace sections of the roots and object graph that may have been modified since they were last examined, then resume all application threads 5. Concurrently sweep up the unreachable objects to the free lists used for allocation, using one processor 6. Concurrently resize the heap and prepare the support data structures for the next collection cycle, using one processor
  • 36. Starting a Concurrent Collection Cycle • Serial collector – A major collection occurs whenever the tenured generation becomes full – all application threads are stopped while the collection is done. – stop-the-world condition • concurrent collector – starts at a time such that the collection can finish before the tenured generation becomes full
  • 37. Starting… • Concurrent collector maintains dynamic estimates based on recent history • A concurrent collection will also start if the occupancy of the tenured generation exceeds an initiating occupancy • -XX:CMSInitiatingOccupancyFraction=<N> – <N> is an integral percentage (0-100) of the tenured generation size.
  • 38. Incremental Mode • Normally, the concurrent collector uses one or more processors during the entire concurrent tracing phase, without voluntarily releasing them. • Also, one processor is used for the entire concurrent sweep phase, again without releasing it. • Incremental mode solves this problem by breaking up the concurrent phases into short bursts of activity, which are scheduled to occur mid-way between minor pauses.
  • 39. [GC [1 CMS-initial-mark: 13991K(20288K)] 14103K(22400K), 0.0023781 secs] [GC [DefNew: 2112K->64K(2112K), 0.0837052 secs] 16103K->15476K(22400K), 0.0838519 secs] ... [GC [DefNew: 2077K->63K(2112K), 0.0126205 secs] 17552K->15855K(22400K), 0.0127482 secs] [CMS-concurrent-mark: 0.267/0.374 secs] [GC [DefNew: 2111K->64K(2112K), 0.0190851 secs] 17903K->16154K(22400K), 0.0191903 secs] [CMS-concurrent-preclean: 0.044/0.064 secs] [GC [1 CMS-remark: 16090K(20288K)] 17242K(22400K), 0.0210460 secs] [GC [DefNew: 2112K->63K(2112K), 0.0716116 secs] 18177K->17382K(22400K), 0.0718204 secs] [GC [DefNew: 2111K->63K(2112K), 0.0830392 secs] 19363K->18757K(22400K), 0.0832943 secs] ... [GC [DefNew: 2111K->0K(2112K), 0.0035190 secs] 17527K->15479K(22400K), 0.0036052 secs] [CMS-concurrent-sweep: 0.291/0.662 secs] [GC [DefNew: 2048K->0K(2112K), 0.0013347 secs] 17527K->15479K(27912K), 0.0014231 secs] [CMS-concurrent-reset: 0.016/0.016 secs] [GC [DefNew: 2048K->1K(2112K), 0.0013936 secs] 17527K->15479K(27912K), 0.0014814 secs]
  • 40. Incremental Mode… • Recommended Options – To use i-cms in Java SE 6, use the following command line options: -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode
  • 41. Excessive GC Time and OutOfMemoryError • Parallel collector and concurrent collectore will throw an OutOfMemoryError if too much time is being spent in garbage collection – If more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered – Prevents applications from running for an extended period of time while making little or no progress • -XX:-UseGCOverheadLimit – To disable this feature
  • 43. Permanent Generation Size • The permanent generation does not have a noticeable impact on GC performance • However, some applications dynamically generate and load many classes; for example, some implementations of JavaServer Pages (JSP) pages. • -XX:MaxPermSize=<N>
  • 44. The size of the JVM thread stack • When Java creates a new thread, it pre- allocates a fixed-size block of memory for that thread's stack. • If you have lots of threads - the memory saving is the reduction in stack size times the number of threads. – May increase the chance of a Stack Overflow error • On x86 Solaris/Linux it is 320k in the 32-bit VM and 1024k in the 64-bit VM
  • 45. JVM thread stack… • (total RAM used by JVM process) = (heap size) + (number of threads)x(thread stack size) • If application has a lot of threads might be running out of memory • You can reduce your stack size by running with the -Xss option • Ex : -Xss64k
  • 46. References [1] "Java SE 6 HotSpot™ Virtual Machine Garbage Collection Tuning", [Online]. Available: http://www.oracle.com/technetwork/java/javase/g c-tuning-6-140523.html [Accessed 12-May-2014] [2] "Frequently Asked Questions About the Java HotSpot VM", [Online]. Available: http://www.oracle.com/technetwork/java/hotspotf aq-138619.htm [Accessed 12-May-2014]
  • 47. Q & A