Concurrency in Go: Tools and Techniques for Developers

Concurrency in Go: Tools and Techniques for Developers

by Katherine Cox-Buday

Paperback

$49.99
View All Available Formats & Editions
Choose Expedited Shipping at checkout for delivery by Thursday, April 15

Overview

Concurrency can be notoriously difficult to get right, but fortunately, the Go open source programming language makes working with concurrency tractable and even easy. If you’re a developer familiar with Go, this practical book demonstrates best practices and patterns to help you incorporate concurrency into your systems.

Author Katherine Cox-Buday takes you step-by-step through the process. You’ll understand how Go chooses to model concurrency, what issues arise from this model, and how you can compose primitives within this model to solve problems. Learn the skills and tooling you need to confidently write and implement concurrent systems of any size.

  • Understand how Go addresses fundamental problems that make concurrency difficult to do correctly
  • Learn the key differences between concurrency and parallelism
  • Dig into the syntax of Go’s memory synchronization primitives
  • Form patterns with these primitives to write maintainable concurrent code
  • Compose patterns into a series of practices that enable you to write large, distributed systems that scale
  • Learn the sophistication behind goroutines and how Go’s runtime stitches everything together

Product Details

ISBN-13: 9781491941195
Publisher: O'Reilly Media, Incorporated
Publication date: 08/11/2017
Pages: 238
Sales rank: 418,172
Product dimensions: 7.00(w) x 9.10(h) x 0.60(d)

About the Author

Katherine is a computer scientist currently working at Simple. Her hobbies include software engineering, creative writing, Go (igo, baduk, weiquei), and music, all of which she pursues intermittently and with various levels of dedication.

Table of Contents

Preface vii

1 An Introduction to Concurrency 1

Moore's Law, Web Scale, and the Mess We're In 2

Why Is Concurrency Hard? 4

Race Conditions 4

Atomicity 6

Memory Access Synchronization 8

Deadlocks, Livelocks, and Starvation 10

Determining Concurrency Safety 18

Simplicity in the Face of Complexity 20

2 Modeling Your Code: Communicating Sequential Processes 23

The Difference Between Concurrency and Parallelism 23

What Is CSP? 26

How This Helps You 29

Go's Philosophy on Concurrency 31

3 Go's Concurrency Building Blocks 37

Goroutines 37

The sync Package 47

WaitGroup 47

Mutex and RWMutex 49

Cond 52

Once 57

Pool 59

Channels 64

The select Statement 78

The GOMAXPROCS Lever 83

Conclusion 83

4 Concurrency Patterns in Go 85

Confinement 85

The for select Loop 89

Preventing Goroutine Leaks 90

The or-channel 94

Error Handling 97

Pipelines 100

Best Practices for Constructing Pipelines 104

Some Handy Generators 109

Fan-Out, Fan-In 114

The or-done-channel 119

The lee-channel 120

The bridge-channel 122

Queuing 124

The context Package 131

Summary 145

5 Concurrency at Scale 147

Error Propagation 147

Timeouts and Cancellation 155

Heartbeats 161

Replicated Requests 172

Rate Limiting 174

Healing Unhealthy Goroutines 188

Summary 194

6 Goroutines and the Go Runtime 197

Work Stealing 197

Stealing Tasks or Continuations? 204

Presenting All of This to the Developer 212

Conclusion 212

A Appendix 213

Index 219

Customer Reviews