Skip to content

feat: resty.limit.count support new shared dict incr function #67

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

Merged
merged 2 commits into from
Nov 4, 2021

Conversation

windmgc
Copy link
Contributor

@windmgc windmgc commented Nov 3, 2021

Hi,
The aim of this pr is to make resty.limit.count's incoming function using the latest type of shared dict's incr function, which supports setting expire time when increasing an unexisting key, and it is also compatible with the old version of OpenResty, just as mentioned in #34 (comment).

I'm doing some pressure tests recently to test the stability of lua-resty-limit-traffic module and found some problems under high volume(possibly due to the concurrent situation and two separate atomic operation(incr and expire) calls in incoming, see #23 (comment) and #47 (comment)). However, I found that when I'm using the latest incr function which supports expire time(which makes the two operation combines into an atomic one(done within the same lock, see https://github.com/openresty/lua-nginx-module/blob/3f33dd862a3d8539b96dda09b624c89712cbe0c8/src/ngx_http_lua_shdict.c#L1889), the problem hardly occurs. So I think it is perhaps a good idea to use incr with expire time arg instead of separate them into two operations.

@@ -80,6 +111,14 @@ function _M.incoming(self, key, commit)
return 0, remaining
end

function _M.incoming(self, key, commit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way should be better:

local function incoming_new
local function incoming_old
_M.incomming = incr_support_init_ttl and incoming_new or incoming_old

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doujiang24 fixed, please review again, thanks

@zhuizhuhaomeng zhuizhuhaomeng merged commit ef2b739 into openresty:master Nov 4, 2021
monkeyDluffy6017 pushed a commit to monkeyDluffy6017/lua-resty-limit-traffic that referenced this pull request Apr 19, 2023
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.

3 participants