Go makes concurrent programming dead simple with the go keyword. And, with its “share memory by communicating” mantra, channels perform as a thread-safe mechanism for IO between threads. These primitives more than meet the demands of most parallel tasks. But sometimes workloads need extra coordination, particularly around error propagation or synchronization. For example, goroutines often need access to a shared yet thread-unsafe resource. Enter the standard library’s sync package with WaitGroup, Once, and Mutex. For...
In this first X-Files post, I’ll cover the simple yet powerful golang.org/x/time/rate. This package provides a Limiter that controls throughput to an arbitrary resource. There’s a ton of utility in rate, and to show its virtues, I will use it to enforce an SLA on an HTTP service. SLAs and Rate Limiting When creating a new service, it is prudent to specify a service level agreement, or SLA. This promises an expected availability given some...
This post will be the start of The X-Files, a blog series exploring the Go sub-repositories located at golang.org/x/*. Chances are, you may not have heard them called that before or know where they came from. Introductions are in order… A brief origin story Go promises, with reasonable exceptions, that its compiler and standard library will remain forward-compatible for all minor releases of the Go 1 language specification. This is incredibly refreshing, especially if you’ve...
I have fallen in love with the flexibility of io.Reader and io.Writer when dealing with any stream of data in Go. And while I am more or less smitten at this point, the reader interface challenged me with something you might think simple: splitting it in two. I’m not even certain “split” is the right word. I would like to receive an io.Reader and read over it multiple times, possibly in parallel. But because readers...
There seems to be a common complaint that working on WordPress plugins and themes locally is difficult to accomplish. If you only need to manage a handful of plugins or a couple themes, the tedium of setting up a dev environment isn’t too complicated; you would probably just have a single install of WP on a MAMP server. As my 8th-grade english teacher would say: done, like a cupcake! Things start to get real messy,...