lua-resty-limit-traffic icon indicating copy to clipboard operation
lua-resty-limit-traffic copied to clipboard

req limit

Open shokin opened this issue 5 years ago • 4 comments

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 avatar Sep 07 '18 03:09 shokin

?

shokin avatar Sep 13 '18 05:09 shokin

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.

coding-brigadier avatar Sep 28 '18 21:09 coding-brigadier

@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

NagamineLee avatar Oct 26 '18 02:10 NagamineLee

thanks @NagamineLee @Willux for help

shokin avatar Nov 23 '18 01:11 shokin