GopherCon Europe 2020: Matt Layher - Schedgroup: a Timer-Based Goroutine Concurrency Primitive

preview_player
Показать описание
About the talk:
Go provides first-class support for concurrency primitives such as goroutines, channels, and select statements. In addition, the Go runtime provides excellent support for high-resolution timers. By combining these primitives, we can create powerful new ones that take advantage of Go’s concurrency and runtime timer facilities.

This talk will introduce a timer-based concurrency primitive called a “schedgroup”: short for “scheduler group”. The schedgroup.Group API mimics the familiar and simple sync.WaitGroup from Go’s standard library. The key feature of the schedgroup.Group type is its ability to efficiently delay or schedule the execution of goroutines according to user-specified time values.

While prototyping the schedgroup package, several different designs were explored, each with differing advantages and disadvantages:

- a minimal implementation which creates a timer per goroutine for scheduling tasks
- a timer-polling approach which checks for scheduled tasks in a queue at a fixed interval
- an event-driven scheduler approach which uses a priority queue and signaling with channels

This talk will demonstrate the strengths and weaknesses of each prototype, building on top of each previous iteration until we reach the final design and implementation of the package as it stands today. During the presentation, attendees will learn about concepts related to Go concurrency and runtime timers, including:
- blocking and non-blocking channel send/receive operations within a select statement
- patterns for implementing context cancelation in concurrent systems
- troubleshooting and prevention of goroutine deadlocks
- efficient use of Go’s time.Timer APIs for tracking elapsed time during operations
- implementing a time-based priority queue with Go’s container/heap package

About the speaker:

#gopherconEU
Рекомендации по теме