Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of redis connection in time wait. #116

Open
ikouchiha47 opened this issue Apr 17, 2017 · 1 comment
Open

Lots of redis connection in time wait. #116

ikouchiha47 opened this issue Apr 17, 2017 · 1 comment

Comments

@ikouchiha47
Copy link

Hi,
I have a code like this:

function _M.get_redis(config, host, port)
  local red = redis:new()
  red:set_keepalive(config.redis_keepalive_in_milliseconds, config.redis_pool_size)

  logger.debug("GoJek-Auth", "Trying to conntect to Redis")
  local ok, _, err = pcall(red.connect, red, host, port)

  if not ok or err ~= nil then
    ngx.log(ngx.ERR, err)
    return nil, errors.ERR_REDIS_CONNECTION
  else
    return red, nil
  end
end

-- another file
-- codes
--
--
local red, err = utils.get_redis(config, config.customer_token_redis_host, config.customer_token_redis_port)
  if err then
    logger.error("Auth", "could not connect to redis.")
    _M.authServiceResponse(config, token)
   red:close()
  end

where pool size is 50 and timeout is 20k ms. But when I do this.. netstat -an | grep TIME_WAIT | grep 6379 | wc -l it yields 28k , and I get a lot of cannot assign address..

I have also enabled tcp_tw_reuse and tcp_tw_recycle .. Why is this happening ? Does red:close() return the connection to the pool ?

@bjoe2k4
Copy link
Contributor

bjoe2k4 commented Apr 17, 2017

Please read the documentation more carefully. set_keepalive returns the connection to the pool, while close actually closes the connection. set_keepalive is usually called AFTER you have executed your redis queries. Also why do you connect using pcall?

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

No branches or pull requests

2 participants