bbangert / retools

Redis Tools
MIT License
138 stars 41 forks source link

distributed lock: faster retry sleep with exponential backoff #24

Closed gjcarneiro closed 9 years ago

gjcarneiro commented 10 years ago

The distributed lock code handles contention by sleeping for 1 second and trying again. There is a time.sleep(1) call.

This value seems a bit excessive in my scenario and I would rather have it as 0.1. Maybe we can make this parameter configurable?

gjcarneiro commented 10 years ago

Related to this, in the original "redis-exp-lock-js" project, they have this setting:

retryTimeout

The amount of time the lock function will wait before attempting to re-acquire the lock. Defaults to five milliseconds.

So, in the JS code they sleep for 0.005 seconds in case of contention, while this module sleeps for whole second!

bbangert commented 10 years ago

I'd be open to a pull request that implements an exponential backoff on the retries with a max sleep period. The Kazoo code has a RetryHelper that does something similar.

gjcarneiro commented 10 years ago

Ping.