SlideShare a Scribd company logo
www.cloudflare.com
A Channel Compendium
April 24, 2014
John Graham-Cumming
www.cloudflare.com
Often mentioned; rarely understood
www.cloudflare.com
Where channels came from
www.cloudflare.com
Channels
www.cloudflare.com
CSP
• Communication == synchronization

!
!
!
!
!
!
!
!
• When communication and synchronization go together it’s
easy to reason about processes
www.cloudflare.com
Channels
• Quick syntax review



c := make(chan bool)– Makes an unbuffered channel
of bools



c <- x – Sends a value on the channel



<- c – Receive a value on the channel



x = <- c – Receive a value and stores it in x



x, ok = <- c – Receive a value; ok will be false if
channel is closed and empty.
www.cloudflare.com
Unbuffered channels are best (mostly)
• They provide both communication and synchronization
func from(connection chan int) {"
connection <- rand.Intn(100)"
}"
!
func to(connection chan int) {"
i := <- connection"
fmt.Printf("Someone sent me %dn", i)"
}"
!
func main() {"
cpus := runtime.NumCPU()"
runtime.GOMAXPROCS(cpus)"
!
connection := make(chan int)"
go from(connection)"
go to(connection)"
…
www.cloudflare.com
SIGNALLING
www.cloudflare.com
Wait for an event
• Sometimes just closing a channel is enough

!
!
!
!
!
!
!
• Could replace close(c) with c <- true
c := make(chan bool)"
!
go func() {"
" // ... do some stuff"
" close(c)"
}()"
!
// ... do some other stuff"
<- c
www.cloudflare.com
Coordinate multiple goroutines
• Close a channel!
func worker(start chan bool) {"
<- start"
// ... do stuff"
}"
!
func main() {"
start := make(chan bool)"
!
for i := 0; i < 100; i++ {"
go worker(start)"
}"
!
close(start)"
!
// ... all workers running now"
}
www.cloudflare.com
Select
• Select statement enables sending/receiving on multiple
channels at once
select {"
case x := <- somechan:"
// ... do stuff with x"
!
case y, ok := <- someOtherchan:"
// ... do stuff with y"
// check ok to see if someOtherChan"
// is closed"
!
case outputChan <- z:"
// ... ok z was sent"
!
default:"
// ... no one wants to communicate"
}
www.cloudflare.com
Common idiom: for/select
for {"
select {"
case x := <- somechan:"
// ... do stuff with x"
!
case y, ok := <- someOtherchan:"
// ... do stuff with y"
// check ok to see if someOtherChan"
// is closed"
!
case outputChan <- z:"
// ... ok z was sent"
!
default:"
// ... no one wants to communicate"
}"
}
www.cloudflare.com
Terminate workers
• Close a channel to terminate multiple goroutines
func worker(die chan bool) {"
for {"
select {"
// ... do stuff cases"
case <- die: "
return"
}"
}"
}"
!
func main() {"
die := make(chan bool)"
for i := 0; i < 100; i++ {"
go worker(die)"
}"
close(die)"
…
www.cloudflare.com
Verify termination
• Terminate a goroutine and verify termination
func worker(die chan bool) {"
for {"
select {"
// ... do stuff cases"
case <- die:"
// ... do termination tasks "
die <- true"
return"
}"
}"
}"
func main() {"
die := make(chan bool)"
go worker(die)"
die <- true"
<- die"
}
www.cloudflare.com
Closed channels never block
func main() {"
c := make(chan bool)"
close(c)"
x := <- c"
fmt.Printf(“%#vn”, x)"
}
func main() {"
c := make(chan bool)"
close(c)"
c <- true"
}
func main() {"
c := make(chan bool)"
close(c)"
x, ok := <- c"
fmt.Printf(“%#v %#vn”, x, ok)"
}
x has the zero
value for the
channel’s type
ok is false
www.cloudflare.com
Closing buffered channels
func main() {"
c := make(chan int, 3)"
c <- 15"
c <- 34"
c <- 65"
close(c)"
!
fmt.Printf(“%dn”, <-c)"
fmt.Printf(“%dn”, <-c)"
fmt.Printf(“%dn”, <-c)"
!
fmt.Printf(“%dn”, <-c)"
}
Drains the buffered
data
Starts returning the
zero value
www.cloudflare.com
range
• Can be used to consume all values from a channel
func generator(strings chan string) {"
strings <- "Five hour's New York jet lag""
strings <- "and Cayce Pollard wakes in Camden Town""
strings <- "to the dire and ever-decreasing circles""
strings <- "of disrupted circadian rhythm.""
close(strings)"
}"
!
func main() {"
strings := make(chan string)"
go generator(strings)"
!
for s := range strings {"
fmt.Printf("%s ", s)"
}"
fmt.Printf("n");"
}
www.cloudflare.com
HIDE STATE
www.cloudflare.com
Example: unique ID service
• Just receive from id to get a unique ID

• Safe to share id channel across routines
id := make(chan string)"
!
go func() {"
var counter int64 = 0"
for {"
id <- fmt.Sprintf("%x", counter)"
counter += 1"
}"
}()"
!
x := <- id // x will be 1"
x = <- id // x will be 2
www.cloudflare.com
Example: memory recycler
func recycler(give, get chan []byte) {"
q := new(list.List)"
!
for {"
if q.Len() == 0 {"
q.PushFront(make([]byte, 100))"
}"
!
e := q.Front()"
!
select {"
case s := <-give:"
q.PushFront(s[:0])"
!
case get <- e.Value.([]byte):"
q.Remove(e)"
}"
}"
}
www.cloudflare.com
DEFAULT
www.cloudflare.comwww.cloudflare.com
select for non-blocking receive
idle:= make(chan []byte, 5)"
!
select {"
case b = <-idle:

!
default:"
makes += 1"
b = make([]byte, size)"
}
Try to get from the
idle queue
Idle queue empty?
Make a new buffer
A buffered channel
makes a simple
queue
www.cloudflare.comwww.cloudflare.com
select for non-blocking send
idle:= make(chan []byte, 5)"
!
select {"
case idle <- b:"
!
default:"
}
A buffered channel
makes a simple
queue
Try to return buffer
to the idle queue
Idle queue full? GC
will have to deal
with the buffer
www.cloudflare.com
NIL CHANNELS
www.cloudflare.com
nil channels block
func main() {"
var c chan bool"
<- c"
}
func main() {"
var c chan bool"
c <- true"
}
www.cloudflare.com
nil channels useful in select
for {"
select {"
case x, ok := <-c1:"
if !ok {"
c1 = nil"
}"
!
case x, ok := <-c2:"
if !ok {"
c2 = nil"
}"
}"
if c1 == nil && c2 == nil {"
return"
}"
}
www.cloudflare.com
Works for sending channels also
c := make(chan int)"
d := make(chan bool)"
!
go func(src chan int) {"
" for {"
" " select {"
" " case src <- rand.Intn(100):"
!
" " case <-d:"
" " " src = nil"
" " }"
" }"
}(c)"
!
fmt.Printf("%dn", <-c)"
fmt.Printf("%dn", <-c)"
d <- true"
fmt.Printf("%dn", <-c)
www.cloudflare.com
TIMERS
www.cloudflare.com
Timeout
func worker(start chan bool) {"
for {"
" timeout := time.After(30 * time.Second)"
" select {"
// ... do some stuff"
!
case <- timeout:"
return"
}"
}"
}
func worker(start chan bool) {"
timeout := time.After(30 * time.Second)"
for {"
" select {"
// ... do some stuff"
!
case <- timeout:"
return"
}"
}"
}
www.cloudflare.com
Heartbeat
func worker(start chan bool) {"
heartbeat := time.Tick(30 * time.Second)"
for {"
" select {"
// ... do some stuff"
!
case <- heartbeat:"
// ... do heartbeat stuff"
}"
}"
}
www.cloudflare.com
EXAMPLES
www.cloudflare.com
Example: network multiplexor
• Multiple goroutines can send on the same channel
func worker(messages chan string) {"
for {"
var msg string // ... generate a message"
messages <- msg"
}"
}"
func main() {"
messages := make(chan string)"
conn, _ := net.Dial("tcp", "example.com")"
!
for i := 0; i < 100; i++ {"
go worker(messages)"
}"
for {"
msg := <- messages"
conn.Write([]byte(msg))"
}"
}
www.cloudflare.com
Example: first of N
• Dispatch requests and get back the first one to complete
type response struct {"
resp *http.Response"
url string"
}"
!
func get(url string, r chan response ) {"
if resp, err := http.Get(url); err == nil {"
r <- response{resp, url}"
}"
}"
!
func main() {"
first := make(chan response)"
for _, url := range []string{"http://code.jquery.com/jquery-1.9.1.min.js","
"http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js","
"http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js","
"http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"} {"
go get(url, first)"
}"
!
r := <- first"
// ... do something"
}
www.cloudflare.com
Passing a ‘response’ channel
type work struct {"
url string"
resp chan *http.Response"
}"
!
func getter(w chan work) {"
for {"
do := <- w"
resp, _ := http.Get(do.url)"
do.resp <- resp"
}"
}"
!
func main() {"
w := make(chan work)"
!
go getter(w)"
!
resp := make(chan *http.Response)"
w <- work{"http://cdnjs.cloudflare.com/jquery/1.9.1/jquery.min.js","
resp}"
!
r := <- resp"
}
www.cloudflare.com
Example: an HTTP load balancer
• Limited number of HTTP clients can make requests for
URLs

• Unlimited number of goroutines need to request URLs and
get responses

• Solution: an HTTP request load balancer
www.cloudflare.com
A URL getter
type job struct {"
url string"
resp chan *http.Response"
}"
!
type worker struct {"
jobs chan *job"
count int"
}"
!
func (w *worker) getter(done chan *worker) {"
for {"
j := <- w.jobs"
resp, _ := http.Get(j.url)"
j.resp <- resp"
done <- w"
}"
}
www.cloudflare.com
A way to get URLs
func get(jobs chan *job, url string, answer chan string) {"
resp := make(chan *http.Response)"
jobs <- &job{url, resp}"
r := <- resp"
answer <- r.Request.URL.String()"
}"
!
func main() {"
jobs := balancer(10, 10)"
answer := make(chan string)"
for {"
var url string"
if _, err := fmt.Scanln(&url); err != nil {"
break"
}"
go get(jobs, url, answer)"
}"
for u := range answer {"
fmt.Printf("%sn", u)"
}"
}
www.cloudflare.com
A load balancer
func balancer(count int, depth int) chan *job {"
jobs := make(chan *job)"
done := make(chan *worker)"
workers := make([]*worker, count)"
!
for i := 0; i < count; i++ {"
workers[i] = &worker{make(chan *job,

depth), 0}"
go workers[i].getter(done)"
}"
!
go func() {"
for {"
var free *worker"
min := depth"
for _, w := range workers {"
if w.count < min {"
free = w"
min = w.count"
}"
}"
!
var jobsource chan *job"
if free != nil {"
jobsource = jobs"
}
!
select {"
case j := <- jobsource:"
free.jobs <- j"
free.count++"
!
case w := <- done:"
w.count—"
}"
}"
}()"
!
return jobs"
}"
www.cloudflare.com
THANKS
The Go Way: “small sequential pieces joined
by channels”

More Related Content

What's hot

Tutorial Stream Reasoning SPARQLstream and Morph-streams
Tutorial Stream Reasoning SPARQLstream and Morph-streamsTutorial Stream Reasoning SPARQLstream and Morph-streams
Tutorial Stream Reasoning SPARQLstream and Morph-streamsJean-Paul Calbimonte
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
Andy McKay
 
Www.cheatgame4u.blogspot.com gemhackcode
Www.cheatgame4u.blogspot.com gemhackcodeWww.cheatgame4u.blogspot.com gemhackcode
Www.cheatgame4u.blogspot.com gemhackcode
Ameth Psycedelic
 
Ugly code
Ugly codeUgly code
Ugly codeOdd-e
 
Classic Games Development with Drools
Classic Games Development with DroolsClassic Games Development with Drools
Classic Games Development with Drools
Mark Proctor
 
PyCon lightning talk on my Toro module for Tornado
PyCon lightning talk on my Toro module for TornadoPyCon lightning talk on my Toro module for Tornado
PyCon lightning talk on my Toro module for Tornado
emptysquare
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184
Mahmoud Samir Fayed
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
Jason Lotito
 
SmokeTests
SmokeTestsSmokeTests
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
Murali Kummitha
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
Roman Elizarov
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer Programming
Utsav Patel
 
bank management system
bank management systembank management system
bank management system
Aisha Aisha
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
Anna Su
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術
名辰 洪
 
누구나 할 수 있다 Networking
누구나 할 수 있다 Networking누구나 할 수 있다 Networking
누구나 할 수 있다 Networking
Jungwon An
 
Idiomatic kotlin
Idiomatic kotlinIdiomatic kotlin
Idiomatic kotlin
Anton Arhipov
 
Real Time Event Dispatcher
Real Time Event DispatcherReal Time Event Dispatcher
Real Time Event Dispatcher
Peter Dietrich
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
Learning Rule Based Programming using Games @DecisionCamp 2016
Learning Rule Based Programming using Games @DecisionCamp 2016Learning Rule Based Programming using Games @DecisionCamp 2016
Learning Rule Based Programming using Games @DecisionCamp 2016
Mark Proctor
 

What's hot (20)

Tutorial Stream Reasoning SPARQLstream and Morph-streams
Tutorial Stream Reasoning SPARQLstream and Morph-streamsTutorial Stream Reasoning SPARQLstream and Morph-streams
Tutorial Stream Reasoning SPARQLstream and Morph-streams
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Www.cheatgame4u.blogspot.com gemhackcode
Www.cheatgame4u.blogspot.com gemhackcodeWww.cheatgame4u.blogspot.com gemhackcode
Www.cheatgame4u.blogspot.com gemhackcode
 
Ugly code
Ugly codeUgly code
Ugly code
 
Classic Games Development with Drools
Classic Games Development with DroolsClassic Games Development with Drools
Classic Games Development with Drools
 
PyCon lightning talk on my Toro module for Tornado
PyCon lightning talk on my Toro module for TornadoPyCon lightning talk on my Toro module for Tornado
PyCon lightning talk on my Toro module for Tornado
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
 
SmokeTests
SmokeTestsSmokeTests
SmokeTests
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer Programming
 
bank management system
bank management systembank management system
bank management system
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術
 
누구나 할 수 있다 Networking
누구나 할 수 있다 Networking누구나 할 수 있다 Networking
누구나 할 수 있다 Networking
 
Idiomatic kotlin
Idiomatic kotlinIdiomatic kotlin
Idiomatic kotlin
 
Real Time Event Dispatcher
Real Time Event DispatcherReal Time Event Dispatcher
Real Time Event Dispatcher
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 
Learning Rule Based Programming using Games @DecisionCamp 2016
Learning Rule Based Programming using Games @DecisionCamp 2016Learning Rule Based Programming using Games @DecisionCamp 2016
Learning Rule Based Programming using Games @DecisionCamp 2016
 

Viewers also liked

Fraser Graham Killer Robots
Fraser Graham Killer RobotsFraser Graham Killer Robots
Fraser Graham Killer RobotsArtem Kovardin
 
Go database/sql
Go database/sqlGo database/sql
Go database/sql
Artem Kovardin
 
Building A Relevancy Engine Using MongoDB and Go
Building A Relevancy Engine Using MongoDB and GoBuilding A Relevancy Engine Using MongoDB and Go
Building A Relevancy Engine Using MongoDB and Go
ardan-bkennedy
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
Derek Collison
 
Best practices-for-production-environments
Best practices-for-production-environmentsBest practices-for-production-environments
Best practices-for-production-environmentsArtem Kovardin
 
Running Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteRunning Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without Parachute
Cloudflare
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014
Cloudflare
 
Go Containers
Go ContainersGo Containers
Go Containers
Cloudflare
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - Webinar
Cloudflare
 
Secure 2013 Poland
Secure 2013 PolandSecure 2013 Poland
Secure 2013 PolandCloudflare
 
Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014
Cloudflare
 
Overview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youOverview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for you
Cloudflare
 
SortaSQL
SortaSQLSortaSQL
SortaSQL
Cloudflare
 
WordPress London Meetup January 2012
WordPress London Meetup January 2012WordPress London Meetup January 2012
WordPress London Meetup January 2012Cloudflare
 
Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season
Cloudflare
 
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksHow to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
Cloudflare
 
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSRunning a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Cloudflare
 
Botconf ppt
Botconf   pptBotconf   ppt
Botconf ppt
Cloudflare
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Cloudflare
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
Cloudflare
 

Viewers also liked (20)

Fraser Graham Killer Robots
Fraser Graham Killer RobotsFraser Graham Killer Robots
Fraser Graham Killer Robots
 
Go database/sql
Go database/sqlGo database/sql
Go database/sql
 
Building A Relevancy Engine Using MongoDB and Go
Building A Relevancy Engine Using MongoDB and GoBuilding A Relevancy Engine Using MongoDB and Go
Building A Relevancy Engine Using MongoDB and Go
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
 
Best practices-for-production-environments
Best practices-for-production-environmentsBest practices-for-production-environments
Best practices-for-production-environments
 
Running Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteRunning Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without Parachute
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014
 
Go Containers
Go ContainersGo Containers
Go Containers
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - Webinar
 
Secure 2013 Poland
Secure 2013 PolandSecure 2013 Poland
Secure 2013 Poland
 
Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014
 
Overview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youOverview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for you
 
SortaSQL
SortaSQLSortaSQL
SortaSQL
 
WordPress London Meetup January 2012
WordPress London Meetup January 2012WordPress London Meetup January 2012
WordPress London Meetup January 2012
 
Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season
 
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksHow to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
 
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSRunning a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
 
Botconf ppt
Botconf   pptBotconf   ppt
Botconf ppt
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
 

Similar to A Channel Compendium

Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go ConcurrencyCloudflare
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to GoCloudflare
 
Go Concurrency Patterns
Go Concurrency PatternsGo Concurrency Patterns
Go Concurrency Patterns
ElifTech
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
Guilherme Garnier
 
Concurrency in go
Concurrency in goConcurrency in go
Concurrency in go
borderj
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
Alex Payne
 
Writing Docker monitoring agent with Go
Writing Docker monitoring agent with GoWriting Docker monitoring agent with Go
Writing Docker monitoring agent with Go
Naoki AINOYA
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
InfluxData
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]testduser1
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]User1test
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017
Jonathon Brouse
 
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Brian Sam-Bodden
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
Mosky Liu
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinJVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
Andrey Breslav
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
inovex GmbH
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
InfluxData
 

