SlideShare uma empresa Scribd logo
1 de 37
GARBAGE COLLECTION:
@EvaAndreasson, @Cloudera
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/garbage-collection-benefits
Presented at QCon London
www.qconlondon.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
AGENDA
2
• Garbage Collection (101)
• The Good
• The Bad
• The Ugly
• The Challenge!
GARBAGE COLLECTION
3
"When you have to shoot, shoot - don't talk!"
WHAT IS GARBAGE COLLECTION (GC)?
4
• What is a Java Virtual Machine (JVM)?
• Runtime code compilation
• Dynamic memory management
• What is dynamic memory management?
• Does not require explicit memory allocation (when programming)
• Frees up memory no longer referenced
JAVA HEAP - SPOTLIGHT
5
• The mythical (?) Java heap
• -Xmx, -Xms
• Top: RES / RSS --- total memory footprint
• Full = a thread fails to allocate a new object
Java Heap: Where all Java Objects get allocated
JVM Internal
Memory:
• Code cache
• VM Threads
• VM & GC Structs
REFERENCE COUNTING VS. TRACING
6
• Reference Counting
• Plus a counter for each reference to an object
• Subtract for each removed reference to an object
• When 0, reclaim the heap space occupied by that object
• Simple to reclaim
• Hard to maintain counters
• Difficult (costly) to handle cyclic structures
REFERENCE COUNTING VS. TRACING
7
• Tracing
• Identify roots (thread stacks, …, etc)
• Trace all references from those objects, recursively
• Anything not found is garbage
• Simple to maintain, handles cyclic structures
• Needs to trace all live objects before reclaiming memory
SIDE NOTE: WHAT IS FRAGMENTATION?
8
New
Object
FULL
HEAP
POST
GC
FRAGMENTS
New
Object
COPYING VS. MARK’N’SWEEP
9
• Copying
• Split the Java Heap into sections
• Allocate only in the one section, until full
• Stop the world
• Trace all reachable objects in the section and move (copy) them to another section
• Reclaim the original section as “free”
• Prevents fragmentation
• Wasteful in space
• Stops the world
COPYING VS. MARK’N’SWEEP
10
• Mark’n’sweep
• Allocate objects in the entire heap space, until full
• Trace and mark live objects (no moving)
• When all live objects are marked, sweep all non-marked areas (build free lists)
• Allocation can now happen at the address spaces of the free lists
• Allows entire heap for allocation
• Suffers from fragmentation
• Over time free list chunks too small to fit new objects
PARALLEL VS. CONCURRENT
11
• Parallel
• Stop the world
• Allow all available threads to do GC work
• Allow allocation once the entire GC cycle is complete
• Concurrent
• Allow some of the available threads to do as much GC work in the background as
possible, without impacting running applications too much
• Iterative marking, track areas where running applications have made
modifications and re-mark
• Needs to start in time…
GENERATIONAL
12
• Generational (-Xns)
• Most objects die young
• Define a space (could be distributed) on the heap for allocation
• The rest of the heap is considered “old space” or “old generation”
• As objects “survive” garbage collection in the young space (a.k.a. nursery), promote
them to the old space
• Reduces the speed of fragmentation of the heap
• Can use different algorithm than old space: copying, parallel and copying…
COMPACTING
13
• Compaction
• The operation of moving objects on the heap together
• Opens up larger consecutive spaces of free memory
• Mitigates fragmentation
• Compaction area size
• Incremental
• Intelligent
• Parallel mark’n’sweep and copying implementations usually do this during their normal
stop the world phase
• Concurrent mark’n’sweep needs to handle this somehow, eventually…
14
GARBAGE IS GOOD!
15
• Wait…what now?!?
THE GOOD
16
• Garbage means you are using Java the way it was intended – truly object oriented!!
• Without GC, the world would have looked differently
• Java helped software (and hardware) innovation
• Programming became “mainstream” (no offence…)
• Coding could be done faster
• More jobs were created
• More products and businesses popped up
• If tuned “right”…
17
THE DESERT OF TUNING
18
• Endless tuning and re-tuning
• Rant-warning!
• Ok for some application profiles
• Time window applications
• Client applications
• Specially architected applications (new-objects only)
• Applications not sensitive to latency
A DESERT SURVIVAL KIT
19
• Chose the right GC algorithm for your application
• Understand your application allocation rate (in production) and allocate enough heap
• Measure the right thing!!
• Test != Production
• Not average or std dev – latency is not a standard distribution!
• Check out: Gil Tene’s jHiccup tool (and his talk) – a great new approach!
20
RECOGNIZE THIS?
21
• Initially everything is fine, GCs are happening without much impact
• Over time application seems to freeze up on occasion, or starts responding slower and
slower
• Soon, the entire application hangs, affecting other servers to start firing up
• Eventually the JVM gives up and “crashes”
• GC logs show back-to-back GCs and in the end some sort of Out Of Memory, Allocation,
or Promotion Error
WHAT REALLY HAPPENS
22
• When allocation fails, GC is triggered
• GC is doing its job, but no memory opens up (everything is live)
• Back-to-back GCs, still no new memory => OOME..
• OOME indicates not enough heap for your allocation rate
WHY NOT CONFIGURE A LARGER HEAP?
23
“GC PAUSES”
24
REMEMBER FRAGMENTATION?
25
New
ObjectFULL
HEAP
POST
x GCs
FRAGMENTS
New
Object
…IF multiple GCs later…
REMEMBER COMPACTION?
26
• Most GC implementations do not handle compaction well
• Moving objects is costly – stop the world is easy
• Generational added
• Tuning options and heuristics added
• Only one JVM that I know of that does compaction concurrently today (Zing)
PREPARE FOR THE REAL VILLAIN…
27
"There are two kinds of people in the world my friend, those with a rope around their
neck and the people that have the job of doing the cutting!"
STOP THE WORLD
OPERATIONS!!!
28
STOP THE WORLD OPERATIONS
29
• Prevents efficient memory utilization
• Creates complex JVM deployments
• Sends you out in the tuning desert…
SUMMARY
30
• Garbage is GOOD
• The need to tune is BAD
• Stop the world operations are UGLY
I CHALLENGE THEE
31
“You see in this world, there’s two kinds of people my friend…
…those with loaded guns and those who dig…you dig!”
JOIN THE FUTURE OF JAVA!
32
• Open JDK is a great opportunity for innovation - join the community!
• Have all GC algorithms been invented yet?
• How do we enable a better world of self-tuning, adaptive JVMs?
• Relieve the admin of the pain of the tuning!
• How about fixing the core problem?
• Implement concurrent compaction
• Be creative around allocation / dynamic allocation rates!
33
Q&A
34
@EvaAndreasson
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/garbage-
collection-benefits

