SlideShare ist ein Scribd-Unternehmen logo
1 von 72
Downloaden Sie, um offline zu lesen
The JVM is your friend
Kai Koenig	

@AgentK
Web/Mobile Developer since the late 1990s	

Interested in: Java, CFML, Functional
Programming, Go, JS, Mobile, Raspberry Pi	

!
I’ve already showed you where I live :)	

Me
- The JVM and Java Memory Management

- What’s the big deal with Garbage Collection?

- GC Strategies for various situations & JVMs

- How to approach JVM “tuning”?

- CFML specifics

Agenda
The JVM and Java Memory
Management
JVM Architecture 
(“What’s that JVM thing?”)
The JVM Architecture
History
First JVM implementations were rather simple:	

	

 - Weak JMM (Java Memory Model)	

	

 - Issues with concepts like final, volatile etc.	

	

 -Very simple, non-generational memory	

	

 - “Mark-and-Sweep” Garbage Collection	

!
History
Hotspot JVM was introduced in Java 1.2 as an
add-on — became part of the default setup in
Java 1.3 (~ mid 2000).	

!
Also be aware of notational flukes:	

1.0 -> 1.1 -> Java 2 (1.2) -> Java 2 (1.3) -> Java 2
(1.4) -> Java 5 -> Java 6 -> Java 7 -> Java 8
Modern JVMs
Generational Memory Management	

Generational Garbage Collection	

Hotspot JVM	

!
What’s the big deal with
Garbage Collection?
Garbage
(“Who made that mess?”)
JVM Garbage
Over time the JVM accumulates a lot of objects
that are not needed anymore.	

If we didn’t clean up, we’d get Out-Of-Memory
errors sooner or later.	

Q:What’s being cleaned up?	

A:“Dead” objects	

!
JVM Garbage Collection
Every single GC algorithm starts with some kind
of “marking”: identifying the objects that are not
necessary anymore.	

The Collector would start with a Root Set and
follow along object references it can reach.	

Everything else is Garbage and can go!	

Q:What’s the Root Set?
The Root Set
References on the Call Stacks of the JVM’s
threads	

Global References, e.g. static fields in Classes	

!
The Root Set are entry points into the reference
graph of “alive” objects.	

!
Root Set and Reference Graphs
Root Set and Reference Graphs
Root Set and Reference Graphs
Root Set and Reference Graphs
Root Set and Reference Graphs
What we’ve looked at is a basic “Mark-and-
Sweep” algorithm.	

The “Free List” could in the easiest form just be
used to mark memory as free.	

Problem: Fragmentation and therefore inability
to assign memory for new, fresh objects.	

!
Fragmentation
Generations
(“OK, let’s make this stuff really complicated”)
Basics of Generational Memory: Heap
Stores your objects and classes at the JVM’s
runtime.	

Usually the following basic assumptions are true:	

	

 - Lots of short-lived objects	

	

 -Very few (or: fewer) long-lived objects	

Also function-local objects are created here.
Lifetime vs. # of objects
Heap management
The JVM can’t know in advance what the lifespan
of a certain object would be.	

Generational Memory Management is a solution
to overcome this issue and fragmentation:	

	

 -Young Generation	

	

 - Old Generation / Tenured Generation	

	

 - Permanent Generation (special case…)
Generations
Young Generation - for new objects
!
!
Typical short-lived objects:	

	

 - Objects local to a function	

	

 - Loop iterators, StringBuilders etc.	

!
Young Generation - for new objects
!
!
Typical medium-lived objects:	

	

 - Objects tied to a session	

!
!
Young Generation - for new objects
!
!
Typical long-lived objects:	

	

 - Thread Pools	

	

 - Singletons	

	

 - Certain framework objects
Young Generation - what happens next?
In general and following the theory of
Generational Memory Management:	

	

 -YG fills up -> Garbage Collection happens	

	

 -YG collection is supposed to be fast	

If an object survives a certain amount of
collections in theYG, the JVM will assume the
object is medium- or long-lived and move it into
the Old Generation.
Old Generation
Over time, more long-lived objects end up in the
Old Generation and at some point it’s going to
be full.	

In general and following the theory of
Generational Memory Management:	

	

 - OG fills up -> Garbage Collection happens	

	

 - OG collection is usually slower thanYG	

	

