NHibernate.Caches.Redis icon indicating copy to clipboard operation
NHibernate.Caches.Redis copied to clipboard

LockTimeout value

Open craigvn opened this issue 8 years ago • 1 comments

I notice the default LockTimeout value is 30 seconds. Is this the time it will attempt to retrieve a value from Redis before failing? Most of my requests take less than 25ms so would it be safe to make this something like 1 or 2 seconds? The reason being that I am using Redis on Azure and it periodically has connection issues which I would prefer to fail quickly on rather than wait.

craigvn avatar May 24 '16 03:05 craigvn

The LockTimeout is how long NHibernate should hold onto the lock. By default, it's a large number of seconds to account for any problems. It's the upper bound of your transaction duration. It's definitely safe to make it 1-2 seconds. However, you need to ensure everything else occurs within the lock timeout as well (e.g. what's your DB timeout?). A possible worst case scenario is:

  1. A lock is taken.
  2. Some sort stall during your request causing the lock to timeout (e.g. DB connection, network latency etc)
  3. A concurrent transaction takes a lock (because the other lock timed out).
  4. The original transaction tries to free the lock, but it doesn't own it anymore (thus triggering the RedisCacheProviderOptions.OnUnlockFailed... which may throw an exception depending on how you have it configured).

The default is very high to simply account for these scenarios, but it could be any value depending on your application's requirements.

TheCloudlessSky avatar May 24 '16 12:05 TheCloudlessSky