Closed themez closed 7 years ago
Hi @themez, thanks for your contribution. Could you describe a use case for this? How would you expect this to work in an application with a cluster of servers?
Hi @clarkie , in my case I often need to query large dataset, think of a feed pusher, say I have several workers concurrently pushing feed item to channel subscribers, they continually query channel subscribers which might be very many,I need to limit workers' total throughput usage.
Normally we use token bucket for rate limiting, but as the consumption of a request is not known util it is finished, it's hard to prevent workers start querying when token is not enough. At first I just add an ability for limiting a single load-all query's request rate, use a simple external rate limiter. You can check the commit history.
But it's not enough in my use case. Then I write my own rate-limiter and add a "pre-auth" mode, a query must do "pre-auth" before sending request, and clear transaction with real consumed amount, just like Pre-Authorization for credit card.
I'm still working on it, it will be appreciated if you can give some suggestions.
I thought again, it may not be good to put such a feature in this library, it could be done in upper level applications.
Use a token bucket to prevent consuming too much capability of throughput. Example: