Skip to content

Use a 'leaky bucket' rate limiting algorithm using aiolimiter.AsyncLimiter.#14

Open
xprl-gjf wants to merge 1 commit intoFilipByren:mainfrom
xprl-gjf:main
Open

Use a 'leaky bucket' rate limiting algorithm using aiolimiter.AsyncLimiter.#14
xprl-gjf wants to merge 1 commit intoFilipByren:mainfrom
xprl-gjf:main

Conversation

@xprl-gjf
Copy link
Copy Markdown

@xprl-gjf xprl-gjf commented Apr 29, 2024

The current implementation introduces a delay between each request irrespective of whether or not the rate limit has been reached.

A more efficient algorithm is the 'leaky bucket' implementation of aiolimiter.AsyncLimiter. This supports "bursting' where the rate limiter has no effect until the limit has been reached. Only then are subsequent requests delayed.

Note that the existing functionality - a regular delay between all requests - can still be achieved by applying a rate limiter with a count of 1, e.g. client = OctopusApi(limiter=AsyncLimiter(1, 1/requests_per_second))

A further advantage of this code is that the same AsyncLimiter instance can be shared across multiple OctopusApi sessions, ensuring consistent application of rate limiting if a series of calls are made to various URLs on the same API service, using multiple OctopusApi sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant