Skip to content

Commit 0d5281e

Browse files
committed
share deaduntils between hosts
This will help avoid many socket timeout especially when we use python-memcached with eventlet. For example,When use eventlet,for each greenlet we call client.get first time,the client will be rebuild,and client.servers[*].deaduntil will be 0.For each http request,we will have one greenlet.So we get a socket timeout for each request. This could be fixed in application,but i believe it's better to fix it in python-memcached.
1 parent b13d6fc commit 0d5281e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

memcache.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,9 @@ def check_key(self, key, key_extra_len=0):
13301330
"Control/space characters not allowed (key=%r)" % key)
13311331

13321332

1333+
_host_last_deaduntils = {}
1334+
1335+
13331336
class _Host(object):
13341337

13351338
def __init__(self, host, debug=0, dead_retry=_DEAD_RETRY,
@@ -1371,7 +1374,7 @@ def __init__(self, host, debug=0, dead_retry=_DEAD_RETRY,
13711374
self.port = int(hostData.get('port') or 11211)
13721375
self.address = (self.ip, self.port)
13731376

1374-
self.deaduntil = 0
1377+
self.deaduntil = _host_last_deaduntils.get(self.ip, 0)
13751378
self.socket = None
13761379
self.flush_on_next_connect = 0
13771380

@@ -1411,6 +1414,7 @@ def _get_socket(self):
14111414
s.connect(self.address)
14121415
except socket.timeout as msg:
14131416
self.mark_dead("connect: %s" % msg)
1417+
_host_last_deaduntils[self.ip] = self.deaduntil
14141418
return None
14151419
except socket.error as msg:
14161420
if isinstance(msg, tuple):

0 commit comments

Comments
 (0)