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

Clarify rate limiter expressions in addsvc example #943

Merged
merged 1 commit into from
Jan 1, 2020

Conversation

marselester
Copy link
Contributor

Rate limiting examples might be a bit confusing when rate.Every method is used #698.
Naturally one would expect to see a throttling demo as a number of requests per unit of time

// 100 requests per second with burst of 100 requests.
rate.NewLimiter(rate.Limit(100), 100)

// 5 requests per minute with burst of 5 requests.
rate.NewLimiter(rate.Limit(5/time.Minute.Seconds()), 5)

instead of defining an interval between requests.

// 1 request per second with burst of 100 requests.
rate.NewLimiter(rate.Every(time.Second), 100)

// 5 requests per minute with burst of 5 requests.
rate.NewLimiter(rate.Every(time.Minute/time.Duration(5)), 5)

@peterbourgon
Copy link
Member

The different ways to express rate limits and burst capacity are properties of the rate limiting package, and it's expected that users will read those docs to learn more. It's not clear to me that your changes are strictly or even generally easier to understand, so I'm -1 on a wholesale change, but I'd welcome a change to one example, and comments (like you have in the comments) on both examples explaining what the expressions mean.

Rate limiting examples might be a bit confusing when Every
method is used go-kit#698.
One could expect to see throttling expressed as
a number of requests per unit of time whereas another would see it
as an interval between requests.
@marselester marselester changed the title Simplify rate limiter examples Clarify rate limiter expressions in addsvc example Dec 29, 2019
@marselester
Copy link
Contributor Author

I added comments to addsvc example since it has two rate limiters. It should be easier to spot the difference when comparing expressions side by side.

@peterbourgon peterbourgon merged commit 7ddd1d2 into go-kit:master Jan 1, 2020
jamesgist pushed a commit to jamesgist/kit that referenced this pull request Nov 1, 2024
Rate limiting examples might be a bit confusing when Every
method is used go-kit#698.
One could expect to see throttling expressed as
a number of requests per unit of time whereas another would see it
as an interval between requests.
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