lock.py: Add random delay between lock retries.

This should reduce memcached spam and burst requests when locks are highly contended.
This commit is contained in:
Robert Ditthardt
2014-12-08 10:57:00 -08:00
parent aacdded178
commit aaa399bd96

View File

@@ -27,6 +27,7 @@ from threading import local
from pylons import g
import os
import socket
import random
from r2.lib.utils import simple_traceback
@@ -91,7 +92,8 @@ class MemcacheLock(object):
msg = "Timed out waiting for %s" % self.key
raise TimeoutExpired(msg)
sleep(.01)
#this should prevent unnecessary spam on highly contended locks.
sleep(random.uniform(0.1, 1))
timer.stop(subname=self.group)