Download presentation
Presentation is loading. Please wait.
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 Each process p i (having r links) has state consisting of: Program state inbut 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
7 Leader election in anonymous 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!!
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 Proceeds in phases In phase j, a process tries to become the temporary leader of its 2 j -neighborhood Only temporary leaders of phase-j continue to phase j+1
10
10 A more effieicnt asynchronous leader election algorithm (cont’d) 1.Intially, asleep=true 2.Upon receiving no message (spontaneous wakeup) 3. if (asleep) 4. asleep:=false 5. send probe(ID, 0, 1) to left and right 6.Upon receiving probe(j,l,d) from left (resp., right) 7. if (j=id) terminate as leader 8. if (j>id) and (d<2 l ) send probe(j,l,d+1) to right (resp., left) 9. if (j>id) and (d = 2 l ) send reply(j,l) to left (resp. right) 10.Upon receiving reply(j,l) from left (resp., right) 11. if (j ≠ id) send reply(j,l) to right (resp., left) 12. else 13. if already received reply(j,l) from right (resp. left) 14. send probe(ID,l+1,1) to left and right
11
11 The complexity of the asynchronous leader election algorithm is n log n
12
12 An (n log n) lower bound on the number of messages 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).
13
13 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
14
14 Induction step of lower bound (illustration 2. for Lemma 6) p1p1 R1R1 q1q1 epep R2R2 p2p2 q2q2 eqeq P Q
15
15 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)
16
16 Does not rely on synchronized start: a preliminary wake-up phase is added. Processes that do note wake-up spontaneously act as relays Messages from process with ID i travel at speed 1/2 i (here we assume IDs are non-negative) An O(n) messages Uniform Algorithm
17
17 An O(n) messages uniform Algorithm (cont’d) Initially waiting is empty and asleep is true 1.Let R be the set of messages received in this computation round 2.S := empty set ; Set of IDs to send 3.if (asleep) then 4. asleep:=false 5. if R is emtpy 6. min := ID ; Participating 7. add ID to S 8.Else min := ∞ ; Act as a relay 9.for each in R do 10. if (m < min) 11. become not elected 12. add to waiting and remember when was added 13. min := m 14. if (m = ID) become elected 15. for each in waiting do 16. if was received 2 m -1 rounds ago 17. remove from waiting and add to S 18.Send S to left
18
18 A proof that the algorithm has linear complexity
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.