SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Downloaden Sie, um offline zu lesen
Go &
The garbage collection
“
Joris Bonnefoy
DevOps @ OVH
@devatoria
2
Introduction
Reminder of basic algorithmic structures
» Objects have a pointer to the next element of the
list
» The last element have a null pointer
Linked list 4
» Objects have pointers to the next and the previous
element of the list
» The first element have a null previous pointer
» The last element have a null next pointer
Doubly linked list 5
» Objects have pointers to the next and the previous element of the
list
» The first element have a previous pointer to the last element of the
list
» The last element have a next pointer to the first element of the list
Circular doubly linked list 6
A simple problem
How to free a dereferenced object?
How to free a dereferenced object? 8
How to free a dereferenced object? 9
How to free a dereferenced object? 10
A solution
The garbage collection
The garbage collection
» John McCarthy - 1959 - Lisp
» Opposite of manual memory management
» Used to free unused allocated memory
» Can handle more types of resources (network
sockets, database handlers, …) using finalization
and region-based allocation
12
The garbage collection
» No dangling pointers
» No memory leaks
» No double free
» Can reduce performances
» Stop-the-world issues
» Can be unpredictable
13
Two types of garbage
collector
Reference counting
How reference counting is implemented?
» Each object has a count of other objects
referencing it
» An object is considered as garbage when its
counter reach 0
16
How reference counting is implemented? 17
How reference counting is implemented? 18
Disadvantages of reference counting
» Sensitive to cycle referencing
19
Disadvantages of reference counting
» Increased space overhead
» Must be atomic
» Not real-time
20
Tracing garbage collection
Concept of tracing garbage collection
» Determine which objects are reachable from a
certain “root” object
» Unreachable objects are considered as garbage
» Can use a lot of algorithms
22
Two ways of reachability
» The object is reachable from a certain root
» Local variables
» Parameters
» Global variables
» The object is reachable via another reachable
object
23
Tracing garbage collection
The naïve mark-and-sweep algorithm
The naïve mark-and-sweep algorithm
» Two stages algorithm
» First, run through the root set tree and mark
reachable objects
» Second, run through the whole memory, sweep
unmarked objects and clear mark of marked
objects
25
The naïve mark-and-sweep algorithm disadvantages
» Must run through the memory twice
» Must freeze the execution of the program to avoid
mutation of the working set
26
Go and the garbage collection
The tri-color marking
The tri-color marking
» Proposed by Dijkstra in 1978
» Tri-color
» Concurrent
» Mark-and-sweep
28
The tri-color marking concept
» Heap is a graph of connected objects
» Uses 3 colored sets
» White: contains objects to collect
» Gray: contains objects reachable from the root
but not yet scanned
» Black: contains reachable and scanned objects
29
The tri-color marking steps
» At the beginning, everyone is in the white set
» Root objects are moved in the gray set
» A root object is scanned
» Its references are colored gray, while the root object itself is
colored black
» Its references are scanned too and moved to the black set
» Once the gray set is empty, the remaining objects in the white set
are freed and sets are recolored
30
The tri-color marking by example 31
The tri-color marking by example 32
The tri-color marking by example 33
The tri-color marking by example 34
The tri-color marking by example 35
The tri-color marking by example 36
The tri-color marking by example 37
The algorithm invariant
“The tri-color marking invariant
No black object may contain a pointer to a
white object
39
How to always satisfy the invariant?
» Stop the world until GC is complete
» Use a write barrier
» Function executed by the mutator to tell the GC that a pointer
has been changed
» Enforce an object to be gray when it is created during the
garbage collector cycle
40
How to always satisfy the invariant? 41
Go back to lower versions of Go
The garbage collector review by Richard Hudson
Go 1.4 and lower
» Stop-the-world from the beginning of the cycle to
the end
» High GC latency
» Not concurrent
43
Go 1.5 (and actual) garbage collector
» Made by Richard Hudson and his team
» Concurrent
» Low latency
» Decrease program performances but increase
throughput
44
Go 1.5 new garbage collector 45
Benchmarking 46
Go 1.6 and further
» Improvements on when to start a GC cycle, used
metrics, etc.
» Predictive
47
What’s new in Go 1.8?
The garbage collector review
Actual garbage collector pain point 49
New type of write barrier
» Hybrid write barrier
» Dijkstra (1978)
» Yuasa (1990)
» New algorithm invariant (weak invariant)
» No need to rescan the whole memory
» Reduces GC cycle
» 100 microseconds for the worst case
» 50 microseconds for 95 percentile
50
“
Any white object pointed to by a black object
is reachable from a grey object via a chain of
white pointers (it is grey-protected).
51
Go 1.8 hybrid write barrier 52
Languages without garbage
collector
Rust
» Based on ownership and borrowing
» Every value has a scope
» Passing or returning a value means transferring its ownership
» When a scope ends, owned values are destroyed
» Everything is checked at compile time
» Everything is allocated on the stack by default
» Using stack frames
» Stack frames are freed on function return
» Can be allocated on the heap using boxes
54
Rust - Ownership 55
Rust - Ownership 56
Rust - Ownership 57
Rust - Borrowing 58
“
Thank you for listening
59
References
» Pusher https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/
» Golang new GC proposal
https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md
» Go GC 1.5 blog post https://blog.golang.org/go15gc
» GopherCon 2015 GC Latency talk https://www.youtube.com/watch?v=aiv1JOfMjm0
» Dijkstra 1978 GC paper http://dl.acm.org/citation.cfm?id=359655
» Rust lang https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html
60

