SlideShare une entreprise Scribd logo
1  sur  50
Télécharger pour lire hors ligne
Pimp my GC
Supersonic Scala !

@pingtimeout

Scala.IO – 24&25 oct 13
/me
●

Pierre Laporte

●

“Java Performance Tuning” Trainer

●

Perfs issues, logs GC eye-compliant
http://www.pingtimeout.fr
@pingtimeout
pierre@pingtimeout.fr

@pingtimeout

Scala.IO – 24&25 oct 13
Agenda
●

42 minutes of
–
–

Fun (Practice)

–

Fun (Feedbacks)

–

Fun (Questions/Answers)

–
●

Fun (Theory)

Fun (Trolls)

Because performance is fun !

@pingtimeout

Scala.IO – 24&25 oct 13
Disclaimer
●

●

●

Be critical with the information contained in this
talk
JVM Tuning is always made on a case-by-case
basis. There is no magic, no special set of flags
that produces good results on every project.
The resemblance of any opinion,
recommendation or comment made during this
presentation to performance tuning advice is
merely coincidental.

@pingtimeout

Scala.IO – 24&25 oct 13
Weak Generational Hypothesis 101

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Weak Generational
Hypothesis

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Weak Generational
Hypothesis

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Weak Generational
Hypothesis
●

“Most objects die young”

●

Possible scales :
–

MB, GB, TB

–

Minutes, hours, days

@pingtimeout

Scala.IO – 24&25 oct 13
Examples – Weak Generational
Hypothesis
Total : 145 GB
Avg : 48 GB/j

GB

3j

@pingtimeout

Scala.IO – 24&25 oct 13
Examples – Weak Generational
Hypothesis
Total : 30 TB
Avg : 3TB/j

TB

10j

@pingtimeout

Scala.IO – 24&25 oct 13
Examples – Weak Generational
Hypothesis
●

35 GB/j
–
–

Play 2

–
●

Scala
Akka

3 TB/j
–

Java

–

Tomcat

–

Jax-RS / Spring / Hibernate...

@pingtimeout

Scala.IO – 24&25 oct 13
Examples – Weak Generational
Hypothesis
Don't forget !
–

Be critical

–

Case-by-case
analysis

–

Please don't do that
---->

@pingtimeout

Scala.IO – 24&25 oct 13
JVM Heap 101

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Memory pools

●

Java Heap – 2 memory pools
(Except for G1 GC)

●

Young Generation for... young objects

●

Old Generation for... old objects !!!
Amazing, right ?

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Memory pools

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Memory pools

●

Young Generation = Eden + Survivors

●

Every object is created in Eden*
* : except when it is too big to fit in Eden
* : except in special cases for G1 GC

@pingtimeout

Scala.IO – 24&25 oct 13
Theory – Memory pools

@pingtimeout

Scala.IO – 24&25 oct 13
Why memory pools ?!
●

Always 2 GC per JVM*
* Except for G1 GC

●

Young GC
–
–

●

Cheap
Duration mostly ≈ O(Live data in YG)

Old GC
–

Expensive

–

Duration mostly ≈ O(Live data in OG)

@pingtimeout

Scala.IO – 24&25 oct 13
Why memory pools ?!
Common GC
Name

Young Gen GC

Old Gen GC

“Parallel GC”

PSYoungGen

ParOldGen

ParNew

CMS

“CMS”
“G1 GC”

@pingtimeout

G1

Scala.IO – 24&25 oct 13
GC Duration ?!

Prove it!

@pingtimeout

Scala.IO – 24&25 oct 13
App with small live set

@pingtimeout

Scala.IO – 24&25 oct 13
App with big live set

@pingtimeout

Scala.IO – 24&25 oct 13
Experiment 1
●

1st run (SmallLiveSet)
–

50 GB heap (-ms50g -mx50g)

–

49.9GB Young Gen (-Xmn49900m)

–

GC logs

@pingtimeout

Scala.IO – 24&25 oct 13
Experiment 1
●

1st run (SmallLiveSet)
–

50 GB heap
●

–

