SlideShare a Scribd company logo
Twitter: @prateekgogia
Github: @prateekgogia
Docker daemon
eth0 Linux machine
Docker
Daemon
Docker runtime adopted Go
• Promoted wider adoption of Go as a systems language
• Bug fixes in Docker produced more Go programmers
• Identifying systems level problem in Go runtime related to syscalls / threads
Isolation in Docker container: namespaces
• Process trees (PID Namespace)
• Mounts (MNT namespace)
• Network (Net namespace)
• Users / UIDs (User Namespace)
• Hostnames (UTS Namespace)
• Inter Process Communication (IPC Namespace)
Lets see this in action
Running a Go Process on Linux machine
eth0 Linux machine
Go Process
OS thread
Goroutine
Add new Network Namespace with lo
(loopback) only interface
eth0
net namespaces n
Linux machine
Go Process
OS thread
Goroutine
Adding worker goroutines to new network
namespaces
eth0
Worker
goroutines
net namespaces n
Linux machine
Go Process
OS thread
Goroutine
runtime.LockOSThread()
Adding worker goroutines to host network
namespace
eth0
Worker
goroutines
net namespaces n
Linux machine
Go Process
OS thread
Goroutine
runtime.LockOSThread()
Adding worker goroutines to host network
namespace
eth0
more
Worker
goroutines
net namespaces n
Linux machine Go Process
OS thread
Goroutine
runtime.LockOSThread()
Incorrect interfaces detected by goroutines
eth0
more
Worker
goroutines
net namespaces n
Linux machine Go Process
goroutine
with wrong
interface info
Go runtime scheduler
M P G G G G
M P G
M
P
G
OS thread
Processor (Logical)
Goroutine
Go runtime scheduler
M P G G G G
M P G G G
Global queue
M
P
G
OS thread
Processor (Logical)
Goroutine
Go runtime Scheduler
M P G G G G
M P G G G
M P G G G
M P G G G G G G
Global queue
M
P
G
OS thread
Processor (Logical)
Goroutine
Go runtime Scheduler
M P G G G G
M P G G G
M P G G G
M P G G G G G G
Global queue
New threads inherit
state from already
running threads
Go runtime model
eth0
more
Worker
goroutines
net namespaces n
Linux machine Go Process
OS thread
Goroutine
runtime.LockOSThread()
Go runtime model
eth0
more
Worker
goroutines
net namespaces n
Linux machine Go Process
How Go 1.10 Fixed it
Go runtime scheduler
M P G G G G
M P G
M
P
G
OS thread
Processor (Logical)
Goroutine
Go runtime scheduler
M P G
M P G
M
P
G
OS thread
Processor
(Logical)
Goroutine
runtime.LockOSThread()
Go runtime scheduler in go 1.10
M P G
M P G
startTemplateThread()
M
P
G
OS thread
Processor
(Logical)
Goroutine
runtime.LockOSThread()
LockOSThread() in go 1.10
M P G
M P G
Template thread
M
P
G
OS thread
Processor (Logical)
Goroutine
runtime.LockOSThread()
Go runtime scheduler in 1.10
M P G
M P G
Template thread
M
P
G
OS thread
Processor (Logical)
Goroutine
runtime.LockOSThread()
M P G
M P G
Template thread creation in Go Process
eth0
net namespaces n
Linux machine
Go Process
Template
thread
Adding worker goroutines to host network
namespace
eth0
net namespaces n
Linux machine
Go Process
Template
thread
Summary
• If creating / managing Linux network namespaces using Go, use Go
version >= 1.10
Thank You!!!
runtime.LockOSThread()
M P G
M P G
M P G G G
M P G G G G G G
Global queue
Goroutine called
LockOSThread()
M
P
G
OS thread
Processor
(Logical)
Goroutine
runtime.LockOSThread()
Docker runtime adopted Go ??
• Static compilation
• Asynchronous primitives
• Multi-arch builds
• Faster development
• Awesome Documentations
GopherCon Denver LT 2018
How to manage network namespaces
with Go 1.10 and beyond
ns := createNetNamespace()
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ns.Do(func(_ ns.NetNS) error {
runtime.LockOSThread()
cb()
}
If the goroutine here changes the state of the
thread, let the thread exit with goroutine
Bonus feature
• OS thread terminates if goroutine exits
• runtime.LockOSThread() is nested.
• UnlockOSThread must be called the same number of times in order to unlock the thread.

More Related Content

PPTX
Workshop on Source control, git merge walkthroughs
PDF
Coding in GO - GDG SL - NSBM
PDF
Go破壊
PDF
The State of Go - Andrew Gerrand
PDF
tokyotalk
PDF
The async/await concurrency pattern in Golang
PDF
Pengenalan Git
PDF
kikstart journey of Golang with Hello world - Gopherlabs
Workshop on Source control, git merge walkthroughs
Coding in GO - GDG SL - NSBM
Go破壊
The State of Go - Andrew Gerrand
tokyotalk
The async/await concurrency pattern in Golang
Pengenalan Git
kikstart journey of Golang with Hello world - Gopherlabs

What's hot (20)

PDF
Learn Git Fundamentals
PDF
Deep dark-side of git: How git works internally
PDF
Dive into Pinkoi 2013
PDF
Tài liệu sử dụng GitHub
PPTX
Linux comands for Hadoop
PDF
Resource Discovery for the Web Platform using a P2P Overlay Network with WebR...
PDF
Git in 5 Minutes
PDF
Concurrency
PDF
GIT: Content-addressable filesystem and Version Control System
PDF
Reversing the dropbox client on windows
PDF
PuppetConf 2017: How People Actually Write Puppet- Gareth Rushgrove, Puppet
PPTX
Git basic
PPT
Dev8d 2011-pipe2 py
PDF
PuppetConf 2017: Puppet Platform: A Path Forward- Eric Sorenson, Puppet
PDF
ODP
Rpm Introduction
PDF
Now i git it!!!
PDF
Golang Performance : microbenchmarks, profilers, and a war story
ODP
Knolx master-slides
PDF
Taming Rich GML with Stetl - FOSS4G 2013 Nottingham
Learn Git Fundamentals
Deep dark-side of git: How git works internally
Dive into Pinkoi 2013
Tài liệu sử dụng GitHub
Linux comands for Hadoop
Resource Discovery for the Web Platform using a P2P Overlay Network with WebR...
Git in 5 Minutes
Concurrency
GIT: Content-addressable filesystem and Version Control System
Reversing the dropbox client on windows
PuppetConf 2017: How People Actually Write Puppet- Gareth Rushgrove, Puppet
Git basic
Dev8d 2011-pipe2 py
PuppetConf 2017: Puppet Platform: A Path Forward- Eric Sorenson, Puppet
Rpm Introduction
Now i git it!!!
Golang Performance : microbenchmarks, profilers, and a war story
Knolx master-slides
Taming Rich GML with Stetl - FOSS4G 2013 Nottingham
Ad

Similar to GopherCon Denver LT 2018 (20)

PDF
Demystifying the Go Scheduler
PDF
An Introduction to Go
PPTX
C100 k and go
PDF
Import golang; struct microservice
PDF
Go Concurrency
PDF
Fixing Docker networking - Milos Gajdos at #DOXLON
PDF
A Channel Compendium
PDF
Job Queue in Golang
PDF
How to Leverage Go for Your Networking Needs
PDF
Go Concurrency
PDF
Mirko Damiani - An Embedded soft real time distributed system in Go
PDF
Go Workshop Day 0
PDF
Go, the one language to learn in 2014
PDF
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
PDF
Import golang; struct microservice - Codemotion Rome 2015
PDF
Go for Rubyists
PDF
The Go features I can't live without, 2nd round
PPTX
Chapel-on-X: Exploring Tasking Runtimes for PGAS Languages
PDF
LCA2014 - Introduction to Go
PDF
Go concurrency
Demystifying the Go Scheduler
An Introduction to Go
C100 k and go
Import golang; struct microservice
Go Concurrency
Fixing Docker networking - Milos Gajdos at #DOXLON
A Channel Compendium
Job Queue in Golang
How to Leverage Go for Your Networking Needs
Go Concurrency
Mirko Damiani - An Embedded soft real time distributed system in Go
Go Workshop Day 0
Go, the one language to learn in 2014
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
Import golang; struct microservice - Codemotion Rome 2015
Go for Rubyists
The Go features I can't live without, 2nd round
Chapel-on-X: Exploring Tasking Runtimes for PGAS Languages
LCA2014 - Introduction to Go
Go concurrency
Ad

Recently uploaded (20)

PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPT
Project quality management in manufacturing
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Geodesy 1.pptx...............................................
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
PPT on Performance Review to get promotions
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Sustainable Sites - Green Building Construction
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Construction Project Organization Group 2.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Project quality management in manufacturing
UNIT 4 Total Quality Management .pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Geodesy 1.pptx...............................................
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Safety Seminar civil to be ensured for safe working.
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Categorization of Factors Affecting Classification Algorithms Selection
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT on Performance Review to get promotions
additive manufacturing of ss316l using mig welding
Sustainable Sites - Green Building Construction
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Foundation to blockchain - A guide to Blockchain Tech
Construction Project Organization Group 2.pptx

GopherCon Denver LT 2018

  • 2. Docker daemon eth0 Linux machine Docker Daemon
  • 3. Docker runtime adopted Go • Promoted wider adoption of Go as a systems language • Bug fixes in Docker produced more Go programmers • Identifying systems level problem in Go runtime related to syscalls / threads
  • 4. Isolation in Docker container: namespaces • Process trees (PID Namespace) • Mounts (MNT namespace) • Network (Net namespace) • Users / UIDs (User Namespace) • Hostnames (UTS Namespace) • Inter Process Communication (IPC Namespace)
  • 5. Lets see this in action
  • 6. Running a Go Process on Linux machine eth0 Linux machine Go Process OS thread Goroutine
  • 7. Add new Network Namespace with lo (loopback) only interface eth0 net namespaces n Linux machine Go Process OS thread Goroutine
  • 8. Adding worker goroutines to new network namespaces eth0 Worker goroutines net namespaces n Linux machine Go Process OS thread Goroutine runtime.LockOSThread()
  • 9. Adding worker goroutines to host network namespace eth0 Worker goroutines net namespaces n Linux machine Go Process OS thread Goroutine runtime.LockOSThread()
  • 10. Adding worker goroutines to host network namespace eth0 more Worker goroutines net namespaces n Linux machine Go Process OS thread Goroutine runtime.LockOSThread()
  • 11. Incorrect interfaces detected by goroutines eth0 more Worker goroutines net namespaces n Linux machine Go Process goroutine with wrong interface info
  • 12. Go runtime scheduler M P G G G G M P G M P G OS thread Processor (Logical) Goroutine
  • 13. Go runtime scheduler M P G G G G M P G G G Global queue M P G OS thread Processor (Logical) Goroutine
  • 14. Go runtime Scheduler M P G G G G M P G G G M P G G G M P G G G G G G Global queue M P G OS thread Processor (Logical) Goroutine
  • 15. Go runtime Scheduler M P G G G G M P G G G M P G G G M P G G G G G G Global queue New threads inherit state from already running threads
  • 16. Go runtime model eth0 more Worker goroutines net namespaces n Linux machine Go Process OS thread Goroutine runtime.LockOSThread()
  • 17. Go runtime model eth0 more Worker goroutines net namespaces n Linux machine Go Process
  • 18. How Go 1.10 Fixed it
  • 19. Go runtime scheduler M P G G G G M P G M P G OS thread Processor (Logical) Goroutine
  • 20. Go runtime scheduler M P G M P G M P G OS thread Processor (Logical) Goroutine runtime.LockOSThread()
  • 21. Go runtime scheduler in go 1.10 M P G M P G startTemplateThread() M P G OS thread Processor (Logical) Goroutine runtime.LockOSThread()
  • 22. LockOSThread() in go 1.10 M P G M P G Template thread M P G OS thread Processor (Logical) Goroutine runtime.LockOSThread()
  • 23. Go runtime scheduler in 1.10 M P G M P G Template thread M P G OS thread Processor (Logical) Goroutine runtime.LockOSThread() M P G M P G
  • 24. Template thread creation in Go Process eth0 net namespaces n Linux machine Go Process Template thread
  • 25. Adding worker goroutines to host network namespace eth0 net namespaces n Linux machine Go Process Template thread
  • 26. Summary • If creating / managing Linux network namespaces using Go, use Go version >= 1.10
  • 28. runtime.LockOSThread() M P G M P G M P G G G M P G G G G G G Global queue Goroutine called LockOSThread() M P G OS thread Processor (Logical) Goroutine runtime.LockOSThread()
  • 29. Docker runtime adopted Go ?? • Static compilation • Asynchronous primitives • Multi-arch builds • Faster development • Awesome Documentations
  • 31. How to manage network namespaces with Go 1.10 and beyond ns := createNetNamespace() runtime.LockOSThread() defer runtime.UnlockOSThread() ns.Do(func(_ ns.NetNS) error { runtime.LockOSThread() cb() } If the goroutine here changes the state of the thread, let the thread exit with goroutine
  • 32. Bonus feature • OS thread terminates if goroutine exits • runtime.LockOSThread() is nested. • UnlockOSThread must be called the same number of times in order to unlock the thread.

Editor's Notes

  • #3: How Goroutines, threads, processors work in Go
  • #7: How Goroutines, threads, processors work in Go
  • #8: How Goroutines, threads, processors work in Go
  • #9: How Goroutines, threads, processors work in Go
  • #10: How Goroutines, threads, processors work in Go
  • #11: How Goroutines, threads, processors work in Go
  • #12: How Goroutines, threads, processors work in Go
  • #17: How Goroutines, threads, processors work in Go
  • #18: How Goroutines, threads, processors work in Go
  • #25: How Goroutines, threads, processors work in Go
  • #26: How Goroutines, threads, processors work in Go