ratelimit
ratelimit copied to clipboard
Optimize Sleep Time for Multiple Limits
Chaining limits causes waiting processes to wake early and churn.
The RateLimitDecorator
could inspect the func
in __call__
and determine if it is a compatible wrapper with attributes like __func__
and __limits__
. It could then discard the previously wrapped func
, wrap the original __func__
, and append the previous __limits__
to its own instance. Then sleep time can be computed as the maximum period remaining of all limits.