• Sales: (866) 518-YARD

Distlockrun: Lockrun for Your Cloud

By Sam Merritt | October 30th, 2009 at 11:10AM

Lockrun is a handy little utility for ensuring you don’t run two of the same cron job (or other task) at the same time on one machine. It’s especially handy when the cron job in question has a widely varying duration. Lockrun was written by Steve Friedl and initially released in 2006.

However, when you have jobs that use resources from multiple machines, lockrun isn’t adequate. Consider a cron job that builds a local index of a bunch of NFS-mounted files. You don’t want more than one consumerĀ of that NFS volume to index it at a time, otherwise performance will be degraded.

Enter distlockrun: it works similarly to lockrun except that it talks to a central server for mutual exclusion instead of locking a file.

First of all, you need the lock server running. It’s really lightweight, so you can run it on any machine you’ve already got. For example, on Engine Yard Cloud, it should be run on the database master in a screen session.

Start the server like so: distlockrun-server

By default, it starts on port 7890, but that can be changed with the --port option.

Then, on the client, run your job as follows: distlockrun --server {server's hostname} big-expensive-indexer.rb

If there’s already a big-expensive-indexer.rb running, then distlockrun will just exit. Otherwise, it runs the job and then tells the lock server that it’s finished.

That’s all it takes to get cluster-wide mutual exclusion; short but sweet!

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 14% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

One Response to “Distlockrun: Lockrun for Your Cloud”

  1. I wasn't even aware of lockrun (let alone distlockrun), I can definitely think of a few uses though. Thanks for the post.