A distributed lock system using websocket and Redis
Java Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


POC Distributed lock

This is a POC to have distributed lock system.

  1. The client (a javascript application running in a browser) open a session, all the locks will be associated with this session.

  2. The client ask for a lock, if available the server return a LOCKED message. If the lock is already taken the server return a WAIT message. The call is not blocking.

  3. When the lock is released the server send a RETRY message with the lockname to all the clients that were waiting for it. They can ask again for the lock.

  4. The client can close the session, releasing all its locks.

There is also a mlock and munlock operations to ask for multiple locks in an atomic way.

The system use websocket between browser and the server, the bi-directional channel stay open during the session.

The system support multiple servers.

The websocket is hanlded by Atmosphere and persistence and communication between servers using Redis.

Lock sequence

The lock sequence

Websocket protocol

Request and response are JSON encoded:

  • Request:

      {'action': String, 'params': String[], 'time': stamp}
  • Response:

      {'status': String, 'message': String, 'time': stamp}

Implemented action:

  • connect sessionName
  • close
  • lock [lockname]
  • unlock lockname
  • mlock [lockname...]
  • munlock [lockname...]


  • FAIL
  • WAIT
  • RETRY lockname


  1. Get the latest tomcat 7.

  2. Build:

      mvn clean package
  3. Deploy:

      cp ./target/distlock.war $TOMCAT/webapps/ && $TOMCAT/bin/startup.sh
  4. Test using http://localhost:8080/distlock/

Load testing

This requires to install:

Test with 10 clients:

    cd ftest/funkload && fl-run-bench test_Distlock.py Distlock.test_distlock -c 10


About Nuxeo

Nuxeo provides a modular, extensible Java-based open source software platform for enterprise content management and packaged applications for document management, digital asset management and case management. Designed by developers for developers, the Nuxeo platform offers a modern architecture, a powerful plug-in model and extensive packaging capabilities for building content applications.

More information on: http://www.nuxeo.com/