SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
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”

Más contenido relacionado

La actualidad más candente

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 EngineAndy McKay
 
Www.cheatgame4u.blogspot.com gemhackcode
Www.cheatgame4u.blogspot.com gemhackcodeWww.cheatgame4u.blogspot.com gemhackcode
Www.cheatgame4u.blogspot.com gemhackcodeAmeth 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 DroolsMark 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 Tornadoemptysquare
 
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 184Mahmoud Samir Fayed
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Jason Lotito
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Roman Elizarov
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingUtsav Patel
 
bank management system
bank management systembank management system
bank management systemAisha Aisha
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?Anna Su
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術名辰 洪
 
누구나 할 수 있다 Networking
누구나 할 수 있다 Networking누구나 할 수 있다 Networking
누구나 할 수 있다 NetworkingJungwon An
 
Real Time Event Dispatcher
Real Time Event DispatcherReal Time Event Dispatcher
Real Time Event DispatcherPeter Dietrich
 
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 2016Mark Proctor
 

La actualidad más candente (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
 

Destacado

Fraser Graham Killer Robots
Fraser Graham Killer RobotsFraser Graham Killer Robots
Fraser Graham Killer RobotsArtem 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 Goardan-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 2014Derek 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 ParachuteCloudflare
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Cloudflare
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudflare
 
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 2014Cloudflare
 
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 youCloudflare
 
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 AttacksCloudflare
 
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 DNSCloudflare
 
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 2014Cloudflare
 

Destacado (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 a A Channel Compendium

Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrencyjgrahamc
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go ConcurrencyCloudflare
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-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 PatternsElifTech
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practiceGuilherme Garnier
 
Concurrency in go
Concurrency in goConcurrency in go
Concurrency in goborderj
 
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 HorizonAlex Payne
 
Writing Docker monitoring agent with Go
Writing Docker monitoring agent with GoWriting Docker monitoring agent with Go
Writing Docker monitoring agent with GoNaoki 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 PiInfluxData
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor 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 2017Jonathon 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 concurrencyMosky 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 KotlinAndrey Breslav
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegeninovex 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 DixInfluxData
 

Similar a 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
 

Más de 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 CloudflareCloudflare
 
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 applianceCloudflare
 
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 WebinarCloudflare
 
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 2021Cloudflare
 
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 fastCloudflare
 
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-serviceCloudflare
 
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 dataCloudflare
 
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 respondCloudflare
 
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 providersCloudflare
 
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 AttacksCloudflare
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaCloudflare
 
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 teamsCloudflare
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformationCloudflare
 

Más de 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
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 

Último (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

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”