1 Leader Election in Rings. 2 A Ring Network 3 1 1 1 1 11 1 1 2 2 2 2 2 2 2 2 Sense of direction...

Preview:

Citation preview

1

Leader Election in Rings

2

A Ring Network

3

1 1

1

1

11

1

1

2

2

2

2

2

2

2

2

Sense of direction

left

right

4

1 1

1

1

11

1

1

2

2

2

2

2

2

2

2

Links are bi-directional for messages

At most one message in each direction

5

1 1

1

1

11

1

1

2

2

2

2

2

2

2

2

Anonymous Ring

6

Eponymous (non-anonymous) Ring

1 1

1

1

11

1

1

2

2

2

2

2

2

2

2

12

34

5

6

7

8

7

Leader Election

Initial state Final state

leader

8

Leader election algorithms are affected by:

Anonymous RingEponymous Ring

The size of the network is knownThe size of the network is not known

n

Synchronous AlgorithmAsynchronous Algorithm

n

9

Synchronous Anonymous Rings

Every processor runs the same algorithm

Every processor does exactly the sameexecution

10

Initial state Final state

leader

If one node is elected a leader,then every node is elected a leader

11

Final state

leader

Conclusion 1:

Leader electioncannot be solvedin synchronousanonymous rings

12

Final state

leader

Conclusion 2:

Leader electioncannot be solvedin asynchronousanonymous ringseither

Why?

The asynchronous ring may behaveLike the synchronous ring

13

Asynchronous Eponymous Rings

12

34

5

6

7

8

The maximum id node is elected leader

14

12

34

5

6

7

8

Each node sends a message with its idto the left neighbor

18

2

6

47

3

5

15

12

34

5

6

7

8

If: message received id current node id

8

6

7

5

Then: forward message

16

12

34

5

6

7

8

If: message received id current node id

8

7

Then: forward message

17

12

34

5

6

7

8

If: message received id current node id

8

7

Then: forward message

18

12

34

5

6

7

8

If: message received id current node id

8

Then: forward message

19

12

34

5

6

7

8

If: a node receives its own message

8

Then: it elects itself a leader

20

12

34

5

6

7

8

If: a node receives its own message

Then: it elects itself a leader

leader

21

12

34

5

6

7

8leader

The leader sends a message in the networkdeclaring itself as the “leader of the ring”

22

12

34

5

6

7

8leader

Time complexity: )(nO n nodes

23

1n-1

n-3

2

n-2

n

Message complexity: )( 2nO n nodes

worst case scenario:

24

1n-1

n-3

2

n-2

n

Message complexity: )( 2nO n nodes

n messages

25

1n-1

n-3

2

n-2

n

Message complexity: )( 2nO n nodes

1n messages

26

1n-1

n-3

2

n-2

n

Message complexity: )( 2nO n nodes

2n messages

27

1n-1

n-3

2

n-2

n

Message complexity: )( 2nO n nodes

1n

Total messages:

n

2n

1 )( 2n2

28

Notes:

ndoes not need to be known to the algorithm

The algorithm can be converted to asynchronous

29

An O(n log n) Mess. Algorithm

12

34

5

6

7

8

Again, the maximum id node is elected leader

30

12

34

5

6

7

8

odneighborhok

nodesknodesk

31

12

34

5

6

7

8

Phase 1: send id to 1-neighborhood

18

2

6

47

3

5 8

1

5

3 74

6

2

32

If: received id current idThen: send a reply

12

34

5

6

7

8

33

If: a node receives both repliesThen: it becomes a temporal leader

12

34

5

6

7

8

34

12

34

5

6

7

8

Phase 2: send id to 2-neighborhood

8

85

5

7

7

6

6

35

12

34

5

6

7

8

8

8

5

5

7

76

6

If: received id current idThen: forward the message

36

If: received id current idThen: send a reply

12

34

5

6

7

8

At second step:

37

12

34

5

6

7

8

If: a node receives both repliesThen: it becomes a temporal leader

38

12

34

5

6

7

8

Phase 3: send id to -neighborhood22

77

8

8

39

12

34

5

6

7

8

77

8

8

If: received id current idThen: forward the message

40

12

34

5

6

7

8

If: received id current idThen: send a reply

At the step:22

41

12

34

5

6

7

8

If: a node receives both repliesThen: it becomes the leader

42

12

34

5

6

7

8leader

43

12

5

6

8leader

nodesn nlog phases

In general:

44

12

5

6

8leader

Phase i: send id to -neighborhood12 i

12 i

12 i

45

Time complexity

The leader spends time in

Phase 1: 2Phase 2: 4…Phase i:…Phase log n:

i2

Total time: )()2(22 log1log nOO nn

nlog2

46

Phase 1: 4Phase 2: 8…Phase i:…Phase log n:

Message complexity

Messages per leader

12 i

1log2 n

Max #leaders

n

2/n

12/ in

1log2/ nn

47

Phase 1: 4Phase 2: 8…Phase i:…Phase log n:

Total messages:

n4

)log( nnO

12 i

1log2 n

n

2/n

12/ in

1log2/ nn

Messages per leader Max #leaders

n4

n4

n4

n4

48

Notes:

The algorithm does not need to know n

It can be converted to anasynchronous algorithm

49

An Mess. Synchronous Algorithm

)(nO

The node with smallest id is elected leader

There are rounds:

If in round there is a node with id • this is the new leader• the algorithm terminates

i i

n is known

50

Round 1 ( time steps): no message sentn

922

33

24

15

16

57

48

n nodes

51

922

33

24

15

16

57

48

n nodes

Round 2 ( time steps): no message sentn

52

22

33

24

15

16

57

48

n nodes

Round 9

9

new leader

53

22

33

24

15

16

57

48

n nodes

Round 9 ( time steps): messages sentn n

9

new leader

54

22

33

24

15

16

57

48

n nodes

Round 9 ( time steps): messages sentn n

9

new leader

Algorithm Terminates

55

22

33

24

15

16

57

48

n nodes

Round 9 ( time steps): messages sentn n

9

new leader

Total number of messages:n

56

Another Synchronous Algorithm)(nO

The node with smallest id is elected leader

n is not known

57

The algorithm:

• Each node injects a message with its id

• Message with id is injected and transferred with rate

ii2

1

• Nodes which have seen smaller id absorb higher id messages

58

42

31

5

6

7

0

Time 1

0

Transfer rate120

59

42

31

5

6

7

0

Time 2

0

1

120

120 221

120 rate

60

42

31

5

6

7

0

Time 3

0

1

61

42

31

5

6

7

0

Time 4

01

62

42

31

5

6

7

0

Time 5

0

63

42

31

5

6

7

0

Time 6

0

64

42

31

5

6

7

0

Time 8

0

65

Time 8

42

31

5

6

7

00

New leader

66

Message complexity

Assume leader has (smallest) idi

Total time of algorithm:in 2

Note that if then algorithmis exponentially slow

)(ni

67

Take the node with immediately higher id

ik

Total number of messages:

222

edge each on delay messagealgorithm of time total nn

k

i

68

Take the node with immediately higher id

ikl

Total number of messages:

422 nnl

i

69

id

imessages

n

k 2/n

l 4/n

lower

higher

nnn

n 242

Total messages:

70

An Lower Bound )log( nnAssume we have algorithms in which:

• the maximum identifier is elected leader

• all the nodes must know the leader

We will prove:at least messages are needed)log( nn

• the size of the network is not knownn

to elect a leader

• the network is asynchronous

71

open edgeno messages cross it

There is a possible asynchronousexecution with an open edge

(i.e. a very slow edge)

Messages may bepending to crossopen edge

72

open edge

If the edge remains open, then the executionwill eventually reach a quiescent statewhere not more messages cross the ring

Messages pendingto cross open edge

Quiescent State

73

open edgeMessages pendingto cross open edge

Quiescent State

In the quiescent state, a node can send a message only after it receives a message(thus no messages cross the ring)

74

This may cause a propagation of messagesuntil the algorithm terminates

Suppose thatthe edge closes

Time t

75

This may cause a propagation of messagesuntil the algorithm terminates

Time t+1

76

This may cause a propagation of messagesuntil the algorithm terminates

Time t+2

77

Time t+k

k k

After k time steps the affected radius is k

78

Time t+x

Eventually, the ring stabilizes with a leader

79

We will show, that there is an executionwith nodes such that:n

• there is an open edge

• at least messages are received )(nM

1)2( Mwhere

422)(

nnMnM

80

x ybasis case 2n

If then is the leader yx x

should know about thisy

Therefore a message is sent: 1)2( M

Proof by induction

81

x y

open edge

The message can be sent on one edge

82

The case 2n From induction hypothesis, we have an execution:

2n

2n

M

openedge

Messages sent

nodes

83

The case 2n

openedges2

n2n

2n

M

2n

MMessages sent

nodes nodes

From induction hypothesis, we have an execution:

84

Observation:

1R 2R

If no message is sent along

then ring cannotdistinguish the twoscenarios 1R

1R

(similarly for ring )2R

85

2n

2n

2n

M

2n

MMessages sent

nodes nodes

Therefore, the same number of messageshave to be sent in sub-rings

True open edge

True open edge

86

max id

1R 2R

All nodes in should learn about

x

2R x

(assume that max id is in )1R

open edge

open edge

87

max id

1R 2R

All nodes in should learn about

x

2R x

Thus, after the open edges close,at least

2n

messages are sent

2n

(At least oneof these is sent)

88

max idx

Suppose edges close at timet

At least one message is sent

89

max idx

time 1t

At least one message is sent

90

max idx

time 2t

At least messages have been sent since2 t

91

max idx

time kt radius k

At least messages have been sent sincek t

92

max idx

time4n

t

radius 4n

At least messages have been sent since4n t

Independent areas

93

max idx

time4n

t

radius 4n

At least messages have been sent in one area

8n

Independent areas

8n

Messages

94

max idx

time4n

t

radius 4n

open edge

Since areas are independent, we could haveclosed only one edge

8n

Messages

95

max idx

time4n

t

radius 4n

open edge

8n

Messages

2n

M

2n

M

Induction Hypothesis

)log(82

2)( nnnn

MnM

Total Messages

Recommended