Title: Distributed Algorithms (22903)
1DistributedAlgorithms (22903)
Leader election in rings
This presentation is based on the book
Distributed Computing by Hagit attiya
Jennifer Welch
2Message-passing systems
p3
p1
p0
1
1
1
2
3
2
2
1
p2
- Processes are represented by graph nodes.
- Bi-directional (unless otherwise stated) labeled
communication links - Each process pi (having r links) has state
consisting of - Program state
- inbutim, 1 m r
- outbufim, 1 m r (this is inaccessible to
pi)
3Message-passing systems (contd)
p3
p1
p0
1
1
1
2
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
4Synchronous message-passing systems
p3
p1
p0
1
1
1
2
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.
5Asynchronous message-passing systems
p3
p1
p0
1
1
1
2
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
6Leader Election in Rings
p0
1
2
1
2
p1
p2
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.
7Leader election in anonymous rings
p
1
2
1
2
p
p
2
1
- A ring algorithm is anonymous if processes dont
have an ID they can use in the algorithm (all
perform the same code)
An anonymous leader election algorithm is
Impossible!!
8A 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 gt ID)
- forward message to the left
- if (iID)
- send terminate(ID) and terminate as
leader - Upon receiving terminate(i)
- if (i gt ID)
- forward message to the left and terminate
as non-leader
T(n2)
Message complexity is
9A more efficient asynchronous leader election
algorithm
- Proceeds in phases
- In phase j, a process tries to become the
temporary leader of its 2j-neighborhood - Only temporary leaders of phase-j continue to
phase j1
10A more effieicnt asynchronous leader election
algorithm (contd)
- Intially, asleeptrue
- Upon receiving no message (spontaneous wakeup)
- if (asleep)
- asleepfalse
- send probe(ID, 0, 1) to left and right
- Upon receiving probe(j,l,d) from left (resp.,
right) - if (jid) terminate as leader
- if (jgtid) and (dlt2l) send probe(j,l,d1) to
right (resp., left) - if (jgtid) 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,l1,1) to left and right
11The complexity of the asynchronous leader
election algorithm is n log n
12An (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.
Well 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).
13Pasting R1 and R2 into R(illustration 1. for
Lemma 6)
p1
p2
e2
R2
R1
e1
q2
q1
p1
p2
ep
R2
R1
eq
q2
q1
14Induction step of lower bound(illustration 2.
for Lemma 6)
P
p1
p2
ep
R2
R1
eq
q2
q1
Q
15An O(n) messages Non-uniform Algorithm for
Synchronous Rings
- Initially phase0 and round 0
- if (phase ID)
- send Leader(ID)
- terminate as leader
- else
- roundround1
- if (round n)
- phasephase1
- round0
- Upon receiving Leader(j)
- if (round lt n-1)
- send Leader(j)
- terminate as non-leader
- Synchronized start
- Only clockwise links are used
Time complexity?
n(minID1)
16An O(n) messages Uniform Algorithm
- 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/2i (here we assume IDs are
non-negative)
17An O(n) messages uniform Algorithm (contd)
- Initially waiting is empty and asleep is true
- Let R be the set of messages received in this
computation round - S empty set Set of IDs to send
- if (asleep) then
- asleepfalse
- if R is emtpy
- min ID Participating
- add ID to S
- Else min 8 Act as a relay
- for each lt m gt in R do
- if (m lt min)
- become not elected
- add lt m gt to waiting and remember when lt m
gt was added - min m
- if (m ID) become elected
- for each lt m gt in waiting do
- if lt m gt was received 2m-1 rounds ago
- remove lt m gt from waiting and add to S
18A proof that the algorithm has linear complexity