openresty / openresty/lua-resty-memcached

idle connections to memcached

Open
#47 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
216
Forks
62
Avg merge
1h 20m
Merged PRs (30d)
2

Description

Hi,
I have the following code executed on each request:

    access_by_lua_block {
      local memcached = require "resty.memcached"
      local memc = memcached:new()
      memc:set_timeout(3000) -- 3 sec
      local ok = memc:connect("127.0.0.1", 11211)
      local myvar = memc:get(othervar)
      ### do something
      local ok, err = memc:close()
    }

put operation is happening in other internal location in case proxy origin receives 302 redirect

    access_by_lua_block {
      local memcached = require "resty.memcached"
      local memc = memcached:new()
      memc:set_timeout(1000) -- 1 sec
      local ok = memc:connect("127.0.0.1", 11211)
      ### do something
      local ok, err = memc:set(stringone, stringtwo, 604800)
      local ok, err = memc:close()
    }

Recently I noticed that connections are not really closed but stay idle for some time. And it's count is pretty high.
I have memcached running in docker contrainer like this

memcached -c 10000 -t 8

nginx itself handles 4k rps nonstop

And netstat shows this

netstat -an | grep 11211 
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:62334         127.0.0.1:11211         TIME_WAIT  
tcp        0      0 127.0.0.1:59430         127.0.0.1:11211         TIME_WAIT  
tcp        0      0 127.0.0.1:61444         127.0.0.1:11211         TIME_WAIT  
tcp        0      0 172.17.0.1:11638        172.17.0.2:11211        TIME_WAIT  
tcp        0      0 127.0.0.1:45352         127.0.0.1:11211         TIME_WAIT  
tcp        0      0 127.0.0.1:62010         127.0.0.1:11211         TIME_WAIT  
tcp        0      0 127.0.0.1:56390         127.0.0.1:11211         TIME_WAIT  
tcp        0      0 172.17.0.1:31884        172.17.0.2:11211        TIME_WAIT  
tcp        0      0 172.17.0.1:64364        172.17.0.2:11211        TIME_WAIT  
...

netstat -an | grep -c 11211 
31836

lua module version is 0.16

Please help me solve this issue, thank you in advance.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the access_by_lua_block examples and the reported netstat output, then inspect how lua-resty-memcached 0.16 handles connect, get, set, and close. Reproduce the request pattern and determine whether the TIME_WAIT connections indicate a client problem; document the cause or define the needed behavior once confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, memcached
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.