Free Sample
+ Collection

Mastering Concurrency in Go

Nathan Kozyra

Discover and harness Go's powerful concurrency features to develop and build fast, scalable network systems
RRP $30.99
RRP $50.99
Print + eBook

Want this title & more?

$16.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781783983483
Paperback328 pages

About This Book

  • Explore the core syntaxes and language features that enable concurrency in Go
  • Understand when and where to use concurrency to keep data consistent and applications non-blocking, responsive, and reliable
  • A practical approach to utilize application scaffolding to design highly-scalable programs that are deeply rooted in go routines and channels

Who This Book Is For

This book is intended for systems developers and programmers with some experience in either Go and/or concurrent programming who wish to become fluent in building high-performance applications that scale by leveraging single-core, multicore, or distributed concurrency.

Table of Contents

Chapter 1: An Introduction to Concurrency in Go
Introducing goroutines
Implementing the defer control mechanism
Understanding goroutines versus coroutines
Implementing channels
Closures and goroutines
Building a web spider using goroutines and channels
Chapter 2: Understanding the Concurrency Model
Understanding the working of goroutines
Synchronous versus asynchronous goroutines
Visualizing concurrency
RSS in action
A little bit about CSP
Go and the actor model
Object orientation
Using concurrency
Managing threads
Using sync and mutexes to lock data
Chapter 3: Developing a Concurrent Strategy
Applying efficiency in complex concurrency
Identifying race conditions with race detection
Synchronizing our concurrent operations
The project – multiuser appointment calendar
A multiuser Appointments Calendar
A note on style
A note on immutability
Chapter 4: Data Integrity in an Application
Getting deeper with mutexes and sync
The cost of goroutines
Working with files
Getting low – implementing C
Distributed Go
Some common consistency models
Using memcached
Chapter 5: Locks, Blocks, and Better Channels
Understanding blocking methods in Go
Cleaning up goroutines
Creating channels of channels
Pprof – yet another awesome tool
Handling deadlocks and errors
Chapter 6: C10K – A Non-blocking Web Server in Go
Attacking the C10K problem
Building our C10K web server
Serving pages
Multithreading and leveraging multiple cores
Exploring our web server
Chapter 7: Performance and Scalability
High performance in Go
Using the App Engine
Distributed Go
Some helpful libraries
Memory preservation
Chapter 8: Concurrent Application Architecture
Designing our concurrent application
Identifying our requirements
Using NoSQL as a data store in Go
Monitoring filesystem changes
Managing logfiles
Handling configuration files
Detecting file changes
Backing up our files
Designing our web interface
Reverting a file's history – command line
Checking the health of our server
Chapter 9: Logging and Testing Concurrency in Go
Handling errors and logging
Using the log4go package for robust logging
Using the runtime package for granular stack traces
Chapter 10: Advanced Concurrency and Best Practices
Going beyond the basics with channels
Building workers
Implementing nil channel blocks
Implementing more granular control over goroutines with tomb
Timing out with channels
Building a load balancer with concurrent patterns
Choosing unidirectional and bidirectional channels
Using an indeterminate channel type
Using Go with unit testing
Using Google App Engine
Utilizing best practices

What You Will Learn

  • Create goroutines as the building blocks of concurrency in Go
  • Extend the goroutines to include channels to open up communication
  • Design concurrent patterns to apply toward our examples and future applications
  • Explore methods to ensure data consistency remains paramount in concurrent and multi-core Go applications
  • Tune performance to squeeze the most out of existing hardware to keep your applications below resource thresholds
  • Utilize advanced concurrency patterns and best practices to stay low-level without compromising the simplicity of Go itself
  • Build several servers in Go that strongly utilize concurrency features

In Detail

This book will take you through the history of concurrency, how Go utilizes it, how Go differs from other languages, and the features and structures of Go's concurrency core. Each step of the way, the book will present real, usable examples with detailed descriptions of the methodologies used. By the end, you will feel comfortable designing a safe, data-consistent, high-performance concurrent application in Go.

The focus of this book is on showing you how Go can be used to program high-performance, robust concurrent programs with Go's unique form of multithreading, which employs goroutines that communicate and synchronize across channels. Designed for any curious developer or systems administrator with an interest in fast, non-blocking, and resource-thrifty systems applications, this book is an invaluable resource to help you understand Go's powerful concurrency focus.


Read More

Recommended for You