49.9GB Young Gen
●

–

●

-ms50g -mx50g
-Xmn49900m

GC logs

Result :
–

6ms YGC pauses to free 38GB of memory

@pingtimeout

Scala.IO – 24&25 oct 13
Experiment 1 : Result
[PSYoungGen: 38329728K->6496K(44710400K)]
38329744K->6512K(46041600K),
0.0067050 secs] //...
●

38.329.728K data before GC in YG, 6.496K after

●

YG size is 44.710.400K

●

38.329.744K data before GC in heap, 6.512K after

●

Heap size is 46.041.600K

●

Total pause time : 6.7ms
@pingtimeout

Scala.IO – 24&25 oct 13
Experiment 2
●

2nd run (SmallLiveSet)
–

50 GB heap (-ms50g -mx50g)

–

10MB Young Gen (-Xmn10m)

–

GC logs

@pingtimeout

Scala.IO – 24&25 oct 13
Experiment 2
●

1st run (SmallLiveSet)
–

50 GB heap
●

–

10MB Young Gen
●

–

●

-ms50g -mx50g
-Xmn10m

GC logs

Result :
–

322ms Full GC pauses to free 52GB of memory

@pingtimeout

Scala.IO – 24&25 oct 13
Experiment 2 : Result
[Full GC
[PSYoungGen: 3072K->0K(7168K)]
[ParOldGen: 52418151K->30287K(52418560K)]
52421223K->30287K(52425728K)//...
0.3229410 secs]
●

52.418.151K data before GC in OG, 30.287K after

●

OG size is 52.418.560K

●

52.421.223K data before GC in heap, 30.287K after

●

Heap size is 52.425.728K

●

Total pause time : 322.9ms

@pingtimeout

Scala.IO – 24&25 oct 13
Experiments 1->4, Wrap up
●

1st and 2nd runs with BigLiveSet
–

