-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lock command performs very differently with one/multiple max lock holders #1006
Comments
Bonus cowsay demo: https://dl.dropboxusercontent.com/u/4153969/consul-lock-cowsay.mp4 |
This is actually expected - a semaphore uses the KV store's long polling to determine when it needs to try to acquire the lock after release, but the lock code uses a timer. By default, each contender for a lock will wait 5 seconds after attempting to acquire a lock and failing to retry due to DefaultLockRetryTime in Now that I read through the code again, the comment up top says it all: The However, no effort is made to distinguish between a lock acquisition failure due to a session already locking the key, and a lock delay (both return a |
Thanks for the info! My concern is that it doesn't seem possible to have "one and only one" of something running without up to 5 seconds of downtime if the command fails. |
So @highlyunavailable hit this exactly dead on. The semaphore implementation does not have the lock-delay while the lock does (by design). The simplest approach was to just wait 5 seconds but I agree this is a bit heavy handed. |
When running multiple
consul lock
commands at the same time with a command that completes almost instantly, there can be up to a 5 second delay until the next client obtains the lock (except the 2nd one, which appears to always happen immediately after the first). It takes ~30 seconds to rundate
8 times.consul lock test date
With a 1 second sleep added, it takes ~17 seconds to run the command 8 times:
consul lock test 'sleep 1 && date'
If the command take ~5 seconds instead of finishing instantly, the lock appears to transfer instantly as expected.
consul lock test 'sleep 5 && date'
However, when running with
-n 2
, the next client obtains the lock as soon as another command finishes, with no delays.consul lock -n 2 test date
I'm assuming it's related to the algorithm differences mentioned in https://www.consul.io/docs/commands/lock.html:
Is this behavior intentional/expected?
The text was updated successfully, but these errors were encountered: