Upgrade to Pro — share decks privately, control downloads, hide ads and more …

yapc::eu 2013

yapc::eu 2013

reliable cron jobs in distributed environment

Oleg Komarov

August 14, 2013
Tweet

More Decks by Oleg Komarov

Other Decks in Programming

Transcript

  1. Common pitfalls of distributed locks no lock cleanup on process

    death operating not actually holding the lock
  2. Apache ZooKeeper http://zookeeper.apache.org a distributed, open-source coordination service for distributed

    applications reliable, replicated, trx-ordered, single system image operations: create, get, set, get children, delete, exists features: watchers, ephemeral nodes, sequential nodes
  3. Sequential nodes $zkh->create( "/path/basename-", $data, flags => ZOO_SEQUENTIAL ) for

    (1 .. 3); creates /path/basename-0000000001 /path/basename-0000000002 /path/basename-0000000003
  4. Non-blocking exclusive lock $zkh->create($lock_path, $node_data, acl => ZOO_OPEN_ACL_UNSAFE, flags =>

    ZOO_EPHEMERAL, ); if (my $error = $zkh->get_error) { if ($error == ZNODEEXISTS) { return undef; # the lock is held by someone else } else { die "Could not acquire lock $lock_path: $error"; } } # success return $zkh->exists($lock_path, watch => $lock_watch);
  5. How to setup install switchman create a local configuration file

    create a znode in zookeeper modify your crontabs
  6. Usage switchman COMMAND # lockname == command’s basename switchman --lockname

    LOCK -- COMMAND [ARGS] switchman --lease FQDN_cpu=1:CPU COMMAND switchman --group grp2 COMMAND # runs only on host1
  7. Thank you! Any questions? If you really liked the talk,

    don’t hesitate to like my quest :) http://questhub.io/player/komarov