governor 0.4.0 is out - very low-cost in-memory rate-limiting library with optional flexibility

51 points snafuchs

governor 0.4.0 has just been released. Governor (named after the iconic "steam governor" that regulates the speed of steam release from kettles) is a really speedy and efficient library for enforcing rate limits in applications. It implements the GCRA and has a pretty hefty test suite and extensive documentation.

There have been tons of improvements in this release, but 0.4.0 has one major new feature that I want to call out here: A trait & type argument that allows users to get extra information about rate limiting decisions.

Where by default, a positive decision ("you're under the rate limit, proceed") by default returns nothing other than Ok(()), now that can be customized to compute all sorts of things that applications may want to convey to downstream users - e.g. the amount of burst balance that remains, or the amount of time until the burst balance fully replenishes. There are some examples in the docs for the middleware module.

I'm pretty proud to say that the availability of behavior that gives you additional information comes at no run-time cost. If you opt into having it available, every positive decision will incur a little bit of overhead; but if you don't, governor is as fast as in the 0.3.x release (about 20 million decisions per second on CI workers)!

If you're a current or future user of governor, I hope you're as excited about this release as I am!