mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user