Channels allow goroutines to communicate with each other through the use of signaling semantics. Channels accomplish this signaling through the use of sending/receiving data or by identifying state changes on individual channels. Don't architect software with the idea of channels being a queue, focus on signaling and the semantics that simplify the orchestration required.
- Learn about the design guidelines for channels.
Channel Communication
http://blog.golang.org/share-memory-by-communicating
http://www.goinggo.net/2014/02/the-nature-of-channels-in-go.html
A Retrospective on SEDA - Matt Welsh
- Large buffers prevent timely notification of back pressure.
- They defeat your ability to reduce back pressure in a timely matter.
- They can increase latency not reduce it.
- Use buffered channels to provide a way of maintaining continuity.
- Don't use them just for performance.
- Use them to handle well defined bursts of data.
- Use them to deal with speed of light issues between handoffs.
Bufferbloat: Dark Buffers in the Internet
Buffer Bloat Videos
Basic mechanics (Go Playground)
Tennis game (Go Playground)
Relay race (Go Playground)
Fan out pattern (Go Playground)
Monitor running time (Go Playground)
Channel communication ordering (Go Playground)
Write a program where two goroutines pass an integer back and forth ten times. Display when each goroutine receives the integer. Increment the integer with each pass. Once the integer equals ten, terminate the program cleanly.
Template (Go Playground) | Answer (Go Playground)
Write a program that uses a fan out pattern to generate 100 random numbers concurrently. Have each goroutine generate a single random number and return that number to the main goroutine over a buffered channel. Set the size of the buffer channel so no send every blocks. Don't allocate more buffers than you need. Have the main goroutine display each random number is receives and then terminate the program.
Template (Go Playground) | Answer (Go Playground)
All material is licensed under the Apache License Version 2.0, January 2004.