我希望memcached的连接池类似数据库连接池一样 ,保持固定数量的长连接
完全拷贝了网站上面的例子,
content_by_lua '
local memcached = require "resty.memcached"
local memc, err = memcached:new()
if not memc then
ngx.say("failed to instantiate memc: ", err)
return
end
memc:set_timeout(1000) -- 1 sec
-- or connect to a unix domain socket file listened
-- by a memcached server:
-- local ok, err = memc:connect("unix:/path/to/memc.sock")
local ok, err = memc:connect("127.0.0.1", 11211)
if not ok then
ngx.say("failed to connect: ", err)
return
end
-- put it into the connection pool of size 100,
-- with 0 idle timeout
memc:set_keepalive(0, 100)
但是在使用过程中,设置了
keepalive=100,但是在进行压力测试的过程中,memcached连接数还是猛增,不确定是我对该keepalive的理解不正确,还是用法不正确,请指点。
[root@thx logs]# netstat -pnt|grep 12101|wc
603 4221 65727
tcp 0 0 192.168.4.26:54142 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:53825 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:53904 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:53898 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:54457 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:54700 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:54120 192.168.52.79:12101 TIME_WAIT -
tcp 0 0 192.168.4.26:54151 192.168.52.79:12101 TIME_WAIT -