anyio icon indicating copy to clipboard operation
anyio copied to clipboard

Ratelimiter: refactor, add burst parameters

Open smurfix opened this issue 3 months ago • 3 comments

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.

smurfix avatar Sep 30 '25 11:09 smurfix

Did you see the changes I already made today?

agronholm avatar Sep 30 '25 11:09 agronholm

Yes; I got notified about them after creating the PR … No free time to do more work on anyio today I'm afraid.

smurfix avatar Sep 30 '25 14:09 smurfix

I'm feeling inclined to merge this, but I'll take a closer look and may adjust some minor details.

agronholm avatar Oct 08 '25 08:10 agronholm