Performance at GitHub: deferring stats with rack.after_reply
Apr 11, 2022blakewilliams

Summary
Implemented `rack.after_reply` functionality in Unicorn to defer expensive telemetry calls (statsd metrics flushing) out of the critical request path. This resulted in a 30ms p50 and 50ms+ p99 improvement on every request across the site. Developed a wrapper class for `rack.after_reply` to buffer and flush telemetry data after the response is sent. Added timeout behavior to prevent `rack.after_reply` code from running too long and increasing HTTP queueing.