ok, let me more clarify this topic since I got one more email about not using memcache for locking.

First of all, I know memcached is not reliable by design but if you visit http://en.wikipedia.org/wiki/Memcached you will see that I'm not the only/first person to try this.( there is a link to IPC::Lock::Memcached - fast locking via memcached).

For more information about my software, the locking mechanism is also backed up by a MVCC implementation in db layer. In other words, I already have a backup mechanism if memcached fails not to loose data integrity, but the cost of rolling back a bunch of transactions is not small, so I dont want to see MVCC exceptions hanging around.

In addition, I need to guarantee that at least one memcached server is alive not to freeze my system.(e.g. if nobody can obtain lock, nobody can take an action).

Now comes the case of saving locks when a server fails. In that case, we may loose ~ 10K locks which will cause ~ 7K operation rollbacks. What I think is, with a memcache master slave implementation, this number can be decreased to a ommittable number. Of course there is another solution to this problem, basically depending on db layer MVCC implementation if memcache fails, but this will be a highly coupling between these two, which wont be preferable by design.


Anyway, to clarify, any master-slave like replication of memcached may be helpful for my case.

Henrik Schröder wrote:
The best practice is to not use memached at all for this. It is a cache, if you store something in it, you are in no way guaranteed that it will be there the next time you ask for it. It is temporary, not permanent, and as such an extremely bad match for a distributed lock where it is absolutely critical that you do not lose data.


/Henrik

On Thu, Mar 12, 2009 at 19:30, Yigit Boyar <[email protected] <mailto:[email protected]>> wrote:


    hi all,

    I'm developing a software where memcached is also used as locking
    server.

    The problem is that, i wanna make this fail safe; which basically
    means if the memcached server goes down, another one starts and
    the locks are transformed. This basically handled by keeping two
    instances up, one as master and if the master dies, slave becomes
    master and an new slave comes live.

    This is my guess, but I'm looking for some good best practices not
    to invent wheel from scratch.

    So is there any link you can provide where a best practice for
    memcached based locking is present ?

    btw. i'm using php in a distributed environment.

    thnks.



Reply via email to