- Size of OG
Why is Generational Memory good?
Lots of garbage - cleaning it up fast is worthwhile	

Generational Memory Management:	

	

 -YG GC often -> space for new objects	

	

 - Each generation focusses on “type” of objects	

	

 - GC doesn’t have to search the whole heap	

!
!
Permanent Generation
Not a “Generation” as such, but still needs to be
managed appropriately.	

Stores:	

	

 - Classes	

	

 - Internal JVM objects	

	

 - JIT information	

!
GC Strategies for various
situations & JVMs
Generation Strategy(optional)
Young Generation Strategies
Generally, theYG is smaller than the OG.	

TheYG consists of sub-sections:	

	

 - Eden (new objects)	

	

 - Survivor 1 and Survivor 2	

One Survivor space is always empty and during a
YG collection the JVM will copy survivors from
Eden and S1 to S2 and vice versa.
Old Generation Strategies
The amount of survived GCs in theYG is called
“Tenuring Threshold”	

If Eden and Survivor Spaces are too small,
sometimes objects might get instant-promoted
to the OG (because there’s no space in theYG).	

Old Generation Collections are usually
expensive (slow, long)!	

!
This is what your heap really looks like
Collector Selection
Selection criteria
Efficiency / Throughput	

Concurrency 	

Overhead	

JVM version you’re on	

!
Ergonomics
Since Java 5 (and much improved in Java 6-land),
the JVM comes pre-setup with certain criteria
for selecting GC strategies and settings
(“Ergonomics”). Most can be changed.	

!
!
JRockit/Apple JVMs — similar mechanisms	

!
Young Generation
(optional)
YG Collectors: Serial
Mark-and-Sweep: Marking phase gets all
reachable objects, Sweeping cleans up the
leftovers	

Problems:	

	

 - Fragmentation
YG Collectors: Serial
Mark-and-Copy: Marking phase gets all reachable
objects, Copy moves those into a new (empty)
space.	

Problems:	

	

 - Slightly more expensive than MaS	

	

 - Copying and References have to be shifted	

	

 - “Intergenerational References” -> homework
YG Collectors: Serial
Both MaS and MaC need exclusive access to the
Reference Graph.	

Stop-the-World: stops all threads, the collection
was traditionally done by a single “Reaper
Thread”.	

Problems:	

	

 - Long Pauses	

	

 - Inefficient
YG Collectors: Parallel
Parallel MaC (since Java 1.4.2) distributes the
Marking and Copying phases over multiple
threads.	

The actual collecting is still Stop-the-World, but
for a much shorter period of time.	

YG default since Java 5 if machine has 2+ cores
or CPUs, otherwise: -XX:+UseParallelGC	

!
YG Collectors: Parallel
Default: 1 GC thread per CPU/Core	

8+ CPUs/Cores: 5/8 * CPUs/Cores	

Explicit: -XX:+UseParallelGCThread=n	

!
Old Generation
(optional)
OG Collectors
Many objects and low mortality means MaC
would be inefficient. Instead we use Mark-and-
Compact.	

MaCo is a variation of MaS with lower
fragmentation	

4 Phases: Marking, Calculation of new Locations,
Reference Adjustments and Moving	

!
OG Collectors
MaCo is a Full Collection algorithm - there’s no
“Pure OG collection”. 	

Doesn’t run often, but if it runs it’ll take a while.	

Performance issues:	

	

 - All objects are visited multiple times	

	

 - Serial collector, stops all the threads	

Enable via -XX:+UseSerialGC
OG Collectors: parallel
ParallelOld: Parallel and more efficient version of
MaCo, still Stop-the-World though - but shorter
StW pause than MaCo.	

Idea: 	

	

 - Marking and Compacting are multi-threaded	

	

 - Algorithm operates on 2 segments per thread	

OG default since Java 6 on server profiles or via
-XX:+UseParallelOldGC
OG Collectors: concurrent
CMS: concurrent version of MaS, does NOT
need to stop threads for the majority parts of its
work.	

4 Phases: Initial Marking, Concurrent Marking,
Remarking, Concurrent Sweep.	

Stop-the-World: Initial Marking & Remarking	

CMS via -XX:+UseConcMarkSweepGC	

!
OG Collectors: concurrent
Concurrent Mark-and-Sweep is the preferred
OG collector if you want to minimise Stop-the-
World collections.	

