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

About limit reset-expire?

Open lebanggit opened this issue 7 years ago • 5 comments

With this config

local lim, err = limit_conn.new("my_limit_conn_store", 10, 5, 0.5)

After somes request. I alway get 503. I want limit per IP request not over 15 concurrent connections

lebanggit avatar May 30 '17 10:05 lebanggit

@lebanggit I don't think I understand your question.

agentzh avatar May 30 '17 18:05 agentzh

I having to config a streaming server on openresty. It's work fine. But with download manager is caused overload. I want to limit concurrent connection on per IP.

location /
	{
		access_by_lua_block
		{
			ngx.log(ngx.INFO, "log for: ", ngx.var.remote_addr)
			local limit_conn = require "resty.limit.conn"
			local lim, err = limit_conn.new("my_limit_conn_store", 10, 5, 0.5)
			if not lim then
				ngx.log(ngx.ERR, "failed to instantiate a resty.limit.conn object: ", err)
				return ngx.exit(500)
			end
			
			local key = ngx.var.binary_remote_addr
			local delay, err = lim:incoming(key, true)
			if not delay then
				ngx.log(ngx.ERR, "failed to limit req: ", err)
				if err == "rejected" then
					return ngx.exit(503)
				end
				return ngx.exit(500)
			end
			
			if lim:is_committed() then
				local ctx = ngx.ctx
				ctx.limit_conn = lim
				ctx.limit_conn_key = key
				ctx.limit_conn_delay = delay
			end
			
			local conn = err

			if delay >= 0.001 then
				-- the request exceeding the 200 connections ratio but below
				-- 300 connections, so
				-- we intentionally delay it here a bit to conform to the
				-- 200 connection limit.
				ngx.log(ngx.WARN, "delaying")
				ngx.sleep(delay)
			end
		}
	}

Max 10 concurrent connections and Burst 5.

When i testing with some request (on browser and download via IDM). It's seems limited and get 503. After 24 hours still get 503.

I don't understand. How it works.

lebanggit avatar May 31 '17 10:05 lebanggit

@lebanggit
Have you ever called lim:leaving in log_by_lua phase ?

you could refer the example in README.md , it shows how to do this.

fankeke avatar May 31 '17 12:05 fankeke

@fankeke: Yes, I have....

For testing i set: local lim, err = limit_conn.new("my_limit_conn_store", 2, 1, 0.5)

And i have open one tab on browser and concurrent downloading with IDM.

OK, total 03 connection limited.

But on browser loaded about 30% file, IDM loaded 45%..... it's error.

I have close the tab on browser and close IDM and re-access on browser. It still get 503.

I guess... lim:leaving working not exactly or leave out.

lebanggit avatar May 31 '17 15:05 lebanggit

限制后,多少时间可以解禁(After the restriction, how long can the ban be lifted?)@agentzh

zhaodaiyang0574 avatar Jan 29 '19 08:01 zhaodaiyang0574