Mais conteúdo relacionado

Destaque

Garbage collection
Garbage collectionGarbage collection
Garbage collectionSomya Bagai
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage CollectionAzul Systems Inc.
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage CollectionDoug Hawkins
 
Basic Garbage Collection Techniques
Basic  Garbage  Collection  TechniquesBasic  Garbage  Collection  Techniques
Basic Garbage Collection TechniquesAn Khuong
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
55 New Features in JDK 9
55 New Features in JDK 955 New Features in JDK 9
55 New Features in JDK 9Simon Ritter
 
G1 Garbage Collector: Details and Tuning
G1 Garbage Collector: Details and TuningG1 Garbage Collector: Details and Tuning
G1 Garbage Collector: Details and TuningSimone Bordet
 

Destaque (11)

Heap Management
Heap ManagementHeap Management
Heap Management
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
How long can you afford to Stop The World?
How long can you afford to Stop The World?How long can you afford to Stop The World?
How long can you afford to Stop The World?
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage Collection
 
Java GC
Java GCJava GC
Java GC
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
Basic Garbage Collection Techniques
Basic  Garbage  Collection  TechniquesBasic  Garbage  Collection  Techniques
Basic Garbage Collection Techniques
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
55 New Features in JDK 9
55 New Features in JDK 955 New Features in JDK 9
55 New Features in JDK 9
 
G1 Garbage Collector: Details and Tuning
G1 Garbage Collector: Details and TuningG1 Garbage Collector: Details and Tuning
G1 Garbage Collector: Details and Tuning
 

Mais de C4Media

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoC4Media
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileC4Media
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020C4Media
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 

