Weekly notes #5
Idempotency for POSTs, on dangers of Ruby’s Timeout and how Java solved the same problem.
Ruby, systems, performance, and programming links from last week.
Designing robust and predictable APIs with idempotency - Brandur Leach from Stripe discusses the benefits of retriable, idempotent requests, idempotency keys for POSTs, and jitter as a way that avoids thundering herd effect.
The Google Analytics Setup I Use on Every Site I Build - getting the most out of Google Analytics. Perf hacks, error tracking, granular interactions and precise (not sampled) timing measurements. A must have.
Incident report on memory leak caused by Cloudflare parser bug and Postmortem of database outage of January 31 - two post mortems from Cloudflare and GitLab, respectively. Both really good - GitLab’s transparency is remarkable. I assume they sent another, private email with recommended actions to affected users - as this info is not in the post.
The Oldest Bug In Ruby - Why Rack::Timeout Might Hose your Server
Why Ruby’s Timeout is dangerous (and Thread.raise is terrifying)
Interrupts (The Java™ Tutorials > Essential Classes > Concurrency).
Timeouts in MRI Ruby are implemented by spawning a new and raising an exception in the original thread after some time elapses. However, this exception can be raised in the middle of an ensure block, effectively causing resource leaks. Richard Schneeman describes the issue and proposes a solution at the end of the post (basically an exception would be delayed only after ensure). Julia’s post adds more details and points to Java’s own solution to this problem - only certain operations can be aborted using Timeout exceptions, e.g.
sleep, for others, the code itself has to check a flag set on the thread. Sounds easy in principle, so I’m sure that for MRI, it would be a SMOP.
Accidentally Quadratic — Ruby
reject! - Ruby’s
reject! was quadratic in complexity between 1.9.3 and 2.3, as it shifted all subsequent of the array whenever an element was removed.
TDD, Straw Men, and Rhetoric and Test Isolation Is About Avoiding Mocks - Gary Bernhardt’s articles on benefits of sub-second test suite and preventing nested Mocking.
Double splat to merge hashes - The Pug Automatic - Neat tick!
Sorting out graph processing - when doing large graph processing, is it faster to pre-sort edges or to do random-accesses? Turns out (radix) pre-sorting is really not that slow.