Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New requests_per_* API #50

Merged
merged 4 commits into from
Sep 16, 2024
Merged

Conversation

kstrauser
Copy link
Contributor

This addresses #49. The current .per_second API is the inverse of governor's. There, it means "the number of requests to allow per second". Here, it means "the number of seconds between requests".

It would be bad to break the current API. Users who've written .per_second(10), meaning "about 6 per minute", should not find their server suddenly honoring "about 600 per minute". That would be bad. Instead, this creates a new API by deprecating the old methods and renaming them:

  • .per_second -> .seconds_per_request
  • .per_millisecond -> .milliseconds_per_request
  • .per_nanosecond -> .nanoseconds_per_request

That means current code will still work exactly as before, but devs will be nudged to rename their calls. It also adds new methods:

  • .requests_per_second (corresponding to governor's . per_second)
  • .requests_per_minute (governor's .per_minute)
  • .requests_per_hour (governor's .per_hour)

There's no .requests_per_{milli,nano}second because at that point the rates aren't actually being limited on hardware that exists today.

I think that .requests_per_second will be the most frequently used. That's what motivated me to file the bug and write this patch: I wanted to limit an API to 2 calls per second. When I wrote .per_second(2), I was surprised to find it meant 1 call every 2 seconds. I ended up with .per_millisecond(500), which to me sounded like "500 per millisecond". With the renamed API, that would be .milliseconds_per_request(500) which I find to be a lot clearer, or .requests_per_second(2) which is also clear to me.

Copy link
Owner

@AaronErhardt AaronErhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, code looks good!

@AaronErhardt AaronErhardt merged commit b33b03c into AaronErhardt:main Sep 16, 2024
1 check passed
@kstrauser kstrauser deleted the ks-requests-per branch September 18, 2024 03:15
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.

2 participants