A platform for community discussion. Free, open, simple.
PERF: Add exponential backoff for DistributedMutex (#17886)
David Taylor2422ca0e6740
diff --git a/lib/distributed_mutex.rb b/lib/distributed_mutex.rbindex b724948d231..bc29d149512 100644--- a/lib/distributed_mutex.rb+++ b/lib/distributed_mutex.rb@@ -4,7 +4,7 @@# Expiration happens when the current time is greater than the expire timeclass DistributedMutexDEFAULT_VALIDITY = 60- CHECK_READONLY_ATTEMPTS = 10+ CHECK_READONLY_ATTEMPTS = 5LOCK_SCRIPT = DiscourseRedis::EvalHelper.new <<~LUAlocal now = redis.call("time")[1]@@ -85,7 +85,9 @@ class DistributedMutexreturn expire_time if expire_time- sleep 0.001+ # Exponential backoff, max duration 1s+ interval = attempts < 10 ? (0.001 * 2**attempts) : 1+ sleep interval# in readonly we will never be able to get a lockif @using_global_redis && Discourse.recently_readonly?