openresty / lua-resty-limit-traffic

Lua library for limiting and controlling traffic in OpenResty/ngx_lua
819 stars 150 forks source link

req limit #38

Open shokin opened 6 years ago

shokin commented 6 years ago

Hello @agentzh , here use your traffice function. If elapsed is 0 in the following statement, excess will return a number greater than 0 whether or not it exceeds concurrency, so burst stage will be carried out?

code:

local elapsed = now - tonumber(rec.last)
        print(elapsed, ":ms", now, "-", tonumber(rec.last))

        excess = max(tonumber(rec.excess) - rate * abs(elapsed) / 1000 + 1000,

log: req.lua:89: incoming(): 0:ms1536289344390-1536289344390,

shokin commented 6 years ago

?

coding-brigadier commented 6 years ago

I think there is also a policy that the questions have to be in English on github. Please translate and either @agentzh or anyone else might be able to help.

NagamineLee commented 6 years ago

@Willux at my point of view, the problem description is : rate=5000r/s means 5r/ms, but in resty.limit.req, time granularity is also ms level

two requests might arrive at the same time, which cause local elapsed = now - tonumber(rec.last) = 0

then excess = max(tonumber(rec.excess) - rate * abs(elapsed) / 1000 + 1000 calculation result always exceees burst=0

so the actual request processing rate might be closer to 1r/ms not match 5r/s

shokin commented 5 years ago

thanks @NagamineLee @Willux for help