ledgetech / lua-resty-redis-connector

Connection utilities for lua-resty-redis
234 stars 71 forks source link

ERR max number of clients reached #25

Closed zhenzhenyang closed 5 years ago

zhenzhenyang commented 5 years ago

local args = ngx.req.get_uri_args(); local tvid = args["tvid"] local page = args["page"] local message = "success" local code = "A000000" local time_now = ngx.time() local timestamp = os.date("%Y%m%d%H%M%S",time_now) local resp={} resp["timestamp"]= timestamp

local rc = require("resty.redis.connector").new({ connect_timeout = 5000, read_timeout = 5000, keepalive_timeout = 30000, keepalive_poolsize = 3000; })

local sentinel_name = config.sentinel_name local sentinel_passwd = config.sentinel_passwd local hash_db_index = config.hash_db_index local sentinel_nodes = config.sentinel_nodes local sentinel_url = "sentinel://"..sentinel_passwd.."@"..sentinel_name..":m/"..tostring(hash_db_index) local redis, err = rc:connect{ url = sentinel_url, sentinels = sentinel_nodes }

if err then ngx.log(ngx.ERR,"connect redis sentinel failed,reason:",err) message="failed" code = "A000001" resp["message"] = message resp["code"] = code resp["data"] = {} ngx.print(cjson.encode(resp)) return 500 end

local hkey = tvid..""..page local results, err = redis:hgetall(h_key)

if err or #results<=0 then message="failed" code = "A000001" resp["message"] = message resp["code"] = code resp["data"] = {} ngx.print(cjson.encode(resp)) ngx.log(ngx.ERR,"hgetall:",err) else resp["message"] = message resp["code"] = code local array={} for i, res in ipairs(results) do if i%2==0 then print(i) k = results[i-1] v = results[i] array[k]=v end end resp["data"] = array --print(cjson.encode(resp)) ngx.print(cjson.encode(resp)) end --[[ local ok, err = redis:set_keepalive(10000,1000) if not ok then ngx.log(ngx.ERR,"failed to set_keepalive: ", err) --return 200 end ]] local ok, err = rc:set_keepalive(redis) if not ok then ngx.log(ngx.ERR,"failed to set_keepalive: ", err) return 200 end

hi,i use ab command press the sentinel ,and the total connections is 50k,concurrent connections is 10k,nginx log appear error " ERR max number of clients reached ",and the error's count is very much.

hamishforbes commented 5 years ago

You're making 10k concurrent connections to Redis, this is likely more than the open file limit for Redis. Not a problem with this lib, it's a configuration issue in Redis.