We actually use memcached as a lock server for certain very rare,
per-user transactions.  It's less than ideal, but we scrambled to
write it in a pinch when our previous solution had problems and it's
held up thus far.  It's something we've had on the "fix when we have
time" list since, but it does indeed work.

I still wouldn't recommend it, though.  What kind of scale are you
looking for?  Have you considered something like zookeeper, for
example?

On Wed, Apr 8, 2009 at 10:07 AM, Clint Webb <[email protected]> wrote:
> Its possible... but really... its a cache.  Thats what it is designed to do,
> and that is what it is good for.  memcached is not optimized at all to be a
> lock server, why exactly are you wanting to use memcached for this instead
> of an actual lock server?
>
> That being said, there are a number of issues when using memcached as a lock
> server that would make it far less than ideal.
>
> Also a default unlock after 5 minutes rather defeats the purpose of a lock
> server...   I wouldn't recommend this at all.  Far better off with an actual
> lock server that can defect if a client has disconnected.
>
> Short answer:  No, do not use memcached as a lock server.
>
> On Wed, Apr 8, 2009 at 9:44 PM, yatagarasu <[email protected]> wrote:
>>
>> Is it possible to implement distributed resource blocking using
>> memcached ?
>>
>> Is it possible to implement them using following scheme (pseudocode)
>>
>> lock(a)
>> 1. if (add( key=>a, expiration=>5min )) {
>> 2.   if (cas( key=>a, expiration=>5min )) {
>>            // resource locked by us
>>      }
>>      // Someone tried to lock resource the same time. Race condition
>> in add.
>>   }
>>   // resource is already locked
>>
>> unlock(a)
>> 1. delete(a)
>>
>> What do you think?
>> Is race condition in add possible?
>> Will such double check work?
>> Or is there more simple way?
>>
>>
>> PS. Expiration in 5min is used to auto unlock resource in case of
>> client disconnection or other errors.
>
>
> --
> "Be excellent to each other"
>



-- 
awl

Reply via email to