feature: new module resty.limit.token - #26
Conversation
|
@timebug Thanks for your contribution. Some thoughts though:
|
|
@agentzh Thanks for the feedback! What do you think of I surveyed some similar libraries, like ratelimit for golang, node-rate-limiter for node.js and ratelimit for rust, they all use token-bucket as the limit algorithm. And I think the word No problem, I will add to the docs some explanation on how this module is different from the existing modules later today. Thanks for your advice. I'm sorry I didn't consider it when I submitted the Pull Request, I looked at the implementation of the function _M.incoming(self, key, commit)
return _M.take(self, key, 1, self.max_wait, commit) -- max_wait may need to configure before this
end
function _M.take(self, key, count, max_wait, commit, fake_now)
-- something else
if is_num(max_wait) and wait_time > max_wait then
if commit then
update(self, key, avail, last)
end
return nil, "rejected"
end
return wait_time / 1000
endImplement |
|
@timebug Seems good to me though I'll have to have a closer look at the code and the docs to be sure :) |
|
@agentzh I created a new PR #27 use a new name called
|
Just like
resty.limit.req, but this module limit request rate using the "token bucket" method.Interface design reference: https://github.com/juju/ratelimit
This module has been used in our internal production environment for limit request, avoiding the large number of requests from individual users affects the global system, like this:
@agentzh are you interested in this feature? or any other suggestions? thanks.