anyio
anyio copied to clipboard
Ratelimiter: refactor, add burst parameters
This PR adds comprehensive parameters to control the limiter's burst behavior.
- initial: the operations allowed in the first time window. May be zero, which is useful when you start a program and can't risk that the previous run has just filled its slot and exited.
- burst_rate: the percentage of "unused" operations that carry over from the previous timeslot(s).
- burst_max: the maximum for carry-over, to avoid large surges after doing nothing for some time.
This also fixes a race condition: if you exactly exhaust a time slot and then resume after the slot has ended, the previous version waited for the next slot unnecessarily.
TODO: tests for all of the above.
Did you see the changes I already made today?
Yes; I got notified about them after creating the PR … No free time to do more work on anyio today I'm afraid.
I'm feeling inclined to merge this, but I'll take a closer look and may adjust some minor details.