http://qs321.pair.com?node_id=1079390

skx has asked for the wisdom of the Perl Monks concerning the following question:

There are various techniques for leader-election, (deciding which one of N nodes is the master), one of variations which is getting a lot of buzz at the moment is the Raft algorithm.

Searching CPAN for "leader", "election", and similar I'm seeing no hits. Nor do I see anything in the raft samples list.

If anybody could point me to an existing implementation for automatically electing a master, whether via HTTP, TCP, UDP, or Multicast, I'd be enormously grateful - if not I guess I have the opportunity to submit something to CPAN myself!

Steve
--
  • Comment on Leader election in a distributed situation?

Replies are listed 'Best First'.
Re: Leader election in a distributed situation?
by wjw (Priest) on Mar 22, 2014 at 19:18 UTC
    I know nothing of this subject and was thus curious.
    Did a search for "perl election leader" and came up with a .ppt file on something called "Zookeeper".

    Then did a search for "cpan zookeeper" and the following showed up: Net::ZooKeeper - search.cpan.org

    Is that at all helpful?

    ...the majority is always wrong, and always the last to know about it...
    Insanity: Doing the same thing over and over again and expecting different results.

      It isn't horrible, but it is an interface to the Apache library so there's a non-perl depdency there.

      In the ideal case I'd be looking for Net::Master class, or similar, with helper classes for different transports. I've been sketching out a prototype using Net::Master::UDP just adding send/recv methods and keeping the logic in the main module, which seems like a good direction.

      The biggest downside is that this is all async stuff, and I've little experience with perl and threading..

      Update: I've got some simple code working for the case of UDP-broadcast only, using threads and threads::shared. I suspect this might be fragile, but I will see.

      Steve
      --
Re: Leader election in a distributed situation?
by tsee (Curate) on Mar 25, 2014 at 20:33 UTC

    For what it's worth, I would welcome a good Raft implementation for Perl. I kind of wonder whether it makes sense to write it in Perl because you kind of want to be able to accept messages out-of-band with your normal application.

    Maybe it's better to wrap a multi-threaded C library or to use the Go implementation (search for Go and Raft on github) and write a client for that. The latter ought to be pretty simple.

      In the end I realized I'd almost certainly need to wrap something external, just due to pain with Perl threading, and handling out of bound accesses.

      I started a pure perl implementation of this, but realized that I couldn't share a "Net::Peer::State" singleton-object around threads because it was too complex for threads::shared, at that point I've stalled for the moment, and have looked at alternative implementations.

      Steve
      --