Presentation is loading. Please wait.

Presentation is loading. Please wait.

Distributed Algorithms (22903) Lecturer: Danny Hendler Leader election in rings This presentation is based on the book “Distributed Computing” by Hagit.

Similar presentations


Presentation on theme: "Distributed Algorithms (22903) Lecturer: Danny Hendler Leader election in rings This presentation is based on the book “Distributed Computing” by Hagit."— Presentation transcript:

1 Distributed Algorithms (22903) Lecturer: Danny Hendler Leader election in rings This presentation is based on the book “Distributed Computing” by Hagit attiya & Jennifer Welch

2 2 Message-passing systems p0p0 p1p1 p2p2 p3p3 Processes are represented by graph nodes Bi-directional (unless otherwise stated) labeled communication links (reliable, FIFO) Each process p i (having r links) has state consisting of:  Program state  inbuf i [m], 1 ≤ m ≤ r  outbuf i [m], 1 ≤ m ≤ r (this is inaccessible to p i ) 11 2 3 1 2 2 1

3 3 Message-passing systems (cont'd) p0p0 p1p1 p2p2 p3p3 A Configuration is a vector of process states (q 0, …, q n-1 ) In the initial configuration  inbuf buffers are empty  outbuf buffers may contain messages 11 2 3 1 2 2 1

4 4 Synchronous message-passing systems p0p0 p1p1 p2p2 p3p3 Computation proceeds in rounds In each round:  All messages in the outbuf buffers are delivered  Each process performs a computational step and sends at most a single message on every link. 11 2 3 1 2 2 1

5 5 Asynchronous message-passing systems p0p0 p1p1 p2p2 p3p3 No fixed upper bound on the delay of a message or the time between computation steps An execution is a sequence of events:  comp(i) – a computational step by process i  del(i,j,m) – the delivery of message m from p i to p j 11 2 3 1 2 2 1

6 6 Leader Election in Rings p0p0 p1p1 p2p2 1 1 1 2 2 2 Each process has to decide whether it is a leader or not Termination states are partitioned to elected and not-elected. In every execution, exactly one process enters an elected state, all others enter a non-elected state. We assume rings are oriented.

7 The set of asynch. executions is a superset of the set of synch. executions Leader election in anonymous (synchronous) rings p p p 1 1 1 2 2 2 A ring algorithm is anonymous if processes don’t have an ID they can use in the algorithm (all perform the same code) An anonymous leader election algorithm …Is impossible!!... What about the asynchronous model?

8 8 A simple algorithm for (non-anonymous) asynchronous rings 1.Each process sends probe(ID) to its left neighbor (and then waits) 2.Upon receiving a message probe(i) (from the right) 3. if (i > ID) 4. forward message to the left 5. if (i=ID) 6. send terminate(ID) and terminate as leader 7.Upon receiving terminate(i) 8. if (i > ID) 9. forward message to the left and terminate as non-leader Message complexity is… Θ(n 2 )

9 9 A more efficient asynchronous leader election algorithm Processes may join the algorithm either by spontaneous wakeup at the same time or by receiving a message from an awake process Only spontaneously awakened processes actively participate – the process with maximum ID wins Algorithm proceeds in phases In phase j, a process tries to become the temporary leader of its 2 j -neighborhood –Has to have maximum ID in this neighborhoud Only temporary leaders of phase-j continue to phase j+1

10 10 A more efficient asynchronous leader election algorithm Processes may join the algorithm either by spontaneous wakeup at the same time or by receiving a message from an awake process Only spontaneously awakened processes actively participate – the process with maximum ID wins Algorithm proceeds in phases In phase j, a process tries to become the temporary leader of its 2 j -neighborhood –Has to have maximum ID in this neighborhoud Only temporary leaders of phase-j continue to phase j+1

11 11 An O(n log n) messages asynchronous leader election algorithm (cont’d) 1.Initially, asleep=true, participating=false 2.Upon receiving no message (spontaneous wakeup) 3. asleep:=false, participating=true 4. send probe(ID, 0, 1) to left and right 5.Upon receiving probe(j,l,d) from left (resp., right) 6. if (j=ID) terminate as leader ;a termination message should be sent 7. if (j>ID or  participating) and (d<2 l ) send probe(j,l,d+1) to right (resp., left) 8. if (j>ID or  participating) and (d = 2 l ) send reply(j,l) to left (resp. right) 9.Upon receiving reply(j,l) from left (resp., right) 10. if (j ≠ ID) send reply(j,l) to right (resp., left) 11. else 12. if already received reply(j,l) from right (resp. left) 13. send probe(ID,l+1,1) to left and right

12 12 The message complexity of the asynchronous leader election algorithm is O(n log n)

13 13 An (n log n) lower bound on the number of messages for asynchronous rings A ring algorithm is uniform if it has no knowledge of the size of the ring. It is non-uniform if it can use its knowledge about the size of the ring. We’ll see a proof for uniform algorithms where the process with the maximum ID must be elected and all other processes must learn its ID (write it to some local variable).

14 14 Pasting R 1 and R 2 into R (illustration 1. for Lemma 6) p1p1 R1R1 q1q1 e1e1 R2R2 e2e2 p2p2 q2q2 p1p1 R1R1 q1q1 epep R2R2 p2p2 q2q2 eqeq

15 15 Induction step of lower bound (illustration 2. for Lemma 6) p1p1 R1R1 q1q1 epep R2R2 p2p2 q2q2 eqeq P Q

16 16 An O(n) messages Non-uniform Algorithm for Synchronous Rings 1.Initially phase:=0 and round :=0 2.if (phase = ID) 3. send Leader(ID) 4. terminate as leader 5.else 6. round:=round+1 7. if (round = n) 8. phase:=phase+1 9. round=0 10.Upon receiving Leader(j) 11. if (round < n-1) 12. send Leader(j) 13. terminate as non-leader Synchronized start Only clockwise links are used Time complexity? n(minID+1)

17 17 An O(n) messages Uniform Algorithm Does not rely on synchronized start: a preliminary wake-up phase is added (first-phase messages) Processes that do not wake-up spontaneously act as relays Messages from process with ID i travel at speed 1/2 i (second-phase messages)

18 18 An O(n) messages uniform Algorithm (cont’d) Initially waiting is empty and status=asleep 1.Let R be the set of messages received in this computation round 2.S := empty set ; Set of IDs to send 3.if (status=asleep) then 4. if (R is empty) ; Woke-up spontaneously 5. status:=participating 6. min := ID ; 7. add (ID,1) to S ; First-phase message 8. Else status=relay, min := ∞ ; Act as a relay 9.for each in R do 10. if (m < min) 11. become not elected 12. min:=m 13. if (status=relay) and (h=1) 14. add to S ; m stays first-phase 15. else 16. add to waiting tagged with current round number 17. elseif (m = ID) become elected ; if m>min message is swallowed 18. for each in waiting do 19. if was received 2 m -1 rounds ago 20. remove from waiting and add to S 21.Send S to left

19 19 A proof that the algorithm has linear complexity


Download ppt "Distributed Algorithms (22903) Lecturer: Danny Hendler Leader election in rings This presentation is based on the book “Distributed Computing” by Hagit."

Similar presentations


Ads by Google