boinkor-net / governor

A rate-limiting library for Rust (f.k.a. ratelimit_meter)
https://github.com/boinkor-net/governor
MIT License
579 stars 45 forks source link

Keyed vs Direct #118

Closed conorbros closed 2 years ago

conorbros commented 2 years ago

Performance wise, is it preferable to construct a direct RateLimiter for each new connection or use a keyed one?

antifuchs commented 2 years ago

Good question - I'm pretty sure a real authoritative answer will involve benchmarks of your specific code base, but I imagine the following factors will play a role in how easy each method will be to execute:

With those in mind, it should be easier to find a representation that'll work for you - if there's a limit per connection (not per user) and you can easily associate a limiter with a connection - make it direct. Otherwise, if you limit per-user, I'd say go with the keyed variant.

Hope that helps - I'll close this issue, but feel free to re-open it you have follow-up questions.