Adding support for an Allow
method
#102
Replies: 10 comments
-
Great idea |
Beta Was this translation helpful? Give feedback.
-
The feature on its own sounds reasonable, however but before any PRs we should discuss what exactly
Most important, have you considered just using https://pkg.go.dev/golang.org/x/time/rate#Limiter.Allow? This sounds like exactly what you need, and I don't see value in copying the the same functionality/API here. |
Beta Was this translation helpful? Give feedback.
-
In regards to how the function would work, I envisaged it peeking the limit, and providing both a count and time as paramters would be ideal. It shouldn't affect the functionality of take, and both should be able to work in harmony. I have looked into using the Allow method from If you think that implementing this functionality here wouldn't be worthwhile/it would be more suitable to request an implementation of |
Beta Was this translation helpful? Give feedback.
-
Hm, I'm now not sure if I understand
If I read this correctly, you could provide a very small float (0.016), that would effectively be the same as our |
Beta Was this translation helpful? Give feedback.
-
Perhaps it's our documentation that's unclear - if you do |
Beta Was this translation helpful? Give feedback.
-
Ah I see, I was under the impression that your package differed from |
Beta Was this translation helpful? Give feedback.
-
Out of curiosity, what's the functionality you're looking for? |
Beta Was this translation helpful? Give feedback.
-
A token bucket system where the refill rate can be entirely customised - for example you could create a new limiter with The initial requirement came from limiting an endpoint to 5 requests every 5 minutes, which doesn't seem possible with any current offering because this duration is simplified into '1 per minute up to a maximum of 5'. |
Beta Was this translation helpful? Give feedback.
-
Yeah, but could you bubble up a bit on the stack? What use-case requires this kind of rate-limiting?
So that's not entirely precise. With |
Beta Was this translation helpful? Give feedback.
-
The requirement came from the desire to limit file uploads to a strict limit per 5-minute period. With slack/burst they'd be able to upload 5 files immediately, followed by another 5 across the next 5 minute period (because the bucket would refill at a rate of 1 per minute), which was not ideal. As it seems most packages act like this, I'll probably end up just using this functionality. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
-
This package initially seemed ideal for my use case - It supports refilling at a certain rate (so limits such as 10 per 2 minutes are possible) however only exposing
Take
means that it can't be used in a context where you want to return a429 HTTP
response (this would block the response which is not the behaviour I'm looking for).I have seen mentioned on other issues that no other features are planned, but I wanted to ask - if I made a pull request which supported an
Allow
method which simply returns whether a call toTake
would block or not, would a merge be considered for this?Beta Was this translation helpful? Give feedback.
All reactions