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

Change to Token Bucket rate limiting. Change defer semantics since Block() isn't in a hot path. #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamdrake
Copy link

This is an example implementation to address #6. For the moment, it uses the Token Bucket Algorithm to provide rate limiting on a time interval basis with an initial and total capacity (for requests) of 1.

If the solution is agreeable, it's also possible to easily extend this and allow the user more advanced rate limiting with command line arguments for initial and total request capacity which would equate to how many requests a host starts with up front, how many requests can be accumulated in the bucket, etc.

For now, I left the implementation static at an initial and total capacity of 1.

I also changed Block() to defer r.Unlock() instead of having multiple called to unlock the map. While defer is currently slow, that shouldn't be a limiting factor in Block() as the code will probably be limited by network latency.

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