Skip to content

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.

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