Overall throughput slightly less than ParallelOld,
but much better suited for web/server apps.	

Well suited for large heaps (but be aware of
fragmentation), there’s an “incremental” mode
for systems with 1-2 cores.
OG Collectors: G1 (Garbage First)
G1 is a replacement for CMS (experimental in
later Java 6 release, full support in Java 7+)	

Benefits:	

	

 - Low-pause	

	

 - Adaptable	

	

 - Much less fragmentation than CMS	

	

 - Better collector for full heap
OG Collectors: G1 (Garbage First)
Heap is split into regions (1-32MB)	

Collector is controlled by min time between GC
pauses and min length of GC pause	

!
!
In Java 6/7 (6u14, 7u4) set via -XX:+UseG1GC 	

!
How to approach JVM
“tuning”?
Tuning
Preamble
Do not trust consultants, blog posts, mailing list
discussions etc. telling you what the “best” JVM
settings for you would be.	

(That’s including myself!)	

There is no such thing as the “best” settings.	

It solely depends on the application and your
usage.
Typical reasons for tuning
Application Growth	

Change in available Resources (memory, CPU
etc)	

Actual Performance issues (unresponsiveness…)	

JVM-level error messages in log files
Tools
Process
Make an assumption for load, memory and GC
settings.	

Run Load tests, monitor and measure results.	

Change one setting, rinse and repeat.
JVM settings and logging
How do you find out what’s
happening in your JVM?	

-verbose:GC
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
!
[GC 64781K->22983K(71360K), 0.0242084 secs]	

[GC 68487K->25003K(77888K), 0.0194041 secs]	

[Full GC 25003K->20302K(89600K), 0.1713420 secs]	

[GC 70670K->21755K(90048K), 0.0054093 secs]	

[GC 71913K->46558K(94912K), 0.0295257 secs]	

[Full GC 46558K->45267K(118336K), 0.2144038 secs]	

[GC 88214K->84651K(133056K), 0.0674443 secs]	

[Full GC 84651K->84633K(171648K), 0.1739369 secs]	

[GC 117977K->115114K(180736K), 0.0623399 secs]	

[GC 158613K->157136K(201152K), 0.0591171 secs]	

[Full GC 157136K->157098K(254784K), 0.1868453 secs]	

[GC 160678K->160455K(261184K), 0.0536678 secs]	

01/24 19:36:22 Debug [scheduler-1] - Next mail spool run in 15 seconds.	

[GC 202912K->200819K(268288K), 0.0625820 secs]	

[Full GC 200819K->200776K(332224K), 0.2121724 secs]	

[GC 213293K->212423K(339520K), 0.0426462 secs]	

[GC 259465K->256115K(340288K), 0.0645039 secs]	

[Full GC 256115K->255462K(418432K), 0.3226731 secs]	

[GC 281947K->279651K(421760K), 0.0530268 secs]	

[GC 331073K->323785K(422720K), 0.0695117 secs]	

[Full GC 323785K->323697K(459264K), 0.2139458 secs]	

[Full GC 364365K->361525K(459264K), 0.2180439 secs]	

[Full GC 400859K->400859K(459264K), 0.1702890 secs]	

[Full GC 400859K->43989K(274112K), 0.2642407 secs]	

[GC 95197K->93707K(273216K), 0.0338568 secs]	

[GC 146978K->140363K(276032K), 0.0664380 secs]	

[GC 193696K->189635K(277952K), 0.0630006 secs]	

[Full GC 189635K->189604K(425920K), 0.1913979 secs]	

[GC 219773K->205157K(426048K), 0.0442126 secs]
GC tuning process
Let’s look at a real world case	

!
!
GC tuning results/criteria
Demo of some tools	

!
!
GC tuning results/criteria
More often than not you’d want to optimise for
low GC pauses. 	

!
GC Throughput: 95%+ are good.	

Optimising for Throughput usually leads to
longer GC pauses, still useful for batch
operations.
Memory sizing concerns
Initial and maximum heap size:	

-Xms4096m, -Xmx6144m	

PermGen size:	

-XX:MaxPermSize=256m	

YG size:	

-XX:NewSize=768m, -XX:MaxNewSize=768m
Memory sizing concerns
32bit JVM: theoretically 4GB	

	

 - In reality under Windows: ~1.2-1.4GB	

