SlideShare une entreprise Scribd logo
1  sur  72
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

Contenu connexe

Tendances

Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVMRomain Schlick
 
(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWSAmazon Web Services
 
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
 
Kubernetes - Security Journey
Kubernetes - Security JourneyKubernetes - Security Journey
Kubernetes - Security JourneyJerry Jalava
 
Panamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶPanamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶYasumasa Suenaga
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
 
Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink Slim Baltagi
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?NAVER D2
 
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Henning Jacobs
 
(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...
(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...
(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...Amazon Web Services
 
Cloud Native Days Korea 2019 - kakao's k8s_as_a_service
Cloud Native Days Korea 2019 - kakao's k8s_as_a_serviceCloud Native Days Korea 2019 - kakao's k8s_as_a_service
Cloud Native Days Korea 2019 - kakao's k8s_as_a_serviceDennis Hong
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewBob Killen
 
Setting Up a TIG Stack for Your Testing
Setting Up a TIG Stack for Your TestingSetting Up a TIG Stack for Your Testing
Setting Up a TIG Stack for Your TestingJet Liu
 
Prometheus (Prometheus London, 2016)
Prometheus (Prometheus London, 2016)Prometheus (Prometheus London, 2016)
Prometheus (Prometheus London, 2016)Brian Brazil
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machineAlexei Starovoitov
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 

Tendances (20)

Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVM
 
(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS
 
Livre blanc docker
Livre blanc docker Livre blanc docker
Livre blanc docker
 
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)
 
Kubernetes - Security Journey
Kubernetes - Security JourneyKubernetes - Security Journey
Kubernetes - Security Journey
 
Panamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶPanamaを先取り!? JVMCIでJITと遊ぶ
Panamaを先取り!? JVMCIでJITと遊ぶ
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
 
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
 
(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...
(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...
(APP307) Leverage the Cloud with a Blue/Green Deployment Architecture | AWS r...
 
Cloud Native Days Korea 2019 - kakao's k8s_as_a_service
Cloud Native Days Korea 2019 - kakao's k8s_as_a_serviceCloud Native Days Korea 2019 - kakao's k8s_as_a_service
Cloud Native Days Korea 2019 - kakao's k8s_as_a_service
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive Overview
 
Setting Up a TIG Stack for Your Testing
Setting Up a TIG Stack for Your TestingSetting Up a TIG Stack for Your Testing
Setting Up a TIG Stack for Your Testing
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
Prometheus (Prometheus London, 2016)
Prometheus (Prometheus London, 2016)Prometheus (Prometheus London, 2016)
Prometheus (Prometheus London, 2016)
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 

En vedette

En vedette (6)

Hey My Web App is Slow Where is the Problem
Hey My Web App is Slow Where is the ProblemHey My Web App is Slow Where is the Problem
Hey My Web App is Slow Where is the Problem
 
How we rest
How we restHow we rest
How we rest
 
ITB2015 - Monitoring and Tracking Your Web Applications
ITB2015 - Monitoring and Tracking Your Web ApplicationsITB2015 - Monitoring and Tracking Your Web Applications
ITB2015 - Monitoring and Tracking Your Web Applications
 
The Art and Science of using LinkedIn
The Art and Science of using LinkedInThe Art and Science of using LinkedIn
The Art and Science of using LinkedIn
 
Using LinkedIn for Organisational Goals
Using LinkedIn for Organisational GoalsUsing LinkedIn for Organisational Goals
Using LinkedIn for Organisational Goals
 
ColdFusion for Penetration Testers
ColdFusion for Penetration TestersColdFusion for Penetration Testers
ColdFusion for Penetration Testers
 

Similaire à The JVM is your friend

Garbage First and you
Garbage First and youGarbage First and you
Garbage First and youKai Koenig
 
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
 
[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
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-productionVladimir Khokhryakov
 
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
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
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
 

Similaire à The JVM is your friend (20)

Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
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
 
[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 performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
 
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
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
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
 

Plus de Kai Koenig

Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Kai Koenig
 
Android 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsAndroid 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsKai Koenig
 
Android 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsAndroid 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsKai Koenig
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesKai Koenig
 
Kotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKai Koenig
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKai Koenig
 
Improving your CFML code quality
Improving your CFML code qualityImproving your CFML code quality
Improving your CFML code qualityKai Koenig
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampKai Koenig
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Kai Koenig
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinKai Koenig
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API BlueprintKai Koenig
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
Introduction to Data Mining
Introduction to Data MiningIntroduction to Data Mining
Introduction to Data MiningKai Koenig
 
Real World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileReal World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileKai Koenig
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Kai Koenig
 
There's a time and a place
There's a time and a placeThere's a time and a place
There's a time and a placeKai Koenig
 
Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Kai Koenig
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developersKai Koenig
 

Plus de Kai Koenig (20)

Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones
 
Android 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsAndroid 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture Components
 
Android 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsAndroid 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other things
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutes
 
Kotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 version
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a tree
 
Improving your CFML code quality
Improving your CFML code qualityImproving your CFML code quality
Improving your CFML code quality
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with Kotlin
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API Blueprint
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Introduction to Data Mining
Introduction to Data MiningIntroduction to Data Mining
Introduction to Data Mining
 
Real World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileReal World Lessons in jQuery Mobile
Real World Lessons in jQuery Mobile
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
There's a time and a place
There's a time and a placeThere's a time and a place
There's a time and a place
 
Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developers
 

Dernier

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
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
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
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
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
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
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
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
 

Dernier (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
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...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
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...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
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...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
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
 

The 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