Mais de C4Media (20)

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy Mobile
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Garbage Collection is Good!

  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /garbage-collection-benefits
  • 3. Presented at QCon London www.qconlondon.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 4. AGENDA 2 • Garbage Collection (101) • The Good • The Bad • The Ugly • The Challenge!
  • 5. GARBAGE COLLECTION 3 "When you have to shoot, shoot - don't talk!"
  • 6. WHAT IS GARBAGE COLLECTION (GC)? 4 • What is a Java Virtual Machine (JVM)? • Runtime code compilation • Dynamic memory management • What is dynamic memory management? • Does not require explicit memory allocation (when programming) • Frees up memory no longer referenced
  • 7. JAVA HEAP - SPOTLIGHT 5 • The mythical (?) Java heap • -Xmx, -Xms • Top: RES / RSS --- total memory footprint • Full = a thread fails to allocate a new object Java Heap: Where all Java Objects get allocated JVM Internal Memory: • Code cache • VM Threads • VM & GC Structs
  • 8. REFERENCE COUNTING VS. TRACING 6 • Reference Counting • Plus a counter for each reference to an object • Subtract for each removed reference to an object • When 0, reclaim the heap space occupied by that object • Simple to reclaim • Hard to maintain counters • Difficult (costly) to handle cyclic structures
  • 9. REFERENCE COUNTING VS. TRACING 7 • Tracing • Identify roots (thread stacks, …, etc) • Trace all references from those objects, recursively • Anything not found is garbage • Simple to maintain, handles cyclic structures • Needs to trace all live objects before reclaiming memory
  • 10. SIDE NOTE: WHAT IS FRAGMENTATION? 8 New Object FULL HEAP POST GC FRAGMENTS New Object
  • 11. COPYING VS. MARK’N’SWEEP 9 • Copying • Split the Java Heap into sections • Allocate only in the one section, until full • Stop the world • Trace all reachable objects in the section and move (copy) them to another section • Reclaim the original section as “free” • Prevents fragmentation • Wasteful in space • Stops the world
  • 12. COPYING VS. MARK’N’SWEEP 10 • Mark’n’sweep • Allocate objects in the entire heap space, until full • Trace and mark live objects (no moving) • When all live objects are marked, sweep all non-marked areas (build free lists) • Allocation can now happen at the address spaces of the free lists • Allows entire heap for allocation • Suffers from fragmentation • Over time free list chunks too small to fit new objects
  • 13. PARALLEL VS. CONCURRENT 11 • Parallel • Stop the world • Allow all available threads to do GC work • Allow allocation once the entire GC cycle is complete • Concurrent • Allow some of the available threads to do as much GC work in the background as possible, without impacting running applications too much • Iterative marking, track areas where running applications have made modifications and re-mark • Needs to start in time…
  • 14. GENERATIONAL 12 • Generational (-Xns) • Most objects die young • Define a space (could be distributed) on the heap for allocation • The rest of the heap is considered “old space” or “old generation” • As objects “survive” garbage collection in the young space (a.k.a. nursery), promote them to the old space • Reduces the speed of fragmentation of the heap • Can use different algorithm than old space: copying, parallel and copying…
  • 15. COMPACTING 13 • Compaction • The operation of moving objects on the heap together • Opens up larger consecutive spaces of free memory • Mitigates fragmentation • Compaction area size • Incremental • Intelligent • Parallel mark’n’sweep and copying implementations usually do this during their normal stop the world phase • Concurrent mark’n’sweep needs to handle this somehow, eventually…
  • 16. 14
  • 17. GARBAGE IS GOOD! 15 • Wait…what now?!?
  • 18. THE GOOD 16 • Garbage means you are using Java the way it was intended – truly object oriented!! • Without GC, the world would have looked differently • Java helped software (and hardware) innovation • Programming became “mainstream” (no offence…) • Coding could be done faster • More jobs were created • More products and businesses popped up • If tuned “right”…
  • 19. 17
  • 20. THE DESERT OF TUNING 18 • Endless tuning and re-tuning • Rant-warning! • Ok for some application profiles • Time window applications • Client applications • Specially architected applications (new-objects only) • Applications not sensitive to latency
  • 21. A DESERT SURVIVAL KIT 19 • Chose the right GC algorithm for your application • Understand your application allocation rate (in production) and allocate enough heap • Measure the right thing!! • Test != Production • Not average or std dev – latency is not a standard distribution! • Check out: Gil Tene’s jHiccup tool (and his talk) – a great new approach!
  • 22. 20
  • 23. RECOGNIZE THIS? 21 • Initially everything is fine, GCs are happening without much impact • Over time application seems to freeze up on occasion, or starts responding slower and slower • Soon, the entire application hangs, affecting other servers to start firing up • Eventually the JVM gives up and “crashes” • GC logs show back-to-back GCs and in the end some sort of Out Of Memory, Allocation, or Promotion Error
  • 24. WHAT REALLY HAPPENS 22 • When allocation fails, GC is triggered • GC is doing its job, but no memory opens up (everything is live) • Back-to-back GCs, still no new memory => OOME.. • OOME indicates not enough heap for your allocation rate
  • 25. WHY NOT CONFIGURE A LARGER HEAP? 23
  • 28. REMEMBER COMPACTION? 26 • Most GC implementations do not handle compaction well • Moving objects is costly – stop the world is easy • Generational added • Tuning options and heuristics added • Only one JVM that I know of that does compaction concurrently today (Zing)
  • 29. PREPARE FOR THE REAL VILLAIN… 27 "There are two kinds of people in the world my friend, those with a rope around their neck and the people that have the job of doing the cutting!"
  • 31. STOP THE WORLD OPERATIONS 29 • Prevents efficient memory utilization • Creates complex JVM deployments • Sends you out in the tuning desert…
  • 32. SUMMARY 30 • Garbage is GOOD • The need to tune is BAD • Stop the world operations are UGLY
  • 33. I CHALLENGE THEE 31 “You see in this world, there’s two kinds of people my friend… …those with loaded guns and those who dig…you dig!”
  • 34. JOIN THE FUTURE OF JAVA! 32 • Open JDK is a great opportunity for innovation - join the community! • Have all GC algorithms been invented yet? • How do we enable a better world of self-tuning, adaptive JVMs? • Relieve the admin of the pain of the tuning! • How about fixing the core problem? • Implement concurrent compaction • Be creative around allocation / dynamic allocation rates!
  • 35. 33
  • 37. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/garbage- collection-benefits