views:

1601

answers:

5

Which distributed lock service would you use?

Requirements are:

  1. A mutual exclusion (lock) that can be seen from different processes/machines
  2. lock...release semantics
  3. Automatic lock release after a certain timeout - if lock holder dies, it will automatically be freed after X seconds
  4. Java implementation
  5. Nice to have: .Net implementation
  6. If it's free: Deadlock detection / mitigation
  7. Easy deployment, see note below.

I'm not interested in answers like "it can be done over a database", or "it can be done over JavaSpaces" - I know. I'm interested in a ready, out-of-the-box, proven implementation.

+6  A: 

Teracotta, including the Open Source edition, has distributed locking semantics by using either synchronized or the java.util.concurrent.ReentrantReadWriteLock - the latter apparently fitting your requirements.


Update

Since the question now added the requirement of 'mixing' with GigaSpaces, I'm going to say don't mix them. It's just going to add more complexity to your technological stack, and the effort of:

  • integrating, in terms of both code and infrastructure;
  • managing synchronisation between them;
  • learning/tuning/debugging Teracotta.

will be better spent creating or implementing a locking solution based on GigaSpaces.

Robert Munteanu
Assuming we're already using GigaSpaces, would you add Terracotta to the mix? Do the two play well together?
ripper234
That's the direction I'm going to at the moment. Will publish it when it's ready.
ripper234
+3  A: 

A newer kid on the block is hazelcast. I've been playing with it and it is amazingly simple to use and configure.

As far as I can see there shouldn't be any conflict between Gigaspaces and hazelcast as hazelcast doesn't have any dependencies i.e. no jgroups.jar etc

Hazelcast:

  1. A mutual exclusion (lock), yep implementation of java.util.concurrency.locks.Lock
  2. Automatic lock release after a certain timeout, yep all locks are released if a member leaves the cluster
  3. Java implementation, yep
  4. Nice to have: .Net implementation, nope is a pure java solution, might be possible to port to j#
  5. If it's free: Deadlock detection / mitigation, nope no effort is made my Hazelcast to handle this
  6. Easy deployment, it's a single jar with a single config file, deployed as part of your application, no additional processes are required
Gareth Davis
Any deployment effort?I'll refine my question - solutions that do not need further deployment and can use either MySql, JavaSpaces/GigaSpaces or NetApp are (highly) preferable.
ripper234
I haven't actually deployed Hazelcast yet, but I'm actively looking at using it for distributed locking. Deployment seems to be almost trival as there is no external process, all the JVM's in the cluster just kinda work out what todo
Gareth Davis
Seems suspicious. They at least need to know about one another's existence somehow...Anyway, I prefer (and insist on) a solution based on existing technologies we're employing - I don't think it's wise introducing yet another clustering framework when we already work with GigaSpaces.Is it possible that no MySql-based solution exists???
ripper234
Yes, hazelcast uses mutlicast to auto discover it's members, hardwiring the cluster is also possible if mutlicast isn't suitable. If you want to lock stuff using MySql that is really easy isn't it? just do 'SELECT ID FROM LOCK_TABLE WHERE ID = `sharedname` FOR UPDATE'
Gareth Davis
+3  A: 

Check out Apache's Zookeeper (A Hadoop sub-project) - it offers distributed synchronization. The documentation isn't great, but what there is makes it look an interesting product - checkout the recipes for ideas on how to use Zookeeper.

It is lower-level than you'd probably want and it does require additional deployment as it recommends dedicated servers.

You can model different locking strategies and it does offer a solution for a lock holder dying (ephemeral nodes).

+1  A: 

The question I really wanted to ask for what lock service that uses either GigaSpaces, Netapp or MySql should I use. I ended up writing one, so here it is.

ripper234
+1  A: 

We are developing a open source distributed synchronization framework. Currently we have finished development of distributed version of ReentrantLock and ReentrantReadWriteLock. It is very simple to use just add the library in classpath and you are ready to go.

we are using jgroups as group communication framework.

Check out the details at http://code.google.com/p/vitrit/.

Kamran

Kamran