1 / 59

Leader Election

Leader Election. Leader Election: the idea. We study Leader Election in rings. Why rings?. historical reasons original motivation: regenerate lost token in token ring networks illustrates techniques and principles good for lower bounds and impossibility results. Outline.

deon
Download Presentation

Leader Election

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Leader Election

  2. Leader Election: the idea We study Leader Election in rings

  3. Why rings? • historical reasons • original motivation: regenerate lost token in token ring networks • illustrates techniques and principles • good for lower bounds and impossibility results

  4. Outline • Specification of Leader Election • YAIR • Leader election in asynchronous rings: • An O(n2) algorithm • An O(nlog(n)) algorithm • The revenge of the lower bound! • Leader election in synchronous rings • Breaking the W(nlog(n)) barrier

  5. p0 some links may be missing p1 p2 p4 p3 Message passing: Model • n processorsp0,…pn-1 • connected by bi-directional communication channels • topology represented by undirected graph

  6. Each piis a state machine state set Qi distinguished initial states could be infinite pi’s state includes outbufi[l]: set of messages sent on l-th channel and not yet delivered inbufi[l]: set of messages delivered on l-th channel and not yet processed inbufi initially empty outbufinot accessible Processors

  7. State Transitions • A state transition: • input: accessible state of pi(doesn’t depend on outbufi) • consumes all messages in inbufi • outputs at most a message per channel

  8. Terminology • Definition: A configuration is a vector C = (q0,…,qn-1) • each qi is a state of pi • set of outbufi are messages in transit • In an initial configuration each qi is an initial state of pi • Definition: An event is • a computation event comp(i) • a delivery eventdel(i,j,m) • Definition: An execution is an infinite sequence C0,f0,C1,f1,… where • C0 is an initial configuration • each Ci is a configuration • each fi is an event • Definition: A schedule for the above execution is the sequence of events f0,f1 ,…

  9. Safety and Liveness • Safety property : “nothing bad happens” • holds in every finite execution prefix • Windows™ never crashes • if one general attacks, both do • a program never terminates with a wrong answer • Liveness property: “something good eventually happens” • no partial execution is irremediable • Windows™ always reboots • both generals eventually attack • a program eventually terminates • Admissible executions satisfy safety and liveness properties for a particular system type.

  10. A really cool theorem • Everyproperty is a combination of a safety property and a liveness property • (Alpern and Schneider)

  11. if fk = del(i,j,m) in Ck-1 m is in outbufi[l], where l is pi’s label for channel {pi, pj} in Ck , remove m from outbufi[l] add m to outbufi[h], where h is pi’s label for channel {pi, pj} if fk = comp(i) pichanges state according to its transition function empties inbufi in Ck-1 might add messages to outbufi in Ck Asynchronous Message-Passing Systems C0,f0,C1,f1,C2 … • Admissible if: • Every processor takes an infinite number of computation steps • Every message sent is eventually delivered

  12. SynchronousMessage-Passing Systems • C0,f0,C1,f1,C2 … • all asynchronous constraints, plus • execution partitioned into disjoint rounds • one delivery event for every message in every outbuf • followed by one computation event for every processor • Remarks • not realistic, but • good for algorithm design • good for lower bounds

  13. TIME each processor’s state set includes terminated states termination: all processors in terminated states no messages in transit Complexity SPACE • Count maximum total number of messages • Synchronous: count number of rounds until termination Asynchronous: set unit of time as maximum message delay

  14. The Problem • Final states of processes partitioned in two classes: elected non-elected • Once entered a state, always in that state • In every admissible execution, exactly one process (the leader) enters an elected state. All remaining enter a non-elected state

  15. Lots of variations... • The ring can be unidirectional or bidirectional • The number n of processors may be known or unknown • Processors can be identical or can be somehow distinguished • Communication may be synchronous or asynchronous

  16. Uni- vs. Bidirectional • In unidirectional rings, messages can only be sent in a clockwise direction

  17. Can processors be distinguished? • If no, anonymous algorithms • Processors have no UID • Formally: identical automata • Can distinguish between left and right.

  18. Can processors be distinguished? • If yes: • processors have unique IDs • chosen from some large totally ordered space of ids (e.g. N+) • no constraint on which ID are used (e.g. integers may not be consecutive) • IDs can be either manipulated only by certain operations (e.g. comparison) • or by unrestricted operations

  19. Is n known? • If no, uniform algorithms • Algorithm cannot use information about ring size

  20. Asynchronous: no upper bound on message delivery time no centralized clock no bound on relative speed of processes Synchronous: communication in rounds In a round a process: delivers all pending messages takes an execution step (which may involve sending one or more messages) Communication:Asynchronous vs. Synchronous • if no failures, every message sent is eventually delivered

  21. Theorem There is no deterministic solution to the leader election problem for a synchronous, non-uniform, anonymous bidirectional ring. An Impossibility Result • ProofBy induction on number of rounds k • Base case:k = 0 Easy, since processes start in same state. • Inductive step: Lemma holds for k = t-1 • processors are identical up to round k = t-1 • send same messages to left and right neighbors • every processors receives identical messages on left and right channel • Proof • Suppose that a solution exists for a system A of n > 1 processes. Each process of A starts in the same state • all processors apply same transition function to identical states in round t • all processors have identical states at the end of round t • LemmaThe states of all processors at the end of the each round of the execution of A are the same. Then, if one enters leader state, all do!

  22. Observations • What are the implication for asynchronous rings? • What are the implication for uniform rings?

  23. Outline • Specification of Leader Election • YAIR • Leader election in asynchronous rings: • An O(n2) algorithm • An O(nlog(n)) algorithm • The revenge of the lower bound! • Leader election in synchronous rings • Breaking the W(nlog(n)) barrier

  24. LeLann (1977), Chang and Roberts (1979) unidirectional asynchronous non anonymous: every process has uid uniform (does not depend on n) 3: upon receiving m from right 4: case 5:m.uid > uidi : 6: sendmto left 7: m.uid < uidi: 8: discard m 9: m.uid = uidi: 10: leader := i 11: send <terminate, i> to left 12: terminate endcase 13: upon receiving <terminate, i>from right neighbor 14: leader := i 15: send <terminate, i> to left 16: terminate The LCR Algorithm • 1: upon receiving no message • 2: senduidito left (clockwise)

  25. Correctness • messages from process with highest ID are never discarded • therefore the correct leader is elected • no other processor ID can traverse the entire ring • therefore no one else is elected

  26. Message complexity: O(n2) Time complexity: O(n) n-1 n-2 0 1 2 Complexity This bound is tight… Can we do better?

  27. Hirschenberg and Sinclair (1980) Ring is bidirectional Each process pioperates in phases In each phase l, pisends out“tokens” containing uidi in both directions Tokens are intended to travel distance 2l and return to pi However, tokens may not make it back Phase 1 Phase 0 Phase 2 Phase 1 Phase 1 Phase 2 Phase 0 Phase 0 Phase 2 The HS algorithm • Token continues outbound only if greater than tokens on path • Otherwise discarded • All processes always forward tokens moving inbound If pi receives its own tokenwhile it isgoing outbound, pi is the leader

  28. 1: upon receiving no message 2: ifasleepthen asleep :=false send <uidi,out,1> to left and right 12: upon receiving <uidj,out,h> from right 13: case 14: uidj > uidiandh>1: 15: send <uidj,out,h-1> to left 16: uidj > uidiandh=1: 17:send <uidj,in, 1> to right 18: uidj = uidi 19: leader := i 20: endcase The Protocol • 0: Init: asleep := true • 3: upon receiving <uidj,out,h> from left • 4: case • 5: uidj > uidiandh>1 : • 6: send <uidj,out,h-1> to right • 7: uidj > uidiandh=1 : • 8:send <uidj,in, 1> to left • 9: uidj = uidi : • 10: leader := i • 11:endcase • 21: upon receiving <uidj,in,1> from right • 22: send <uidj,in,1> to left • 23: upon receiving <uidj,in,1> from left 24:send <uidj,in,1> to right • 25: upon receiving <uidi,in,1> from left and right • 26: phase := phase +1 • 27: send (uidi,out,2phase) to left and 28: right

  29. Correctness • Same as LCR: • messages from process with highest ID are never discarded • therefore the correct leader is elected • no other processor ID can traverse the entire ring • therefore no one else is elected

  30. Communication Complexity • Every processor sends a token in phase 0 • 4n messages • For phase l > 0, • the only processors to send a tokens are those who “won” in phase l-1 • There is a winner for every processors 2l-1+1 • Winners in phase l > 0 • Tokens travel distance • Total number of messages sent in phase l is bounded by • Total number of phases • No. of messages bound by which is 2l O(nlogn)

  31. Time Complexity • Time for each phase l • Final phase takes • Next to last phase is • Total time complexity excluding last phase • Time complexity is at most 2 · 2l = 2l+1 n (tokens only traveling outbound) 3n to 5n

  32. The revenge of the lower bound • So far we have seen: • a simple O(n2) algorithm • a more clever O(n logn) algorithm • focus on message complexity • Facts: • W(n logn) lower bound in asynchronous networks • W(n logn) lower bound in synchronous networks when using only comparisons

  33. Outline • Specification of Leader Election • YAIR • Leader election in asynchronous rings: • An O(n2) algorithm • An O(nlog(n)) algorithm • The revenge of the lower bound! • Leader election in synchronous rings • Breaking the W(nlog(n)) barrier • The rise and fall of randomization

  34. Leader Election with fewer than O(n logn) messages • Synchronous rings • UID are positive integers • Can be manipulated using arbitrary arithmetic operations • TimeSlice • n is known to all processors • unidirectional communication • O(n) messages • VariableSpeeds • n is not known to all processors • unidirectional communication • O(n) messages What about Time complexity?

  35. What is special about synchronous rings? • Can convey information by not sending a message • “when your phone doesn’t ring, it’s me”

  36. TimeSlice • Runs in phases • each phase consists of n rounds • in phase i ³0 • if no one elected yet • processor with id i • declares itself the leader • sends token with its UID around • Message complexity: • Time complexity: n n · UIDmin

  37. VariableSpeeds • Each process piinitiates a token • Different tokens travel at different speeds: • for token carrying UIDv, 1 message every rounds • (each process waits rounds after receiving the token before sending it out) • Each process keeps track of smallest UID seen • Discard token with UID greater than smallest UID

  38. Complexity Analysis • By the time UIDmin goes around the ring, the second smallest UID has gone only half way, third smallest a fourth of the way, etc. • Forwarding the token carrying UIDmin has caused more messages than all the other tokens combined • Message complexity bound by • Time Complexity 2n

  39. Variable start times • Processors can start at protocol different times • processors that wake up spontaneously (participants) send token with UID around ring • processors that wake up on receiving a UID (relays) do not initiate their own token

  40. A message life cycle • A message is in phase one • until it is received by an awake processor • forwarded immediately • A message is in phase two • once received by an awake processor • forwarded after rounds

  41. The New Algorithm • When participant receives a message from pi: • if UIDi larger than minimal seen (including own), swallow it • otherwise, delay for rounds • When relay receives a message from pi: • if UIDi larger than minimal seen (not including own), swallow it • otherwise, delay for rounds

  42. Correctness • Lemma: Only the participant processor with the smallest identifier receives its token back • Proof: • Let pi be participating processor with smallest UID • No processor can swallow UIDi • All tokens must go through pi , and will be swallowed • No other processor can receive token back

  43. Complexity • Three categories of messages: • phase one messages • phase two messages sent before the message of eventual leader enters its second phase • phase two messages sent after the eventual leader enters its second phase

  44. Complexity • Lemma:The total number of messages in the first category is at most n. • Proof The lemma follows because at most one phase one message is forwarded by each processor • Suppose pi forwards two phase 1 messages, carrying UIDj and UIDk • Assume, WLOG, that pj closer to pi than pk. • Them, phase 1 message with UIDk must go through pj • If pj awake, then it becomes a phase 2 message • Otherwise, pj becomes a relay and does not send its UID

  45. Complexity • Lemma:The total number of messages in the second category is at most n • Proof • After the first process awakens, it takes at most n rounds before message with UIDmin reaches a participant • During this time, token with UIDv is responsible for messages at most • Max number of messages obtained when UIDs are small (0,1,…,n-1) • Max number of messages in second category:

  46. Complexity • Lemma:The total number of messages in the third category is at most 2n • Proof: analogous to complexity analysis for Variable Speeds • In summary: • Message Complexity: At most 4n • Time complexity

  47. And now for somethingcompletely different... • RANDOMIZATION

  48. Randomized Algorithms • Extend transition function to accept as input • a random number • from a bounded range • under some fixed distribution

  49. Why is it important? • The bad news: • randomization alone does not generally affect • impossibility results • leader election in anonymous network still impossible! • worst case bounds • The good news: • randomization + weakening of problem statement does

  50. Example: RandomizedLeader Election • Impossibility in anonymous rings still holds • but can now elect a leader with some probability • So weaken LE as follows Safety: In every configuration of every admissible execution, at most one processor is in an elected state Liveness: At least one processor is elected with some non-zero probability Behaviors allowed by weakenedspecification: • terminate without a leader • never terminate

More Related