Weitere ähnliche Inhalte

Was ist angesagt?

Cycloudのストレージ紹介と歴史
Cycloudのストレージ紹介と歴史Cycloudのストレージ紹介と歴史
Cycloudのストレージ紹介と歴史Hiroki Chinen
 
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...Vietnam Open Infrastructure User Group
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetesrajdeep
 
VXLAN and FRRouting
VXLAN and FRRoutingVXLAN and FRRouting
VXLAN and FRRoutingFaisal Reza
 
CODT2021 CyberAgentでの サーバ選定手法の紹介
CODT2021 CyberAgentでの サーバ選定手法の紹介CODT2021 CyberAgentでの サーバ選定手法の紹介
CODT2021 CyberAgentでの サーバ選定手法の紹介Hiroki Chinen
 
Service Mesh on Kubernetes with Istio
Service Mesh on Kubernetes with IstioService Mesh on Kubernetes with Istio
Service Mesh on Kubernetes with IstioMichelle Holley
 
微服務對IT人員的衝擊
微服務對IT人員的衝擊微服務對IT人員的衝擊
微服務對IT人員的衝擊Philip Zheng
 
Replacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with CiliumReplacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with CiliumMichal Rostecki
 
NFV management and orchestration framework architecture
NFV management and orchestration framework architectureNFV management and orchestration framework architecture
NFV management and orchestration framework architecturesidneel
 
ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜
ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜
ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜LINE Corporation
 
Software Containerization
Software ContainerizationSoftware Containerization
Software ContainerizationRoshan Deniyage
 
Software engineering تلخيص
Software engineering تلخيصSoftware engineering تلخيص
Software engineering تلخيصARWA ALSAIF
 
Introduction to OpenDaylight & Application Development
Introduction to OpenDaylight & Application DevelopmentIntroduction to OpenDaylight & Application Development
Introduction to OpenDaylight & Application DevelopmentMichelle Holley
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteWeaveworks
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumScyllaDB
 

Was ist angesagt? (20)

Cycloudのストレージ紹介と歴史
Cycloudのストレージ紹介と歴史Cycloudのストレージ紹介と歴史
Cycloudのストレージ紹介と歴史
 
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
VXLAN and FRRouting
VXLAN and FRRoutingVXLAN and FRRouting
VXLAN and FRRouting
 
Gitlab, GitOps & ArgoCD
Gitlab, GitOps & ArgoCDGitlab, GitOps & ArgoCD
Gitlab, GitOps & ArgoCD
 
CODT2021 CyberAgentでの サーバ選定手法の紹介
CODT2021 CyberAgentでの サーバ選定手法の紹介CODT2021 CyberAgentでの サーバ選定手法の紹介
CODT2021 CyberAgentでの サーバ選定手法の紹介
 
