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

Allow maxCASAttempts to be configurable #90

Merged

Conversation

roshan-gorasia-cko
Copy link
Contributor

@roshan-gorasia-cko roshan-gorasia-cko commented Jul 1, 2021

Hi,

We've recently come in need of having a configurable retry limit (maxCASAttemptsLimit). Currently as is, this is a constant set to 10 - Which isn't flexible in certain use cases.

This PR adds a NewGCRARateLimiterWithRetryLimit() function which can take in a user defined retry limit. The current NewGCRARateLimiter() in place will make use of the existing maxCASAttemptsLimit of 10.

While here, I also noticed that the current logic was always retrying +1 times of the defined limit. Therefore it was always attempting a maximum of 11 times with the default max attempt limit of 10. I've addressed this so the limit comparison is greater than or equal to (as opposed to greater than only)

Let me know what you think

Relates to: #91

@brandur
Copy link
Member

brandur commented Jul 3, 2021

@roshan-gorasia-cko What do you think about making this a setter on the limiter like SetMaxCASAttemptsLimit instead of a new constructor? I suspect that this option won't be needed all too often so it probably makes more sense to keep a little more hidden away.

@roshan-gorasia-cko roshan-gorasia-cko force-pushed the add-configurable-max-cas-attempts branch from 1065566 to 6ae33ff Compare July 5, 2021 08:51
@roshan-gorasia-cko roshan-gorasia-cko force-pushed the add-configurable-max-cas-attempts branch from 6ae33ff to c47c008 Compare July 5, 2021 08:52
@roshan-gorasia-cko
Copy link
Contributor Author

roshan-gorasia-cko commented Jul 5, 2021

@roshan-gorasia-cko What do you think about making this a setter on the limiter like SetMaxCASAttemptsLimit instead of a new constructor? I suspect that this option won't be needed all too often so it probably makes more sense to keep a little more hidden away.

@brandur Agreed! I've committed the changes

Just for my knowledge, what is the reasoning behind such an (arguably) high retry limit?

@brandur
Copy link
Member

brandur commented Jul 17, 2021

Thanks Roshan! Sorry about taking so long to get back on this. Changes LGTM.

Just for my knowledge, what is the reasoning behind such an (arguably) high retry limit?

So I'm not the original author (mostly just maintain it), but I bet the decision was pretty arbitrary — 10 is a nice, round number and they probably just went with that.

I think you're right though in that this isn't an optimal choice. If you are ever getting anywhere near 10 attempts on a regular basis than something is almost certainly wrong in that you're seeing way too much contention in the system. It could still work for a while, but in practice it'd mean that all rate limiting operations are taking way longer than they're supposed to (maybe 10x as long!). It would probably be smarter to only retry a few times and then error out earlier.

@brandur brandur merged commit 5769ec5 into throttled:master Jul 17, 2021
@brandur
Copy link
Member

brandur commented Jul 17, 2021

Released as version 2.9.0.

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.

None yet

2 participants