天天看點

python close_wait_redis 産生大量 CLOSE_WAIT?

Python 操作 redis 時,由于 redis 執行個體線程安全,是以我使用了兩種方式:

(1).直接做全局變量,如下:

R = redis.Redis()

# 導入到多個需要使用 redis 的子產品中,直接使用,如:

R.get('name')

(2).連接配接池,如下:

class mRedis(object):

def __init__(self, db=0):

self.db = db

self.redis_pool = redis.ConnectionPool(host=settings.redis_svr_addr,

port=settings.redis_svr_addr_port,

db=self.db,

password=settings.redis_svr_pass)

def getR(self):

return redis.Redis(connection_pool=self.redis_pool)

# 執行個體化直接使用

myredis = mRedis(db=0).getR()

但是在使用過程中,産生了大量 CLOSE_WAIT.,一大螢幕,如下:

tcp 1 0 127.0.0.1:62286 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15153 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:14972 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15134 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15030 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:62486 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15097 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:4912 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:14517 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15155 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:59812 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15031 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15121 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:14812 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:59806 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:14813 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:14928 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:63476 127.0.0.1:6379 CLOSE_WAIT

tcp 1 0 127.0.0.1:15048 127.0.0.1:6379 CLOSE_WAIT

其中 redis.conf 設定 timeout 200

而且時常會出現 redis 連接配接逾時的問題,導緻 tornado 一直阻塞請求,看了下帶寬,負載,CPU,記憶體都比較正常,暫時找不到原因,不知道是 redis 使用方面出了什麼問題?求指點!!:-D