Service Mesh on Kubernetes with Istio
Service Mesh on Kubernetes with IstioService Mesh on Kubernetes with Istio
Service Mesh on Kubernetes with Istio
 
微服務對IT人員的衝擊
微服務對IT人員的衝擊微服務對IT人員的衝擊
微服務對IT人員的衝擊
 
Git由超淺入超深
Git由超淺入超深Git由超淺入超深
Git由超淺入超深
 
Git submodule
Git submoduleGit submodule
Git submodule
 
Replacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with CiliumReplacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with Cilium
 
NFV management and orchestration framework architecture
NFV management and orchestration framework architectureNFV management and orchestration framework architecture
NFV management and orchestration framework architecture
 
ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜
ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜
ソフトウェアでのパケット処理あれこれ〜何故我々はロードバランサを自作するに至ったのか〜
 
Software Containerization
Software ContainerizationSoftware Containerization
Software Containerization
 
Software engineering تلخيص
Software engineering تلخيصSoftware engineering تلخيص
Software engineering تلخيص
 
Introduction to OpenDaylight & Application Development
Introduction to OpenDaylight & Application DevelopmentIntroduction to OpenDaylight & Application Development
Introduction to OpenDaylight & Application Development
 
Observability
ObservabilityObservability
Observability
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event Keynote
 
systemd 再入門
systemd 再入門systemd 再入門
systemd 再入門
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
 

Ähnlich wie Go and the garbage collection

JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional APIJustin Lin
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup
 
A survey on Heap Exploitation
A survey on Heap Exploitation A survey on Heap Exploitation
A survey on Heap Exploitation Alireza Karimi
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structureThinh Dang
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)Sung Kim
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software DevelopmentNaveenkumar Muguda
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big DataAlbert Bifet
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
 
Ants coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsAnts coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsALIZAIB KHAN
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford MapR Technologies
 
Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Yuanyuan Tian
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
Aco 03-04-2013
Aco 03-04-2013Aco 03-04-2013
Aco 03-04-2013Ahmad Khan
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...huguk
 
Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Kira
 

Ähnlich wie Go and the garbage collection (20)

JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves
 
Understanding low latency jvm gcs
Understanding low latency jvm gcsUnderstanding low latency jvm gcs
Understanding low latency jvm gcs
 
A survey on Heap Exploitation
A survey on Heap Exploitation A survey on Heap Exploitation
A survey on Heap Exploitation
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structure
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Hoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdfHoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdf
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
 
Ants coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsAnts coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithms
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
 
C# basics
C# basicsC# basics
C# basics
 
Quantum Computing
Quantum ComputingQuantum Computing
Quantum Computing
 
Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Aco 03-04-2013
Aco 03-04-2013Aco 03-04-2013
Aco 03-04-2013
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 
Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)
 

Kürzlich hochgeladen

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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 WorkerThousandEyes
 