Switching to a 64bit JVM creates ~20-30%
memory overhead due to longer pointer
references.	

Also: easier to multi-threaded create new
objects than clean them up multi-threaded.
Example
Setup of extremely high volume/traffic site,
optimisation goal low pause times	

-Xms6144m -Xmx6144m 

-XX:NewSize=2500m -XX:MaxNewSize=2500m 

-XX:+CMSIncrementalMode 

-XX:+ExplicitGCInvokesConcurrent 

-XX:+CMSPermGenSweepingEnabled 

-XX:+CMSClassUnloadingEnabled 

-XX:MaxPermSize=384m 

-XX:PermSize=384m 

-XX:+UseConcMarkSweepGC
Overview Java 6
Max throughput Min pause time
2+ cores 1 core 2+ cores 1 core
YG parYG serYG parYG parYG
OldGen par OG ser OG CMS iCMS
JVM Flags defaults
-XX:
+UseSerialGC
-XX:
+UseConcMarkSweepGC 	

(implicitly using: -XX:
+UseParNewGC forYG)
-XX:
+UseConcMarkSweepGC
-XX:
+CMSIncrementalMode	

(implicitly using: -XX:
+UseParNewGC forYG)
Overview Java 7
Max throughput Min pause time
2+ cores 1 core 2+ cores 1 core
YG parYG serYG G1 parYG
OldGen par OG ser OG G1 iCMS
JVM Flags defaults
-XX:
+UseSerialGC
-XX:+UseG1GC
-XX:
+UseConcMarkSweepGC
-XX:
+CMSIncrementalMode	

(implicitly using: -XX:
+UseParNewGC forYG)
(Oracle Java 7 JVMs also incorporate some JRockit features)
Photo credits
http://www.flickr.com/photos/aigle_dore/6973012997/	

http://www.flickr.com/photos/thanh_tan/2903192937	

http://www.flickr.com/photos/museemccordmuseum/3294656277/	

http://www.flickr.com/photos/wwarby/3297205226/	

https://www.flickr.com/photos/nationalmuseumofamericanhistory/9607222709/	

https://www.flickr.com/photos/mr_zorgman/6396087451/	

http://www.flickr.com/photos/thomashawk/3958193579/	

https://www.flickr.com/photos/24742305@N00/5589187752	

https://www.flickr.com/photos/39587102@N07/3821835981	

https://www.flickr.com/photos/21160499@N04/5437070898	

https://www.flickr.com/photos/65694112@N05/6147388744
Get in touch
Kai Koenig	

Email: kai@ventego-creative.co.nz	

www.ventego-creative.co.nz	

Blog: www.bloginblack.de	

Twitter: @AgentK

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyajuckel
 
Java tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy devJava tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy devTomek Borek
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia "What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia Vladimir Ivanov
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torqueboxrockyjaiswal
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyAmit Solanki
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?What's New in the JVM in Java 8?
What's New in the JVM in Java 8?Azul Systems Inc.
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxbobmcwhirter
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With TerracottaPT.JUG
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applicationspkoza
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosBruno Oliveira
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machineelliando dias
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의Terry Cho
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
 
Eliminating the Pauses in your Java Application
Eliminating the Pauses in your Java ApplicationEliminating the Pauses in your Java Application
Eliminating the Pauses in your Java ApplicationMark Stoodley
 

Was ist angesagt? (20)

Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Java tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy devJava tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy dev
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia "What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?What's New in the JVM in Java 8?
What's New in the JVM in Java 8?
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With Terracotta
 
2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
Eliminating the Pauses in your Java Application
Eliminating the Pauses in your Java ApplicationEliminating the Pauses in your Java Application
Eliminating the Pauses in your Java Application
 

Ähnlich wie Jvm is-your-friend

Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!devObjective
 
Jvm performance tuning
Jvm performance tuningJvm performance tuning
Jvm performance tuningIgor Igoroshka
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Marcos García
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?Alonso Torres
 
«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в JavaOlga Lavrentieva
 
A quick view about Java Virtual Machine
A quick view about Java Virtual MachineA quick view about Java Virtual Machine
A quick view about Java Virtual MachineJoão Santana
 
Java Garbage Collector and The Memory Model
Java Garbage Collector and The Memory ModelJava Garbage Collector and The Memory Model
Java Garbage Collector and The Memory ModelErnesto Arroyo Ron
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnosticsDanijel Mitar
 
Garbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMGarbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMjaganmohanreddyk
 
Garbage collection
Garbage collectionGarbage collection
Garbage collectionMudit Gupta
 
Java garbage collection, jvm, visual vm
Java garbage collection, jvm, visual vmJava garbage collection, jvm, visual vm
Java garbage collection, jvm, visual vmBrad Schoening, MSCS
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlLeon Chen
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionHaribabu Nandyal Padmanaban
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12sidg75
 

Ähnlich wie Jvm is-your-friend (20)

Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Jvm performance tuning
Jvm performance tuningJvm performance tuning
Jvm performance tuning
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?
 
«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java
 
A quick view about Java Virtual Machine
A quick view about Java Virtual MachineA quick view about Java Virtual Machine
A quick view about Java Virtual Machine
 
Java Garbage Collector and The Memory Model
Java Garbage Collector and The Memory ModelJava Garbage Collector and The Memory Model
Java Garbage Collector and The Memory Model
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnostics
 
Garbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMGarbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVM
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
JVM Magic
JVM MagicJVM Magic
JVM Magic
 
Java garbage collection, jvm, visual vm
Java garbage collection, jvm, visual vmJava garbage collection, jvm, visual vm
Java garbage collection, jvm, visual vm
 
Javasession10
Javasession10Javasession10
Javasession10
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage Collection
 
Basics of JVM Tuning
Basics of JVM TuningBasics of JVM Tuning
Basics of JVM Tuning
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
 

Mehr von ColdFusionConference

Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
API Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsAPI Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsColdFusionConference
 
Crafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectCrafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectColdFusionConference
 
Security And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API ManagerSecurity And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API ManagerColdFusionConference
 
Monetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APISMonetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APISColdFusionConference
 
Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016ColdFusionConference
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016ColdFusionConference
 
ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995ColdFusionConference
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMSColdFusionConference
 
Build your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webBuild your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webColdFusionConference
 

Mehr von ColdFusionConference (20)

Api manager preconference
Api manager preconferenceApi manager preconference
Api manager preconference
 
Cf ppt vsr
Cf ppt vsrCf ppt vsr
Cf ppt vsr
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
API Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsAPI Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIs
 
Don't just pdf, Smart PDF
Don't just pdf, Smart PDFDon't just pdf, Smart PDF
Don't just pdf, Smart PDF
 
Crafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectCrafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an Architect
 
Security And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API ManagerSecurity And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API Manager
 
Monetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APISMonetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APIS
 
Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016
 
ColdFusion in Transit action
ColdFusion in Transit actionColdFusion in Transit action
ColdFusion in Transit action
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016
 
Where is cold fusion headed
Where is cold fusion headedWhere is cold fusion headed
Where is cold fusion headed
 
ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995
 
Instant ColdFusion with Vagrant
Instant ColdFusion with VagrantInstant ColdFusion with Vagrant
Instant ColdFusion with Vagrant
 
Restful services with ColdFusion
Restful services with ColdFusionRestful services with ColdFusion
Restful services with ColdFusion
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
 
Build your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webBuild your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and web
 
Why Everyone else writes bad code
Why Everyone else writes bad codeWhy Everyone else writes bad code
Why Everyone else writes bad code
 
Securing applications
Securing applicationsSecuring applications
Securing applications
 
Testing automaton
Testing automatonTesting automaton
Testing automaton
 

Kürzlich hochgeladen

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Kürzlich hochgeladen (20)

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Jvm is-your-friend

  • 1. The JVM is your friend Kai Koenig @AgentK
  • 2.
  • 3. Web/Mobile Developer since the late 1990s Interested in: Java, CFML, Functional Programming, Go, JS, Mobile, Raspberry Pi ! I’ve already showed you where I live :) Me
  • 4. - The JVM and Java Memory Management
 - What’s the big deal with Garbage Collection?
 - GC Strategies for various situations & JVMs
 - How to approach JVM “tuning”?
 - CFML specifics
 Agenda
  • 5. The JVM and Java Memory Management
  • 6. JVM Architecture 
