AaronErhardt / actix-governor

A middleware for actix-web that provides rate-limiting backed by governor.
GNU General Public License v3.0
103 stars 21 forks source link

per_second is the inverse of governor's #49

Closed kstrauser closed 2 months ago

kstrauser commented 2 months ago

In the governor code for .per_second(max_burst), the replenishment interval is set as 1 / max_burst seconds. But in the actix-governor code for .per_second(period), the replenishment period is set to be the passed in number of seconds. That is, .per_second(2) only allows an average of one request every 2 seconds, not 2 per second.

I've verified this by running:

$ for i in (seq 20); curl http://localhost:8080/...; echo; sleep .5; end

After the initial burst, only 1 out of every 4 requests succeeds. With .per_second(2), I would expect every request to succeed.

To get 2-per-second, I have to configure .per_millisecond(500), which I'd similarly have expected to mean "500 per millisecond", not "1 per every 500 milliseconds".

AaronErhardt commented 2 months ago

Fixed thanks to your PR and a new crates.io release.