Similar to A Channel Compendium (20)

Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Go Concurrency Patterns
Go Concurrency PatternsGo Concurrency Patterns
Go Concurrency Patterns
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
 
Concurrency in go
Concurrency in goConcurrency in go
Concurrency in go
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
Writing Docker monitoring agent with Go
Writing Docker monitoring agent with GoWriting Docker monitoring agent with Go
Writing Docker monitoring agent with Go
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017
 
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinJVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 

More from Cloudflare

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)
Cloudflare
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with Cloudflare
Cloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware appliance
Cloudflare
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Cloudflare
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021
Cloudflare
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
Cloudflare
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fast
Cloudflare
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
Cloudflare
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...
Cloudflare
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-service
Cloudflare
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare data
Cloudflare
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respond
Cloudflare
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)
Cloudflare
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providers
Cloudflare
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Cloudflare
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North America
Cloudflare
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?
Cloudflare
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)
Cloudflare
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teams
Cloudflare
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
Cloudflare
 

More from Cloudflare (20)

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with Cloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware appliance
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fast
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-service
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare data
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respond
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providers
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North America
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teams
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
 

Recently uploaded

Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

A Channel Compendium

  • 1. www.cloudflare.com A Channel Compendium April 24, 2014 John Graham-Cumming
  • 5. www.cloudflare.com CSP • Communication == synchronization ! ! ! ! ! ! ! ! • When communication and synchronization go together it’s easy to reason about processes
  • 6. www.cloudflare.com Channels • Quick syntax review
 
 c := make(chan bool)– Makes an unbuffered channel of bools
 
 c <- x – Sends a value on the channel
 
 <- c – Receive a value on the channel
 
 x = <- c – Receive a value and stores it in x
 
 x, ok = <- c – Receive a value; ok will be false if channel is closed and empty.
  • 7. www.cloudflare.com Unbuffered channels are best (mostly) • They provide both communication and synchronization func from(connection chan int) {" connection <- rand.Intn(100)" }" ! func to(connection chan int) {" i := <- connection" fmt.Printf("Someone sent me %dn", i)" }" ! func main() {" cpus := runtime.NumCPU()" runtime.GOMAXPROCS(cpus)" ! connection := make(chan int)" go from(connection)" go to(connection)" …
  • 9. www.cloudflare.com Wait for an event • Sometimes just closing a channel is enough ! ! ! ! ! ! ! • Could replace close(c) with c <- true c := make(chan bool)" ! go func() {" " // ... do some stuff" " close(c)" }()" ! // ... do some other stuff" <- c
  • 10. www.cloudflare.com Coordinate multiple goroutines • Close a channel! func worker(start chan bool) {" <- start" // ... do stuff" }" ! func main() {" start := make(chan bool)" ! for i := 0; i < 100; i++ {" go worker(start)" }" ! close(start)" ! // ... all workers running now" }
  • 11. www.cloudflare.com Select • Select statement enables sending/receiving on multiple channels at once select {" case x := <- somechan:" // ... do stuff with x" ! case y, ok := <- someOtherchan:" // ... do stuff with y" // check ok to see if someOtherChan" // is closed" ! case outputChan <- z:" // ... ok z was sent" ! default:" // ... no one wants to communicate" }
  • 12. www.cloudflare.com Common idiom: for/select for {" select {" case x := <- somechan:" // ... do stuff with x" ! case y, ok := <- someOtherchan:" // ... do stuff with y" // check ok to see if someOtherChan" // is closed" ! case outputChan <- z:" // ... ok z was sent" ! default:" // ... no one wants to communicate" }" }
  • 13. www.cloudflare.com Terminate workers • Close a channel to terminate multiple goroutines func worker(die chan bool) {" for {" select {" // ... do stuff cases" case <- die: " return" }" }" }" ! func main() {" die := make(chan bool)" for i := 0; i < 100; i++ {" go worker(die)" }" close(die)" …
  • 14. www.cloudflare.com Verify termination • Terminate a goroutine and verify termination func worker(die chan bool) {" for {" select {" // ... do stuff cases" case <- die:" // ... do termination tasks " die <- true" return" }" }" }" func main() {" die := make(chan bool)" go worker(die)" die <- true" <- die" }
  • 15. www.cloudflare.com Closed channels never block func main() {" c := make(chan bool)" close(c)" x := <- c" fmt.Printf(“%#vn”, x)" } func main() {" c := make(chan bool)" close(c)" c <- true" } func main() {" c := make(chan bool)" close(c)" x, ok := <- c" fmt.Printf(“%#v %#vn”, x, ok)" } x has the zero value for the channel’s type ok is false
  • 16. www.cloudflare.com Closing buffered channels func main() {" c := make(chan int, 3)" c <- 15" c <- 34" c <- 65" close(c)" ! fmt.Printf(“%dn”, <-c)" fmt.Printf(“%dn”, <-c)" fmt.Printf(“%dn”, <-c)" ! fmt.Printf(“%dn”, <-c)" } Drains the buffered data Starts returning the zero value
  • 17. www.cloudflare.com range • Can be used to consume all values from a channel func generator(strings chan string) {" strings <- "Five hour's New York jet lag"" strings <- "and Cayce Pollard wakes in Camden Town"" strings <- "to the dire and ever-decreasing circles"" strings <- "of disrupted circadian rhythm."" close(strings)" }" ! func main() {" strings := make(chan string)" go generator(strings)" ! for s := range strings {" fmt.Printf("%s ", s)" }" fmt.Printf("n");" }
  • 19. www.cloudflare.com Example: unique ID service • Just receive from id to get a unique ID • Safe to share id channel across routines id := make(chan string)" ! go func() {" var counter int64 = 0" for {" id <- fmt.Sprintf("%x", counter)" counter += 1" }" }()" ! x := <- id // x will be 1" x = <- id // x will be 2
  • 20. www.cloudflare.com Example: memory recycler func recycler(give, get chan []byte) {" q := new(list.List)" ! for {" if q.Len() == 0 {" q.PushFront(make([]byte, 100))" }" ! e := q.Front()" ! select {" case s := <-give:" q.PushFront(s[:0])" ! case get <- e.Value.([]byte):" q.Remove(e)" }" }" }
  • 22. www.cloudflare.comwww.cloudflare.com select for non-blocking receive idle:= make(chan []byte, 5)" ! select {" case b = <-idle:
 ! default:" makes += 1" b = make([]byte, size)" } Try to get from the idle queue Idle queue empty? Make a new buffer A buffered channel makes a simple queue
  • 23. www.cloudflare.comwww.cloudflare.com select for non-blocking send idle:= make(chan []byte, 5)" ! select {" case idle <- b:" ! default:" } A buffered channel makes a simple queue Try to return buffer to the idle queue Idle queue full? GC will have to deal with the buffer
  • 25. www.cloudflare.com nil channels block func main() {" var c chan bool" <- c" } func main() {" var c chan bool" c <- true" }
  • 26. www.cloudflare.com nil channels useful in select for {" select {" case x, ok := <-c1:" if !ok {" c1 = nil" }" ! case x, ok := <-c2:" if !ok {" c2 = nil" }" }" if c1 == nil && c2 == nil {" return" }" }
  • 27. www.cloudflare.com Works for sending channels also c := make(chan int)" d := make(chan bool)" ! go func(src chan int) {" " for {" " " select {" " " case src <- rand.Intn(100):" ! " " case <-d:" " " " src = nil" " " }" " }" }(c)" ! fmt.Printf("%dn", <-c)" fmt.Printf("%dn", <-c)" d <- true" fmt.Printf("%dn", <-c)
  • 29. www.cloudflare.com Timeout func worker(start chan bool) {" for {" " timeout := time.After(30 * time.Second)" " select {" // ... do some stuff" ! case <- timeout:" return" }" }" } func worker(start chan bool) {" timeout := time.After(30 * time.Second)" for {" " select {" // ... do some stuff" ! case <- timeout:" return" }" }" }
  • 30. www.cloudflare.com Heartbeat func worker(start chan bool) {" heartbeat := time.Tick(30 * time.Second)" for {" " select {" // ... do some stuff" ! case <- heartbeat:" // ... do heartbeat stuff" }" }" }
  • 32. www.cloudflare.com Example: network multiplexor • Multiple goroutines can send on the same channel func worker(messages chan string) {" for {" var msg string // ... generate a message" messages <- msg" }" }" func main() {" messages := make(chan string)" conn, _ := net.Dial("tcp", "example.com")" ! for i := 0; i < 100; i++ {" go worker(messages)" }" for {" msg := <- messages" conn.Write([]byte(msg))" }" }
  • 33. www.cloudflare.com Example: first of N • Dispatch requests and get back the first one to complete type response struct {" resp *http.Response" url string" }" ! func get(url string, r chan response ) {" if resp, err := http.Get(url); err == nil {" r <- response{resp, url}" }" }" ! func main() {" first := make(chan response)" for _, url := range []string{"http://code.jquery.com/jquery-1.9.1.min.js"," "http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"," "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"," "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"} {" go get(url, first)" }" ! r := <- first" // ... do something" }
  • 34. www.cloudflare.com Passing a ‘response’ channel type work struct {" url string" resp chan *http.Response" }" ! func getter(w chan work) {" for {" do := <- w" resp, _ := http.Get(do.url)" do.resp <- resp" }" }" ! func main() {" w := make(chan work)" ! go getter(w)" ! resp := make(chan *http.Response)" w <- work{"http://cdnjs.cloudflare.com/jquery/1.9.1/jquery.min.js"," resp}" ! r := <- resp" }
  • 35. www.cloudflare.com Example: an HTTP load balancer • Limited number of HTTP clients can make requests for URLs • Unlimited number of goroutines need to request URLs and get responses
 • Solution: an HTTP request load balancer
  • 36. www.cloudflare.com A URL getter type job struct {" url string" resp chan *http.Response" }" ! type worker struct {" jobs chan *job" count int" }" ! func (w *worker) getter(done chan *worker) {" for {" j := <- w.jobs" resp, _ := http.Get(j.url)" j.resp <- resp" done <- w" }" }
  • 37. www.cloudflare.com A way to get URLs func get(jobs chan *job, url string, answer chan string) {" resp := make(chan *http.Response)" jobs <- &job{url, resp}" r := <- resp" answer <- r.Request.URL.String()" }" ! func main() {" jobs := balancer(10, 10)" answer := make(chan string)" for {" var url string" if _, err := fmt.Scanln(&url); err != nil {" break" }" go get(jobs, url, answer)" }" for u := range answer {" fmt.Printf("%sn", u)" }" }
  • 38. www.cloudflare.com A load balancer func balancer(count int, depth int) chan *job {" jobs := make(chan *job)" done := make(chan *worker)" workers := make([]*worker, count)" ! for i := 0; i < count; i++ {" workers[i] = &worker{make(chan *job,
 depth), 0}" go workers[i].getter(done)" }" ! go func() {" for {" var free *worker" min := depth" for _, w := range workers {" if w.count < min {" free = w" min = w.count" }" }" ! var jobsource chan *job" if free != nil {" jobsource = jobs" } ! select {" case j := <- jobsource:" free.jobs <- j" free.count++" ! case w := <- done:" w.count—" }" }" }()" ! return jobs" }"
  • 39. www.cloudflare.com THANKS The Go Way: “small sequential pieces joined by channels”