Presentation is loading. Please wait.

Presentation is loading. Please wait.

Distributed Algorithms (22903)

Similar presentations


Presentation on theme: "Distributed Algorithms (22903)"— Presentation transcript:

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

2 Message-passing systems
1 1 2 1 3 2 2 1 p2 Processes are represented by graph nodes Bi-directional (unless otherwise stated) labeled communication links (reliable, FIFO) Each process pi (having r links) has state consisting of: Program state inbufi[m], 1 ≤ m ≤ r outbufi[m], 1 ≤ m ≤ r (this is inaccessible to pi)

3 Message-passing systems (cont'd)
1 1 2 1 3 2 2 1 p2 A Configuration is a vector of process states (q0, …, qn-1) In the initial configuration inbuf buffers are empty outbuf buffers may contain messages

4 Synchronous message-passing systems
1 1 2 1 3 2 2 1 p2 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.

5 Asynchronous message-passing systems
1 1 2 1 3 2 2 1 p2 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 pi to pj

6 Leader Election in Rings
p0 2 1 1 2 p2 p1 2 1 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 Leader election in anonymous (synchronous) rings
p 2 1 1 2 p p 2 1 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? The set of asynch. executions is a superset of the set of synch. executions

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

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 2j-neighborhood Has to have maximum ID in this neighborhoud Only temporary leaders of phase-j continue to phase j+1

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 2j-neighborhood Has to have maximum ID in this neighborhoud Only temporary leaders of phase-j continue to phase j+1

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

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

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 Pasting R1 and R2 into R (illustration 1. for Lemma 6)
q1 q2 p1 p2 ep R1 R2 eq q1 q2

15 Induction step of lower bound (illustration 2. for Lemma 6)
eq q1 q2 Q

16 An O(n) messages Non-uniform Algorithm for Synchronous Rings
Initially phase:=0 and round :=0 if (phase = ID) send Leader(ID) terminate as leader else round:=round+1 if (round = n) phase:=phase+1 round=0 Upon receiving Leader(j) if (round < n-1) send Leader(j) terminate as non-leader Synchronized start Only clockwise links are used Time complexity? n(minID+1)

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/2i (second-phase messages)

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

19 A proof that the algorithm has linear complexity


Download ppt "Distributed Algorithms (22903)"

Similar presentations


Ads by Google