(“What’s that JVM thing?”)
  • 8. History First JVM implementations were rather simple: - Weak JMM (Java Memory Model) - Issues with concepts like final, volatile etc. -Very simple, non-generational memory - “Mark-and-Sweep” Garbage Collection !
  • 9. History Hotspot JVM was introduced in Java 1.2 as an add-on — became part of the default setup in Java 1.3 (~ mid 2000). ! Also be aware of notational flukes: 1.0 -> 1.1 -> Java 2 (1.2) -> Java 2 (1.3) -> Java 2 (1.4) -> Java 5 -> Java 6 -> Java 7 -> Java 8
  • 10. Modern JVMs Generational Memory Management Generational Garbage Collection Hotspot JVM !
  • 11. What’s the big deal with Garbage Collection?
  • 13. JVM Garbage Over time the JVM accumulates a lot of objects that are not needed anymore. If we didn’t clean up, we’d get Out-Of-Memory errors sooner or later. Q:What’s being cleaned up? A:“Dead” objects !
  • 14. JVM Garbage Collection Every single GC algorithm starts with some kind of “marking”: identifying the objects that are not necessary anymore. The Collector would start with a Root Set and follow along object references it can reach. Everything else is Garbage and can go! Q:What’s the Root Set?
  • 15. The Root Set References on the Call Stacks of the JVM’s threads Global References, e.g. static fields in Classes ! The Root Set are entry points into the reference graph of “alive” objects. !
  • 16. Root Set and Reference Graphs
  • 17. Root Set and Reference Graphs
  • 18. Root Set and Reference Graphs
  • 19. Root Set and Reference Graphs
  • 20. Root Set and Reference Graphs What we’ve looked at is a basic “Mark-and- Sweep” algorithm. The “Free List” could in the easiest form just be used to mark memory as free. Problem: Fragmentation and therefore inability to assign memory for new, fresh objects. !
  • 22. Generations