Ran out of time* :-(
*: Stopped measuring at Heap occupancy ≈ 22GB

●

GC Pauses :

Live
set
Small
Big
@pingtimeout

6 millis
55 secs (Full GC)*
Scala.IO – 24&25 oct 13

322 millis (Full GC)
250 secs (Full GC)*
Immutability

Is immutability a problem ?

@pingtimeout

Scala.IO – 24&25 oct 13
Immutability

●

What does this code do ?
(GC point of view ?)

@pingtimeout

Scala.IO – 24&25 oct 13
Immutability

@pingtimeout

Scala.IO – 24&25 oct 13
Immutability

●

What does this code do ?
–

Create more temporary objects that dies young

–

Respect Weak Generational Hypothesis

@pingtimeout

Scala.IO – 24&25 oct 13
Immutability

●

Consequences compared to mutable state
–

GC will run more frequently

–

GC time will be short
O(Live data in YG)

@pingtimeout

Scala.IO – 24&25 oct 13
Tuning for immutability
●

Reduce YGC frequency (for ParallelGC and
CMS)
–

Identify allocation rate (MB/seconds)

–

Define the GC interval (seconds between GCs)
=> Set Eden = Allocation rate * GC interval

@pingtimeout

Scala.IO – 24&25 oct 13
Tuning for immutability
●

Reduce YGC frequency (for ParallelGC and
CMS)
–

AR = 200 MB/s

–

Desired interval = 1 YGC every 4 seconds
=> Set Eden to 800 MB (Young to 1 GB)
-Xmn1g

@pingtimeout

Scala.IO – 24&25 oct 13
Poney Pause

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC time !

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC
●

Idea
–

Split the heap in
2048 regions

–

Associate on-the-fly one
region to a memory pool

–

Increase/Shrink memory
pool at runtime

http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All
@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC
●

Memory pools :
–
–

Old

–

●

Young (Eden, Survivors)
Humongous

Humongous:
–

Objects >= 50% region

http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All
@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC
●

1 ½ GC algorithm:
–

Always collect Young Gen

–

Collect Old Gen if possible
●
●
●
●

●

Best regions only
Time budget large enough
Preconditions
“mixed” collection

G1 is self-tuning
http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning
●

Define GC time budget
-XX:MaxGCPauseMillis=<N>
-XX:GCPauseIntervalMillis=<M>

●

Set Xms == Xmx

●

Drop all other GC-related flags
-Xmn, -XX:TenuringThreshold, -XX:NewRatio
-XX:InitiatingHeapOccupancyPercent, …

●

Don't try to outsmart the GC

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning
●

Enable GC logs
-Xloggc:gc.log
-XX:+PrintGCDetails
-XX:+PrintTenuringDistribution
-XX:+PrintGCCause
-XX:+PrintAdaptiveSizePolicy

●

Wait and see

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning – Low hanging fruits
●

Eliminate Humongous allocations
–

Humongous regions collected only at Full GC

–

Or when empty

[G1Ergonomics (Concurrent Cycles) request concurrent cycle
initiation, reason: occupancy higher than threshold, occupancy: 0
bytes, allocation request: 79012360 bytes, threshold: 47185920 bytes
(45.00 %), source: concurrent humongous allocation]
[G1Ergonomics (Concurrent Cycles) request concurrent cycle
initiation, reason: requested by GC cause, GC cause: G1 Humongous
Allocation]

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning – Low hanging fruits
●

Eliminate Humongous allocations
–

Humongous regions collected only at Full GC

–

Or when empty

2013-10-21T19:23:48.758+0200:
[GC pause (G1 Humongous Allocation) (young) (initial-mark)
Desired survivor size 1572864 bytes, new threshold 15 (max 15)
, 0.0015120 secs]

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning – Low hanging fruits
●

Eliminate Humongous
allocations
–
–

●

Track your big allocations
Kill'em !

Why ?
–

Fragments the heap

–

Can cause evacuations
failures

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning – Low hanging fruits
●

Get rid of “mixed collections”
–

Increase heap size

–

Set a higher threshold for mixed collections
-XX:InitiatingHeapOccupancyPercent=<N>

●

Why ?
–

Some phases of G1 are STW (like “baaaaad”)

–

G1 goal : find the best candidates among all old
regions

@pingtimeout

Scala.IO – 24&25 oct 13
G1 GC Tuning – Low hanging fruits
●

Eliminate “Evacuation/Allocation failures”
–

They are our good old Full Gcs

[GC pause (G1 Evacuation Pause) (young)
//...
[Full GC (Allocation Failure)
5860M->2690M(7000M), 0.9824032 secs]

@pingtimeout

Scala.IO – 24&25 oct 13
Summary
●

Performance is fun !

●

Understand what you do

●

Immutability is not an issue (by itself)
–

Bad code is.

●

GC Duration ≈ O(Live data)

●

G1 is self-tuning
–

Try it :-)

@pingtimeout

Scala.IO – 24&25 oct 13
Thank you for listening !

For more information :
http://www.pingtimeout.fr
@pingtimeout
pierre@pingtimeout.fr

@pingtimeout

Scala.IO – 24&25 oct 13

Contenu connexe

Tendances

Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in Realtime
Tikal Knowledge
 
pipeline_structure_overview
pipeline_structure_overviewpipeline_structure_overview
pipeline_structure_overview
setitesuk
 

Tendances (20)

Kafka short
Kafka shortKafka short
Kafka short
 
Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in Realtime
 
Heatmap
HeatmapHeatmap
Heatmap
 
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
 
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
 
Low pause GC in HotSpot
Low pause GC in HotSpotLow pause GC in HotSpot
Low pause GC in HotSpot
 
Tp cms-g1-v4
Tp cms-g1-v4Tp cms-g1-v4
Tp cms-g1-v4
 
pipeline_structure_overview
pipeline_structure_overviewpipeline_structure_overview
pipeline_structure_overview
 
Genomics algorithms on digital NISQ accelerators - 2019-01-25
Genomics algorithms on digital NISQ accelerators - 2019-01-25Genomics algorithms on digital NISQ accelerators - 2019-01-25
Genomics algorithms on digital NISQ accelerators - 2019-01-25
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 
Parallel Prime Number Generation Using The Sieve of Eratosthenes
Parallel Prime Number Generation Using The Sieve of EratosthenesParallel Prime Number Generation Using The Sieve of Eratosthenes
Parallel Prime Number Generation Using The Sieve of Eratosthenes
 
Exploring Garbage Collection
Exploring Garbage CollectionExploring Garbage Collection
Exploring Garbage Collection
 
HiPEAC'19 Tutorial on Quantum algorithms using QX - 2019-01-23
HiPEAC'19 Tutorial on Quantum algorithms using QX - 2019-01-23HiPEAC'19 Tutorial on Quantum algorithms using QX - 2019-01-23
HiPEAC'19 Tutorial on Quantum algorithms using QX - 2019-01-23
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOM
 
Java ME API Next
 Java ME API Next Java ME API Next
Java ME API Next
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, Wix
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展
 
«Продакшн в Kotlin DSL» Сергей Рыбалкин
«Продакшн в Kotlin DSL» Сергей Рыбалкин«Продакшн в Kotlin DSL» Сергей Рыбалкин
«Продакшн в Kotlin DSL» Сергей Рыбалкин
 
Clr jvm implementation differences
Clr jvm implementation differencesClr jvm implementation differences
Clr jvm implementation differences
 

Similaire à Pimp my gc - Supersonic Scala

marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badoo
Marko Kevac
 

Similaire à Pimp my gc - Supersonic Scala (20)

Performance Optimization of CGYRO for Multiscale Turbulence Simulations
Performance Optimization of CGYRO for Multiscale Turbulence SimulationsPerformance Optimization of CGYRO for Multiscale Turbulence Simulations
Performance Optimization of CGYRO for Multiscale Turbulence Simulations
 
Hotspot gc
Hotspot gcHotspot gc
Hotspot gc
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
 
GC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerGC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance Engineer
 
CGYRO Performance on Power9 CPUs and Volta GPUS
CGYRO Performance on Power9 CPUs and Volta GPUSCGYRO Performance on Power9 CPUs and Volta GPUS
CGYRO Performance on Power9 CPUs and Volta GPUS
 
Tuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesTuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issues
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
 
GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
Progress_190130
Progress_190130Progress_190130
Progress_190130
 
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
 
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo..."Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
 
Can FPGAs Compete with GPUs?
Can FPGAs Compete with GPUs?Can FPGAs Compete with GPUs?
Can FPGAs Compete with GPUs?
 
Tackling 400 MHz Timing Closure
Tackling 400 MHz Timing ClosureTackling 400 MHz Timing Closure
Tackling 400 MHz Timing Closure
 
marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badoo
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Speedrunning the Open Street Map osm2pgsql Loader
Speedrunning the Open Street Map osm2pgsql LoaderSpeedrunning the Open Street Map osm2pgsql Loader
Speedrunning the Open Street Map osm2pgsql Loader
 
Beyond the DSL - Unlocking the power of Kafka Streams with the Processor API
Beyond the DSL - Unlocking the power of Kafka Streams with the Processor APIBeyond the DSL - Unlocking the power of Kafka Streams with the Processor API
Beyond the DSL - Unlocking the power of Kafka Streams with the Processor API
 
Pseudo GTID and Easy MySQL Replication Topology Management
Pseudo GTID and Easy MySQL Replication Topology ManagementPseudo GTID and Easy MySQL Replication Topology Management
Pseudo GTID and Easy MySQL Replication Topology Management
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
 

Plus de Pierre Laporte

Plus de Pierre Laporte (7)

Leveraging chaos mesh in Astra Serverless testing
Leveraging chaos mesh in Astra Serverless testingLeveraging chaos mesh in Astra Serverless testing
Leveraging chaos mesh in Astra Serverless testing
 
Les race conditions, nos très chères amies
Les race conditions, nos très chères amiesLes race conditions, nos très chères amies
Les race conditions, nos très chères amies
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarking
 
Lyon jug-how-to-fail-at-benchmarking
Lyon jug-how-to-fail-at-benchmarkingLyon jug-how-to-fail-at-benchmarking
Lyon jug-how-to-fail-at-benchmarking
 
La BDD, l'enfant gâté des SI
La BDD, l'enfant gâté des SILa BDD, l'enfant gâté des SI
La BDD, l'enfant gâté des SI
 
How to fail at benchmarking?
How to fail at benchmarking?How to fail at benchmarking?
How to fail at benchmarking?
 
Building a lock profiler on the JVM
Building a lock profiler on the JVMBuilding a lock profiler on the JVM
Building a lock profiler on the JVM
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Pimp my gc - Supersonic Scala

  • 1. Pimp my GC Supersonic Scala ! @pingtimeout Scala.IO – 24&25 oct 13
  • 2. /me ● Pierre Laporte ● “Java Performance Tuning” Trainer ● Perfs issues, logs GC eye-compliant http://www.pingtimeout.fr @pingtimeout pierre@pingtimeout.fr @pingtimeout Scala.IO – 24&25 oct 13
  • 3. Agenda ● 42 minutes of – – Fun (Practice) – Fun (Feedbacks) – Fun (Questions/Answers) – ● Fun (Theory) Fun (Trolls) Because performance is fun ! @pingtimeout Scala.IO – 24&25 oct 13
  • 4. Disclaimer ● ● ● Be critical with the information contained in this talk JVM Tuning is always made on a case-by-case basis. There is no magic, no special set of flags that produces good results on every project. The resemblance of any opinion, recommendation or comment made during this presentation to performance tuning advice is merely coincidental. @pingtimeout Scala.IO – 24&25 oct 13
  • 5. Weak Generational Hypothesis 101 @pingtimeout Scala.IO – 24&25 oct 13
  • 6. Theory – Weak Generational Hypothesis @pingtimeout Scala.IO – 24&25 oct 13
  • 7. Theory – Weak Generational Hypothesis @pingtimeout Scala.IO – 24&25 oct 13
  • 8. Theory – Weak Generational Hypothesis ● “Most objects die young” ● Possible scales : – MB, GB, TB – Minutes, hours, days @pingtimeout Scala.IO – 24&25 oct 13
  • 9. Examples – Weak Generational Hypothesis Total : 145 GB Avg : 48 GB/j GB 3j @pingtimeout Scala.IO – 24&25 oct 13
  • 10. Examples – Weak Generational Hypothesis Total : 30 TB Avg : 3TB/j TB 10j @pingtimeout Scala.IO – 24&25 oct 13
  • 11. Examples – Weak Generational Hypothesis ● 35 GB/j – – Play 2 – ● Scala Akka 3 TB/j – Java – Tomcat – Jax-RS / Spring / Hibernate... @pingtimeout Scala.IO – 24&25 oct 13
  • 12. Examples – Weak Generational Hypothesis Don't forget ! – Be critical – Case-by-case analysis – Please don't do that ----> @pingtimeout Scala.IO – 24&25 oct 13
  • 14. Theory – Memory pools ● Java Heap – 2 memory pools (Except for G1 GC) ● Young Generation for... young objects ● Old Generation for... old objects !!! Amazing, right ? @pingtimeout Scala.IO – 24&25 oct 13
  • 15. Theory – Memory pools @pingtimeout Scala.IO – 24&25 oct 13
  • 16. Theory – Memory pools ● Young Generation = Eden + Survivors ● Every object is created in Eden* * : except when it is too big to fit in Eden * : except in special cases for G1 GC @pingtimeout Scala.IO – 24&25 oct 13
  • 17. Theory – Memory pools @pingtimeout Scala.IO – 24&25 oct 13
  • 18. Why memory pools ?! ● Always 2 GC per JVM* * Except for G1 GC ● Young GC – – ● Cheap Duration mostly ≈ O(Live data in YG) Old GC – Expensive – Duration mostly ≈ O(Live data in OG) @pingtimeout Scala.IO – 24&25 oct 13
  • 19. Why memory pools ?! Common GC Name Young Gen GC Old Gen GC “Parallel GC” PSYoungGen ParOldGen ParNew CMS “CMS” “G1 GC” @pingtimeout G1 Scala.IO – 24&25 oct 13
  • 20. GC Duration ?! Prove it! @pingtimeout Scala.IO – 24&25 oct 13
  • 21. App with small live set @pingtimeout Scala.IO – 24&25 oct 13
  • 22. App with big live set @pingtimeout Scala.IO – 24&25 oct 13
  • 23. Experiment 1 ● 1st run (SmallLiveSet) – 50 GB heap (-ms50g -mx50g) – 49.9GB Young Gen (-Xmn49900m) – GC logs @pingtimeout Scala.IO – 24&25 oct 13
  • 24. Experiment 1 ● 1st run (SmallLiveSet) – 50 GB heap ● – 49.9GB Young Gen ● – ● -ms50g -mx50g -Xmn49900m GC logs Result : – 6ms YGC pauses to free 38GB of memory @pingtimeout Scala.IO – 24&25 oct 13
  • 25. Experiment 1 : Result [PSYoungGen: 38329728K->6496K(44710400K)] 38329744K->6512K(46041600K), 0.0067050 secs] //... ● 38.329.728K data before GC in YG, 6.496K after ● YG size is 44.710.400K ● 38.329.744K data before GC in heap, 6.512K after ● Heap size is 46.041.600K ● Total pause time : 6.7ms @pingtimeout Scala.IO – 24&25 oct 13
  • 26. Experiment 2 ● 2nd run (SmallLiveSet) – 50 GB heap (-ms50g -mx50g) – 10MB Young Gen (-Xmn10m) – GC logs @pingtimeout Scala.IO – 24&25 oct 13
  • 27. Experiment 2 ● 1st run (SmallLiveSet) – 50 GB heap ● – 10MB Young Gen ● – ● -ms50g -mx50g -Xmn10m GC logs Result : – 322ms Full GC pauses to free 52GB of memory @pingtimeout Scala.IO – 24&25 oct 13
  • 28. Experiment 2 : Result [Full GC [PSYoungGen: 3072K->0K(7168K)] [ParOldGen: 52418151K->30287K(52418560K)] 52421223K->30287K(52425728K)//... 0.3229410 secs] ● 52.418.151K data before GC in OG, 30.287K after ● OG size is 52.418.560K ● 52.421.223K data before GC in heap, 30.287K after ● Heap size is 52.425.728K ● Total pause time : 322.9ms @pingtimeout Scala.IO – 24&25 oct 13
  • 29. Experiments 1->4, Wrap up ● 1st and 2nd runs with BigLiveSet – Ran out of time* :-( *: Stopped measuring at Heap occupancy ≈ 22GB ● GC Pauses : Live set Small Big @pingtimeout 6 millis 55 secs (Full GC)* Scala.IO – 24&25 oct 13 322 millis (Full GC) 250 secs (Full GC)*
  • 30. Immutability Is immutability a problem ? @pingtimeout Scala.IO – 24&25 oct 13
  • 31. Immutability ● What does this code do ? (GC point of view ?) @pingtimeout Scala.IO – 24&25 oct 13
  • 33. Immutability ● What does this code do ? – Create more temporary objects that dies young – Respect Weak Generational Hypothesis @pingtimeout Scala.IO – 24&25 oct 13
  • 34. Immutability ● Consequences compared to mutable state – GC will run more frequently – GC time will be short O(Live data in YG) @pingtimeout Scala.IO – 24&25 oct 13
  • 35. Tuning for immutability ● Reduce YGC frequency (for ParallelGC and CMS) – Identify allocation rate (MB/seconds) – Define the GC interval (seconds between GCs) => Set Eden = Allocation rate * GC interval @pingtimeout Scala.IO – 24&25 oct 13
  • 36. Tuning for immutability ● Reduce YGC frequency (for ParallelGC and CMS) – AR = 200 MB/s – Desired interval = 1 YGC every 4 seconds => Set Eden to 800 MB (Young to 1 GB) -Xmn1g @pingtimeout Scala.IO – 24&25 oct 13
  • 38. G1 GC time ! @pingtimeout Scala.IO – 24&25 oct 13
  • 39. G1 GC ● Idea – Split the heap in 2048 regions – Associate on-the-fly one region to a memory pool – Increase/Shrink memory pool at runtime http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All @pingtimeout Scala.IO – 24&25 oct 13
  • 40. G1 GC ● Memory pools : – – Old – ● Young (Eden, Survivors) Humongous Humongous: – Objects >= 50% region http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All @pingtimeout Scala.IO – 24&25 oct 13
  • 41. G1 GC ● 1 ½ GC algorithm: – Always collect Young Gen – Collect Old Gen if possible ● ● ● ● ● Best regions only Time budget large enough Preconditions “mixed” collection G1 is self-tuning http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All @pingtimeout Scala.IO – 24&25 oct 13
  • 42. G1 GC Tuning ● Define GC time budget -XX:MaxGCPauseMillis=<N> -XX:GCPauseIntervalMillis=<M> ● Set Xms == Xmx ● Drop all other GC-related flags -Xmn, -XX:TenuringThreshold, -XX:NewRatio -XX:InitiatingHeapOccupancyPercent, … ● Don't try to outsmart the GC @pingtimeout Scala.IO – 24&25 oct 13
  • 43. G1 GC Tuning ● Enable GC logs -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintTenuringDistribution -XX:+PrintGCCause -XX:+PrintAdaptiveSizePolicy ● Wait and see @pingtimeout Scala.IO – 24&25 oct 13
  • 44. G1 GC Tuning – Low hanging fruits ● Eliminate Humongous allocations – Humongous regions collected only at Full GC – Or when empty [G1Ergonomics (Concurrent Cycles) request concurrent cycle initiation, reason: occupancy higher than threshold, occupancy: 0 bytes, allocation request: 79012360 bytes, threshold: 47185920 bytes (45.00 %), source: concurrent humongous allocation] [G1Ergonomics (Concurrent Cycles) request concurrent cycle initiation, reason: requested by GC cause, GC cause: G1 Humongous Allocation] @pingtimeout Scala.IO – 24&25 oct 13
  • 45. G1 GC Tuning – Low hanging fruits ● Eliminate Humongous allocations – Humongous regions collected only at Full GC – Or when empty 2013-10-21T19:23:48.758+0200: [GC pause (G1 Humongous Allocation) (young) (initial-mark) Desired survivor size 1572864 bytes, new threshold 15 (max 15) , 0.0015120 secs] @pingtimeout Scala.IO – 24&25 oct 13
  • 46. G1 GC Tuning – Low hanging fruits ● Eliminate Humongous allocations – – ● Track your big allocations Kill'em ! Why ? – Fragments the heap – Can cause evacuations failures @pingtimeout Scala.IO – 24&25 oct 13
  • 47. G1 GC Tuning – Low hanging fruits ● Get rid of “mixed collections” – Increase heap size – Set a higher threshold for mixed collections -XX:InitiatingHeapOccupancyPercent=<N> ● Why ? – Some phases of G1 are STW (like “baaaaad”) – G1 goal : find the best candidates among all old regions @pingtimeout Scala.IO – 24&25 oct 13
  • 48. G1 GC Tuning – Low hanging fruits ● Eliminate “Evacuation/Allocation failures” – They are our good old Full Gcs [GC pause (G1 Evacuation Pause) (young) //... [Full GC (Allocation Failure) 5860M->2690M(7000M), 0.9824032 secs] @pingtimeout Scala.IO – 24&25 oct 13
  • 49. Summary ● Performance is fun ! ● Understand what you do ● Immutability is not an issue (by itself) – Bad code is. ● GC Duration ≈ O(Live data) ● G1 is self-tuning – Try it :-) @pingtimeout Scala.IO – 24&25 oct 13
  • 50. Thank you for listening ! For more information : http://www.pingtimeout.fr @pingtimeout pierre@pingtimeout.fr @pingtimeout Scala.IO – 24&25 oct 13