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.
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()
todefer r.Unlock()
instead of having multiple called to unlock the map. Whiledefer
is currently slow, that shouldn't be a limiting factor inBlock()
as the code will probably be limited by network latency.