(“OK, let’s make this stuff really complicated”)
  • 23. Basics of Generational Memory: Heap Stores your objects and classes at the JVM’s runtime. Usually the following basic assumptions are true: - Lots of short-lived objects -Very few (or: fewer) long-lived objects Also function-local objects are created here.
  • 24. Lifetime vs. # of objects
  • 25. Heap management The JVM can’t know in advance what the lifespan of a certain object would be. Generational Memory Management is a solution to overcome this issue and fragmentation: -Young Generation - Old Generation / Tenured Generation - Permanent Generation (special case…)
  • 27. Young Generation - for new objects ! ! Typical short-lived objects: - Objects local to a function - Loop iterators, StringBuilders etc. !
  • 28. Young Generation - for new objects ! ! Typical medium-lived objects: - Objects tied to a session ! !
  • 29. Young Generation - for new objects ! ! Typical long-lived objects: - Thread Pools - Singletons - Certain framework objects
  • 30. Young Generation - what happens next? In general and following the theory of Generational Memory Management: -YG fills up -> Garbage Collection happens -YG collection is supposed to be fast If an object survives a certain amount of collections in theYG, the JVM will assume the object is medium- or long-lived and move it into the Old Generation.
  • 31. Old Generation Over time, more long-lived objects end up in the Old Generation and at some point it’s going to be full. In general and following the theory of Generational Memory Management: - OG fills up -> Garbage Collection happens - OG collection is usually slower thanYG - Size of OG
  • 32. Why is Generational Memory good? Lots of garbage - cleaning it up fast is worthwhile Generational Memory Management: -YG GC often -> space for new objects - Each generation focusses on “type” of objects - GC doesn’t have to search the whole heap ! !
  • 33. Permanent Generation Not a “Generation” as such, but still needs to be managed appropriately. Stores: - Classes - Internal JVM objects - JIT information !
  • 34. GC Strategies for various situations & JVMs
  • 36. Young Generation Strategies Generally, theYG is smaller than the OG. TheYG consists of sub-sections: - Eden (new objects) - Survivor 1 and Survivor 2 One Survivor space is always empty and during a YG collection the JVM will copy survivors from Eden and S1 to S2 and vice versa.
  • 37. Old Generation Strategies The amount of survived GCs in theYG is called “Tenuring Threshold” If Eden and Survivor Spaces are too small, sometimes objects might get instant-promoted to the OG (because there’s no space in theYG). Old Generation Collections are usually expensive (slow, long)! !
  • 38. This is what your heap really looks like
  • 40. Selection criteria Efficiency / Throughput Concurrency Overhead JVM version you’re on !
  • 41. Ergonomics Since Java 5 (and much improved in Java 6-land), the JVM comes pre-setup with certain criteria for selecting GC strategies and settings (“Ergonomics”). Most can be changed. ! ! JRockit/Apple JVMs — similar mechanisms !
  • 43. YG Collectors: Serial Mark-and-Sweep: Marking phase gets all reachable objects, Sweeping cleans up the leftovers Problems: - Fragmentation
  • 44. YG Collectors: Serial Mark-and-Copy: Marking phase gets all reachable objects, Copy moves those into a new (empty) space. Problems: - Slightly more expensive than MaS - Copying and References have to be shifted - “Intergenerational References” -> homework
  • 45. YG Collectors: Serial Both MaS and MaC need exclusive access to the Reference Graph. Stop-the-World: stops all threads, the collection was traditionally done by a single “Reaper Thread”. Problems: - Long Pauses - Inefficient
  • 46. YG Collectors: Parallel Parallel MaC (since Java 1.4.2) distributes the Marking and Copying phases over multiple threads. The actual collecting is still Stop-the-World, but for a much shorter period of time. YG default since Java 5 if machine has 2+ cores or CPUs, otherwise: -XX:+UseParallelGC !
  • 47. YG Collectors: Parallel Default: 1 GC thread per CPU/Core 8+ CPUs/Cores: 5/8 * CPUs/Cores Explicit: -XX:+UseParallelGCThread=n !
  • 49. OG Collectors Many objects and low mortality means MaC would be inefficient. Instead we use Mark-and- Compact. MaCo is a variation of MaS with lower fragmentation 4 Phases: Marking, Calculation of new Locations, Reference Adjustments and Moving !
  • 50. OG Collectors MaCo is a Full Collection algorithm - there’s no “Pure OG collection”. Doesn’t run often, but if it runs it’ll take a while. Performance issues: - All objects are visited multiple times - Serial collector, stops all the threads Enable via -XX:+UseSerialGC
  • 51. OG Collectors: parallel ParallelOld: Parallel and more efficient version of MaCo, still Stop-the-World though - but shorter StW pause than MaCo. Idea: - Marking and Compacting are multi-threaded - Algorithm operates on 2 segments per thread OG default since Java 6 on server profiles or via -XX:+UseParallelOldGC
  • 52. OG Collectors: concurrent CMS: concurrent version of MaS, does NOT need to stop threads for the majority parts of its work. 4 Phases: Initial Marking, Concurrent Marking, Remarking, Concurrent Sweep. Stop-the-World: Initial Marking & Remarking CMS via -XX:+UseConcMarkSweepGC !
  • 53. OG Collectors: concurrent Concurrent Mark-and-Sweep is the preferred OG collector if you want to minimise Stop-the- World collections. Overall throughput slightly less than ParallelOld, but much better suited for web/server apps. Well suited for large heaps (but be aware of fragmentation), there’s an “incremental” mode for systems with 1-2 cores.
  • 54. OG Collectors: G1 (Garbage First) G1 is a replacement for CMS (experimental in later Java 6 release, full support in Java 7+) Benefits: - Low-pause - Adaptable - Much less fragmentation than CMS - Better collector for full heap
  • 55. OG Collectors: G1 (Garbage First) Heap is split into regions (1-32MB) Collector is controlled by min time between GC pauses and min length of GC pause ! ! In Java 6/7 (6u14, 7u4) set via -XX:+UseG1GC !
  • 56. How to approach JVM “tuning”?
  • 58. Preamble Do not trust consultants, blog posts, mailing list discussions etc. telling you what the “best” JVM settings for you would be. (That’s including myself!) There is no such thing as the “best” settings. It solely depends on the application and your usage.
  • 59. Typical reasons for tuning Application Growth Change in available Resources (memory, CPU etc) Actual Performance issues (unresponsiveness…) JVM-level error messages in log files
  • 60. Tools
  • 61. Process Make an assumption for load, memory and GC settings. Run Load tests, monitor and measure results. Change one setting, rinse and repeat.
  • 62. JVM settings and logging How do you find out what’s happening in your JVM? -verbose:GC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps ! [GC 64781K->22983K(71360K), 0.0242084 secs] [GC 68487K->25003K(77888K), 0.0194041 secs] [Full GC 25003K->20302K(89600K), 0.1713420 secs] [GC 70670K->21755K(90048K), 0.0054093 secs] [GC 71913K->46558K(94912K), 0.0295257 secs] [Full GC 46558K->45267K(118336K), 0.2144038 secs] [GC 88214K->84651K(133056K), 0.0674443 secs] [Full GC 84651K->84633K(171648K), 0.1739369 secs] [GC 117977K->115114K(180736K), 0.0623399 secs] [GC 158613K->157136K(201152K), 0.0591171 secs] [Full GC 157136K->157098K(254784K), 0.1868453 secs] [GC 160678K->160455K(261184K), 0.0536678 secs] 01/24 19:36:22 Debug [scheduler-1] - Next mail spool run in 15 seconds. [GC 202912K->200819K(268288K), 0.0625820 secs] [Full GC 200819K->200776K(332224K), 0.2121724 secs] [GC 213293K->212423K(339520K), 0.0426462 secs] [GC 259465K->256115K(340288K), 0.0645039 secs] [Full GC 256115K->255462K(418432K), 0.3226731 secs] [GC 281947K->279651K(421760K), 0.0530268 secs] [GC 331073K->323785K(422720K), 0.0695117 secs] [Full GC 323785K->323697K(459264K), 0.2139458 secs] [Full GC 364365K->361525K(459264K), 0.2180439 secs] [Full GC 400859K->400859K(459264K), 0.1702890 secs] [Full GC 400859K->43989K(274112K), 0.2642407 secs] [GC 95197K->93707K(273216K), 0.0338568 secs] [GC 146978K->140363K(276032K), 0.0664380 secs] [GC 193696K->189635K(277952K), 0.0630006 secs] [Full GC 189635K->189604K(425920K), 0.1913979 secs] [GC 219773K->205157K(426048K), 0.0442126 secs]
  • 63. GC tuning process Let’s look at a real world case ! !
  • 64. GC tuning results/criteria Demo of some tools ! !
  • 65. GC tuning results/criteria More often than not you’d want to optimise for low GC pauses. ! GC Throughput: 95%+ are good. Optimising for Throughput usually leads to longer GC pauses, still useful for batch operations.
  • 66. Memory sizing concerns Initial and maximum heap size: -Xms4096m, -Xmx6144m PermGen size: -XX:MaxPermSize=256m YG size: -XX:NewSize=768m, -XX:MaxNewSize=768m
  • 67. Memory sizing concerns 32bit JVM: theoretically 4GB - In reality under Windows: ~1.2-1.4GB Switching to a 64bit JVM creates ~20-30% memory overhead due to longer pointer references. Also: easier to multi-threaded create new objects than clean them up multi-threaded.
  • 68. Example Setup of extremely high volume/traffic site, optimisation goal low pause times -Xms6144m -Xmx6144m 
 -XX:NewSize=2500m -XX:MaxNewSize=2500m 
 -XX:+CMSIncrementalMode 
 -XX:+ExplicitGCInvokesConcurrent 
 -XX:+CMSPermGenSweepingEnabled 
 -XX:+CMSClassUnloadingEnabled 
 -XX:MaxPermSize=384m 
 -XX:PermSize=384m 
 -XX:+UseConcMarkSweepGC
  • 69. Overview Java 6 Max throughput Min pause time 2+ cores 1 core 2+ cores 1 core YG parYG serYG parYG parYG OldGen par OG ser OG CMS iCMS JVM Flags defaults -XX: +UseSerialGC -XX: +UseConcMarkSweepGC (implicitly using: -XX: +UseParNewGC forYG) -XX: +UseConcMarkSweepGC -XX: +CMSIncrementalMode (implicitly using: -XX: +UseParNewGC forYG)
  • 70. Overview Java 7 Max throughput Min pause time 2+ cores 1 core 2+ cores 1 core YG parYG serYG G1 parYG OldGen par OG ser OG G1 iCMS JVM Flags defaults -XX: +UseSerialGC -XX:+UseG1GC -XX: +UseConcMarkSweepGC -XX: +CMSIncrementalMode (implicitly using: -XX: +UseParNewGC forYG) (Oracle Java 7 JVMs also incorporate some JRockit features)
  • 72. Get in touch Kai Koenig Email: kai@ventego-creative.co.nz www.ventego-creative.co.nz Blog: www.bloginblack.de Twitter: @AgentK