Kürzlich hochgeladen (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 

Go and the garbage collection

  • 1. Go & The garbage collection
  • 2. “ Joris Bonnefoy DevOps @ OVH @devatoria 2
  • 3. Introduction Reminder of basic algorithmic structures
  • 4. » Objects have a pointer to the next element of the list » The last element have a null pointer Linked list 4
  • 5. » Objects have pointers to the next and the previous element of the list » The first element have a null previous pointer » The last element have a null next pointer Doubly linked list 5
  • 6. » Objects have pointers to the next and the previous element of the list » The first element have a previous pointer to the last element of the list » The last element have a next pointer to the first element of the list Circular doubly linked list 6
  • 7. A simple problem How to free a dereferenced object?
  • 8. How to free a dereferenced object? 8
  • 9. How to free a dereferenced object? 9
  • 10. How to free a dereferenced object? 10
  • 12. The garbage collection » John McCarthy - 1959 - Lisp » Opposite of manual memory management » Used to free unused allocated memory » Can handle more types of resources (network sockets, database handlers, …) using finalization and region-based allocation 12
  • 13. The garbage collection » No dangling pointers » No memory leaks » No double free » Can reduce performances » Stop-the-world issues » Can be unpredictable 13
  • 14. Two types of garbage collector
  • 16. How reference counting is implemented? » Each object has a count of other objects referencing it » An object is considered as garbage when its counter reach 0 16
  • 17. How reference counting is implemented? 17
  • 18. How reference counting is implemented? 18
  • 19. Disadvantages of reference counting » Sensitive to cycle referencing 19
  • 20. Disadvantages of reference counting » Increased space overhead » Must be atomic » Not real-time 20
  • 22. Concept of tracing garbage collection » Determine which objects are reachable from a certain “root” object » Unreachable objects are considered as garbage » Can use a lot of algorithms 22
  • 23. Two ways of reachability » The object is reachable from a certain root » Local variables » Parameters » Global variables » The object is reachable via another reachable object 23
  • 24. Tracing garbage collection The naïve mark-and-sweep algorithm
  • 25. The naïve mark-and-sweep algorithm » Two stages algorithm » First, run through the root set tree and mark reachable objects » Second, run through the whole memory, sweep unmarked objects and clear mark of marked objects 25
  • 26. The naïve mark-and-sweep algorithm disadvantages » Must run through the memory twice » Must freeze the execution of the program to avoid mutation of the working set 26
  • 27. Go and the garbage collection The tri-color marking
  • 28. The tri-color marking » Proposed by Dijkstra in 1978 » Tri-color » Concurrent » Mark-and-sweep 28
  • 29. The tri-color marking concept » Heap is a graph of connected objects » Uses 3 colored sets » White: contains objects to collect » Gray: contains objects reachable from the root but not yet scanned » Black: contains reachable and scanned objects 29
  • 30. The tri-color marking steps » At the beginning, everyone is in the white set » Root objects are moved in the gray set » A root object is scanned » Its references are colored gray, while the root object itself is colored black » Its references are scanned too and moved to the black set » Once the gray set is empty, the remaining objects in the white set are freed and sets are recolored 30
  • 31. The tri-color marking by example 31
  • 32. The tri-color marking by example 32
  • 33. The tri-color marking by example 33
  • 34. The tri-color marking by example 34
  • 35. The tri-color marking by example 35
  • 36. The tri-color marking by example 36
  • 37. The tri-color marking by example 37
  • 39. “The tri-color marking invariant No black object may contain a pointer to a white object 39
  • 40. How to always satisfy the invariant? » Stop the world until GC is complete » Use a write barrier » Function executed by the mutator to tell the GC that a pointer has been changed » Enforce an object to be gray when it is created during the garbage collector cycle 40
  • 41. How to always satisfy the invariant? 41
  • 42. Go back to lower versions of Go The garbage collector review by Richard Hudson
  • 43. Go 1.4 and lower » Stop-the-world from the beginning of the cycle to the end » High GC latency » Not concurrent 43
  • 44. Go 1.5 (and actual) garbage collector » Made by Richard Hudson and his team » Concurrent » Low latency » Decrease program performances but increase throughput 44
  • 45. Go 1.5 new garbage collector 45
  • 47. Go 1.6 and further » Improvements on when to start a GC cycle, used metrics, etc. » Predictive 47
  • 48. What’s new in Go 1.8? The garbage collector review
  • 49. Actual garbage collector pain point 49
  • 50. New type of write barrier » Hybrid write barrier » Dijkstra (1978) » Yuasa (1990) » New algorithm invariant (weak invariant) » No need to rescan the whole memory » Reduces GC cycle » 100 microseconds for the worst case » 50 microseconds for 95 percentile 50
  • 51. “ Any white object pointed to by a black object is reachable from a grey object via a chain of white pointers (it is grey-protected). 51
  • 52. Go 1.8 hybrid write barrier 52
  • 54. Rust » Based on ownership and borrowing » Every value has a scope » Passing or returning a value means transferring its ownership » When a scope ends, owned values are destroyed » Everything is checked at compile time » Everything is allocated on the stack by default » Using stack frames » Stack frames are freed on function return » Can be allocated on the heap using boxes 54
  • 59. “ Thank you for listening 59
  • 60. References » Pusher https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/ » Golang new GC proposal https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md » Go GC 1.5 blog post https://blog.golang.org/go15gc » GopherCon 2015 GC Latency talk https://www.youtube.com/watch?v=aiv1JOfMjm0 » Dijkstra 1978 GC paper http://dl.acm.org/citation.cfm?id=359655 » Rust lang https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html 60