If a lock was not obtained in the lock function, is it desired behavior to sleep (in line 80), even after the last retry?
I think that the last retry's sleep will be a waste of time, if the lock was not obtained.
|
def lock(resource,ttl) |
|
val = get_unique_lock_id |
|
@retry_count.times { |
|
# Wait a random delay before to retry |
|
sleep(rand(@retry_delay).to_f/1000) |
|
} |
If my argument holds, how about:
for i in 0..(retry_count-1)
# The major part of the lock function goes here.
# Don't sleep if it's the last retry.
if (i != retry_count-1)
# Wait a random part of retry_delay, before retrying.
sleep(rand(@retry_delay).to_f/1000)
end
end
If a lock was not obtained in the lock function, is it desired behavior to sleep (in line 80), even after the last retry?
I think that the last retry's sleep will be a waste of time, if the lock was not obtained.
redlock-rb/redlock.rb
Lines 55 to 57 in 97be08b
redlock-rb/redlock.rb
Lines 79 to 81 in 97be08b
If my argument holds, how about: