SlideShare a Scribd company logo
1 of 24
Download to read offline
DEMYSTIFYING 
THE GO 
SCHEDULER 
MATTHEW DALE
Go Concurrency Crash Course 
The atomic unit of concurrent work in Go is the goroutine 
Started by invoking a function with the go keyword 
! 
Invoked function runs concurrently with the current thread 
of execution 
Goroutine synchronization is accomplished with channels 
Message passing construct 
Buffered or unbuffered
The Go Scheduler 
Attempts to efficiently schedule 
goroutines on available resources 
The scheduler will pick up a new 
goroutine when the current goroutine… 
1. Finishes 
2. Makes a blocking system call 
E.g. reading a file 
3. Makes a blocking Go runtime call 
E.g. reading from a channel 
4. Invokes another function (only 
happens sometimes)* 
Taken from http://morsmachine.dk/go-scheduler 
M - Machine (OS thread) 
P - Context (Go scheduler) 
*As of Go 1.2 ( https://golang.org/doc/go1.2#preemption ) G - Goroutine
If the current goroutine is blocked on a system call… 
The OS thread processing the goroutine idles waiting for the 
system call to return 
The context that was scheduling gorotuines on the blocked thread 
is moved to a new thread (or a new one is created if none are 
available) Taken from http://morsmachine.dk/go-scheduler
HOW DOES GO ASK FOR 
RESOURCES ABSTRACTED BY THE 
OPERATING SYSTEM?
The syscall Package 
All calls that can block an OS thread go through 
the syscall package (except cgo calls) 
Responsible for informing the Go runtime that a 
potentially blocking system call is about to happen
src/pkg/os/file.go, line 91 
src/pkg/os/file_unix.go, line 186 
Let’s follow a call to file.Read…
src/package/zsyscall_linux_amd64.go, line 831 (generated) 
src/pkg/syscall/asm_linux_amd64.s, line 44
src/pkg/runtime/proc.c, line 1502
Notes on Host Setup 
Modify /etc/security/limits.conf 
Go will quickly use up the default allotment of 
file descriptors on most Linux distros 
The default Go HTTP server will panic if 
listener.Accept() ever returns an error, killing your 
service 
Example configuration 
ec2-user soft nofile 100000 
ec2-user hard nofile 100000 
root soft nofile 100000 
root hard nofile 100000
FILE I/O DEMO!
BUT HOW DOES THAT WORK WITH 
NETWORK I/O? 
! 
WOULDN’T THAT JUST CREATE A 
BILLION THREADS?
The netpoller 
Runs in its own thread and polls the OS’s asynchronous 
I/O network interface for data 
Goroutines asking for network I/O block waiting for the 
netpoller to give them data, not for a system event 
Go treats Unix sockets and network connection file 
descriptors the same, so Unix socket I/O will not block 
OS threads 
See http://morsmachine.dk/netpoller for a great, 
concise description of the netpoller
RESOURCE STARVATION 
OR 
WHY DID MY GO SERVICE 
STOP RESPONDING?
WEB SERVICE 
PERFORMANCE DEMO!
NOT SO GOOD…
Which Problems Are 
Essential vs Accidental*? 
Essential 
A computer can do a finite 
amount of work per unit time 
If there is more work than 
resources, then work must be 
delegated, queued or dropped 
Accidental 
Sometimes you and the Go 
scheduler disagree about what 
is the most important work to 
do 
*Essential vs accidental complexity is a problem decomposition 
strategy proposed in Frederick Brooks Jr.’s book The Mythical 
Man-Month
Simplify vs Complexify 
Simplify - synchronous instead of concurrent 
Still requires determining how to do CPU load 
balancing 
Pushes performance problems to the front, letting the 
caller tune on their side 
Complexify - refactor into micro services and add queues 
Lots of additional code just to solve a “simple” 
problem
Think bite-sized 
Refactor long-running, non-blocking 
workloads to add more 
function calls 
The Go scheduler will 
sometimes preempt the 
running goroutine when it 
makes a non-inlineable 
function call 
Explicitly call runtime.Gosched 
Causes the current running 
goroutine to yield to the 
scheduler
Think micro services 
Keep heterogeneous 
workloads in different Go 
processes 
One service handles 
quick or I/O heavy tasks 
One service handles 
long-running 
OS handles resource 
scheduling
runtime.LockOSThread 
Locks the current goroutine to the current thread 
and doesn’t allow any other goroutines to run on 
that thread 
Call runtime.UnlockOSThread to unlock the 
thread.
Extra Go Scheduler Topics 
There are a lot of topics relevant to the Go 
scheduler but beyond the scope of this 
presentation, including… 
Tailoring GOMAXPROCS for your workload 
How cgo calls interact with the scheduler
Sources and Suggested 
Reading 
http://morsmachine.dk/go-scheduler 
http://morsmachine.dk/netpoller 
http://dave.cheney.net/2014/06/07/five-things-that-make- 
go-fast 
http://golang.org/pkg/runtime/ 
Code examples used in this presentation can be 
found at https://github.com/matthewdale/ 
GoSchedulerDemo
QUESTIONS?

More Related Content

What's hot

Oracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aasOracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aas
Kyle Hailey
 
Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会
Masahiko Sawada
 

What's hot (20)

PostgreSQLモニタリングの基本とNTTデータが追加したモニタリング新機能(Open Source Conference 2021 Online F...
PostgreSQLモニタリングの基本とNTTデータが追加したモニタリング新機能(Open Source Conference 2021 Online F...PostgreSQLモニタリングの基本とNTTデータが追加したモニタリング新機能(Open Source Conference 2021 Online F...
PostgreSQLモニタリングの基本とNTTデータが追加したモニタリング新機能(Open Source Conference 2021 Online F...
 
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
 
Google Spanner
Google SpannerGoogle Spanner
Google Spanner
 
User Administration in Linux
User Administration in LinuxUser Administration in Linux
User Administration in Linux
 
Linux networking
Linux networkingLinux networking
Linux networking
 
PostgreSQLのfull_page_writesについて(第24回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLのfull_page_writesについて(第24回PostgreSQLアンカンファレンス@オンライン 発表資料)PostgreSQLのfull_page_writesについて(第24回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLのfull_page_writesについて(第24回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
Oracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aasOracle 10g Performance: chapter 02 aas
Oracle 10g Performance: chapter 02 aas
 
Best Practices for Running PostgreSQL on AWS - DAT314 - re:Invent 2017
Best Practices for Running PostgreSQL on AWS - DAT314 - re:Invent 2017Best Practices for Running PostgreSQL on AWS - DAT314 - re:Invent 2017
Best Practices for Running PostgreSQL on AWS - DAT314 - re:Invent 2017
 
リペア時間短縮にむけた取り組み@Yahoo! JAPAN #casstudy
リペア時間短縮にむけた取り組み@Yahoo! JAPAN #casstudyリペア時間短縮にむけた取り組み@Yahoo! JAPAN #casstudy
リペア時間短縮にむけた取り組み@Yahoo! JAPAN #casstudy
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会
 
PostgreSQL共有バッファと関連ツール
PostgreSQL共有バッファと関連ツールPostgreSQL共有バッファと関連ツール
PostgreSQL共有バッファと関連ツール
 
不揮発メモリ(NVDIMM)とLinuxの対応動向について(for comsys 2019 ver.)
不揮発メモリ(NVDIMM)とLinuxの対応動向について(for comsys 2019 ver.)不揮発メモリ(NVDIMM)とLinuxの対応動向について(for comsys 2019 ver.)
不揮発メモリ(NVDIMM)とLinuxの対応動向について(for comsys 2019 ver.)
 
Cronjob
CronjobCronjob
Cronjob
 
GKE に飛んでくるトラフィックを 自由自在に操る力 | 第 10 回 Google Cloud INSIDE Games & Apps Online
GKE に飛んでくるトラフィックを 自由自在に操る力 | 第 10 回 Google Cloud INSIDE Games & Apps OnlineGKE に飛んでくるトラフィックを 自由自在に操る力 | 第 10 回 Google Cloud INSIDE Games & Apps Online
GKE に飛んでくるトラフィックを 自由自在に操る力 | 第 10 回 Google Cloud INSIDE Games & Apps Online
 
ネットワークスイッチ構築実践 2.STP・RSTP・PortSecurity・StormControl・SPAN・Stacking編
ネットワークスイッチ構築実践 2.STP・RSTP・PortSecurity・StormControl・SPAN・Stacking編ネットワークスイッチ構築実践 2.STP・RSTP・PortSecurity・StormControl・SPAN・Stacking編
ネットワークスイッチ構築実践 2.STP・RSTP・PortSecurity・StormControl・SPAN・Stacking編
 
How to find what is making your Oracle database slow
How to find what is making your Oracle database slowHow to find what is making your Oracle database slow
How to find what is making your Oracle database slow
 
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
クラウドコラボレーションサーバ「Collabora Online」を構築してみた
クラウドコラボレーションサーバ「Collabora Online」を構築してみたクラウドコラボレーションサーバ「Collabora Online」を構築してみた
クラウドコラボレーションサーバ「Collabora Online」を構築してみた
 

Similar to Demystifying the Go Scheduler

The Pillars Of Concurrency
The Pillars Of ConcurrencyThe Pillars Of Concurrency
The Pillars Of Concurrency
aviade
 
A Scalable I/O Manager for GHC
A Scalable I/O Manager for GHCA Scalable I/O Manager for GHC
A Scalable I/O Manager for GHC
Johan Tibell
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1
Viên Mai
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
Akshay Nagpurkar
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
Akshay Nagpurkar
 

Similar to Demystifying the Go Scheduler (20)

Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdf
 
concurrency
concurrencyconcurrency
concurrency
 
The Windows Scheduler
The Windows SchedulerThe Windows Scheduler
The Windows Scheduler
 
The Pillars Of Concurrency
The Pillars Of ConcurrencyThe Pillars Of Concurrency
The Pillars Of Concurrency
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
5 - ch3.pptx
5 - ch3.pptx5 - ch3.pptx
5 - ch3.pptx
 
Tuning Java Servers
Tuning Java Servers Tuning Java Servers
Tuning Java Servers
 
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
 
A Scalable I/O Manager for GHC
A Scalable I/O Manager for GHCA Scalable I/O Manager for GHC
A Scalable I/O Manager for GHC
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1
 
Gophers Riding Elephants: Writing PostgreSQL tools in Go
Gophers Riding Elephants: Writing PostgreSQL tools in GoGophers Riding Elephants: Writing PostgreSQL tools in Go
Gophers Riding Elephants: Writing PostgreSQL tools in Go
 
Asynchronous programming intro
Asynchronous programming introAsynchronous programming intro
Asynchronous programming intro
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
MultiThreading in Python
MultiThreading in PythonMultiThreading in Python
MultiThreading in Python
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

Demystifying the Go Scheduler

  • 1. DEMYSTIFYING THE GO SCHEDULER MATTHEW DALE
  • 2. Go Concurrency Crash Course The atomic unit of concurrent work in Go is the goroutine Started by invoking a function with the go keyword ! Invoked function runs concurrently with the current thread of execution Goroutine synchronization is accomplished with channels Message passing construct Buffered or unbuffered
  • 3. The Go Scheduler Attempts to efficiently schedule goroutines on available resources The scheduler will pick up a new goroutine when the current goroutine… 1. Finishes 2. Makes a blocking system call E.g. reading a file 3. Makes a blocking Go runtime call E.g. reading from a channel 4. Invokes another function (only happens sometimes)* Taken from http://morsmachine.dk/go-scheduler M - Machine (OS thread) P - Context (Go scheduler) *As of Go 1.2 ( https://golang.org/doc/go1.2#preemption ) G - Goroutine
  • 4. If the current goroutine is blocked on a system call… The OS thread processing the goroutine idles waiting for the system call to return The context that was scheduling gorotuines on the blocked thread is moved to a new thread (or a new one is created if none are available) Taken from http://morsmachine.dk/go-scheduler
  • 5. HOW DOES GO ASK FOR RESOURCES ABSTRACTED BY THE OPERATING SYSTEM?
  • 6. The syscall Package All calls that can block an OS thread go through the syscall package (except cgo calls) Responsible for informing the Go runtime that a potentially blocking system call is about to happen
  • 7. src/pkg/os/file.go, line 91 src/pkg/os/file_unix.go, line 186 Let’s follow a call to file.Read…
  • 8. src/package/zsyscall_linux_amd64.go, line 831 (generated) src/pkg/syscall/asm_linux_amd64.s, line 44
  • 10. Notes on Host Setup Modify /etc/security/limits.conf Go will quickly use up the default allotment of file descriptors on most Linux distros The default Go HTTP server will panic if listener.Accept() ever returns an error, killing your service Example configuration ec2-user soft nofile 100000 ec2-user hard nofile 100000 root soft nofile 100000 root hard nofile 100000
  • 12. BUT HOW DOES THAT WORK WITH NETWORK I/O? ! WOULDN’T THAT JUST CREATE A BILLION THREADS?
  • 13. The netpoller Runs in its own thread and polls the OS’s asynchronous I/O network interface for data Goroutines asking for network I/O block waiting for the netpoller to give them data, not for a system event Go treats Unix sockets and network connection file descriptors the same, so Unix socket I/O will not block OS threads See http://morsmachine.dk/netpoller for a great, concise description of the netpoller
  • 14. RESOURCE STARVATION OR WHY DID MY GO SERVICE STOP RESPONDING?
  • 17. Which Problems Are Essential vs Accidental*? Essential A computer can do a finite amount of work per unit time If there is more work than resources, then work must be delegated, queued or dropped Accidental Sometimes you and the Go scheduler disagree about what is the most important work to do *Essential vs accidental complexity is a problem decomposition strategy proposed in Frederick Brooks Jr.’s book The Mythical Man-Month
  • 18. Simplify vs Complexify Simplify - synchronous instead of concurrent Still requires determining how to do CPU load balancing Pushes performance problems to the front, letting the caller tune on their side Complexify - refactor into micro services and add queues Lots of additional code just to solve a “simple” problem
  • 19. Think bite-sized Refactor long-running, non-blocking workloads to add more function calls The Go scheduler will sometimes preempt the running goroutine when it makes a non-inlineable function call Explicitly call runtime.Gosched Causes the current running goroutine to yield to the scheduler
  • 20. Think micro services Keep heterogeneous workloads in different Go processes One service handles quick or I/O heavy tasks One service handles long-running OS handles resource scheduling
  • 21. runtime.LockOSThread Locks the current goroutine to the current thread and doesn’t allow any other goroutines to run on that thread Call runtime.UnlockOSThread to unlock the thread.
  • 22. Extra Go Scheduler Topics There are a lot of topics relevant to the Go scheduler but beyond the scope of this presentation, including… Tailoring GOMAXPROCS for your workload How cgo calls interact with the scheduler
  • 23. Sources and Suggested Reading http://morsmachine.dk/go-scheduler http://morsmachine.dk/netpoller http://dave.cheney.net/2014/06/07/five-things-that-make- go-fast http://golang.org/pkg/runtime/ Code examples used in this presentation can be found at https://github.com/matthewdale/ GoSchedulerDemo