comp 655: distributed/operating systems

35
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 06/13/22 1 Distributed Systems - COMP 655

Upload: lazzaro-murphy

Post on 01-Jan-2016

29 views

Category:

Documents


2 download

DESCRIPTION

COMP 655: Distributed/Operating Systems. Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation. Clock Synchronization. Figure 6-1. When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time. Clock Synchronization Algorithms. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: COMP 655: Distributed/Operating Systems

COMP 655:Distributed/Operating Systems

Summer 2011

Dr. Chunbo Chu

Week 6: Synchronyzation

04/20/23 1

Distributed Systems - COMP 655

Page 2: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Clock Synchronization

Figure 6-1. When each machine has its own clock, an event that occurred after another event may

nevertheless be assigned an earlier time.04/20/23 2

Page 3: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Clock Synchronization Algorithms

Figure 6-5. The relation between clock time and UTC when clocks tick at different rates.04/20/23 3

Page 4: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Network Time Protocol

Figure 6-6. Getting the current time from a time server.04/20/23 4

Page 5: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

The Berkeley Algorithm (1)

Figure 6-7. (a) The time

daemon asks all the other

machines for their clock

values.

04/20/23 5

Page 6: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

The Berkeley Algorithm (2)

Figure 6-7.

(b) The machines answer.

04/20/23 6

Page 7: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

The Berkeley Algorithm (3)

Figure 6-7. (c) The time

daemon tells everyone how

to adjust their clock.

04/20/23 7

Page 8: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Lamport’s Logical Clocks (1)

The "happens-before" relation → can be observed directly in two situations:

• If a and b are events in the same process, and a occurs before b, then a → b is true.

• If a is the event of a message being sent by one process, and b is the event of the message being received by another process, then a → b

04/20/23 8

Page 9: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Lamport’s Logical Clocks (2)

Figure 6-9. (a) Three processes, each with its own clock. The clocks run at different rates. 04/20/23 9

Page 10: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Lamport’s Logical Clocks (3)

Figure 6-9. (b) Lamport’s algorithm corrects the clocks.04/20/23 10

Page 11: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Lamport’s Logical Clocks (4)

Figure 6-10. The positioning of Lamport’s logical clocks in distributed systems.04/20/23 11

Page 12: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Lamport’s Logical Clocks (5)

Updating counter Ci for process Pi

1. Before executing an event Pi executes Ci ← Ci + 1.

2. When process Pi sends a message m to Pj, it sets m’s timestamp ts (m) equal to Ci after having executed the previous step.

3. Upon the receipt of a message m, process Pj

adjusts its own local counter as Cj ← max{Cj , ts (m)}, after which it then executes the first step and delivers the message to the application.04/20/23 12

Page 13: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Example: Totally Ordered Multicasting

• CMH customer adds $100, NY bank adds 1% interest• CMHwill have $1,111 and NY will have $1,110

• Updating a replicated database and leaving it in an inconsistent state.

• Can use Lamport’s to logical clock totally order04/20/23 13

Page 14: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

14

Totally-Ordered MulticastA multicast operation by which all messages are delivered in the same order to each receiver.

Lamport Details:– Each message is timestamped with the current logical time of its sender.– Multicast messages are conceptually sent to the sender.– Assume all messages sent by one sender are received in the order they were sent and that no messages are lost.

04/20/23

Page 15: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

15

Totally-Ordered Multicast

Lamport Details (cont):– Receiving process puts a message into a local queue

ordered according to timestamp.

– The receiver multicasts an ACK to all other processes.

– Key Point from Lamport: the timestamp of the received message is lower than the timestamp of the ACK.

– All processes will eventually have the same copy of the local queue consistent global ordering.

04/20/23

Page 16: COMP 655: Distributed/Operating Systems

04/20/23

Distributed Systems - Comp 655

16

How totally-ordered multicast worksProcess 1 Process 2

10Queue:10 Queue:

8 10

8 Queue:8

Queue:8 10

****

*

msgack

process

Page 17: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Vector Clocks (1)

Figure 6-12. Concurrent message transmission using logical clocks.04/20/23 17

Page 18: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Vector Clocks (2)

Vector clocks are constructed by letting each process Pi maintain a vector VCi with the following two properties:

1. VCi [ i ] is the number of events that have occurred so far at Pi. In other words, VCi [ i ] is the local logical clock at process Pi .

2. If VCi [ j ] = k then Pi knows that k events have occurred at Pj. It is thus Pi’s knowledge of the local time at Pj .

04/20/23 18

Page 19: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Vector Clocks (3)

Steps carried out to accomplish property 2 of previous slide:

1. Before executing an event Pi executes VCi [ i ] ← VCi [i ] + 1.

2. When process Pi sends a message m to Pj, it sets m’s (vector) timestamp ts (m) equal to VCi after having executed the previous step.

3. Upon the receipt of a message m, process Pj adjusts its own vector by setting VCj [k ] ← max{VCj [k ], ts (m)[k ]} for each k, after which it executes the first step and delivers the message to the application.04/20/23 19

Page 20: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Enforcing Causal Communication

Figure 6-13. Enforcing causal communication.04/20/23 20

Page 21: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Mutual ExclusionA Centralized Algorithm (1)

Figure 6-14. (a) Process 1 asks the coordinator for permission to access a hared resource. Permission is granted.

04/20/23 21

Page 22: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Mutual ExclusionA Centralized Algorithm (2)

Figure 6-14. (b) Process 2 then asks permission to access the same resource. The coordinator does not reply.

04/20/23 22

Page 23: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Mutual ExclusionA Centralized Algorithm (3)

Figure 6-14. (c) When process 1 releases the resource, it tells the coordinator, which then replies to 2.04/20/23 23

Page 24: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Distributed Algorithm (1)

Three different cases:1. If the receiver is not accessing the resource and

does not want to access it, it sends back an OK message to the sender.

2. If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request.

3. If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins.

04/20/23 24

Page 25: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Distributed Algorithm (2)

Figure 6-15. (a) Two processes want to access a shared resource at the same moment. 04/20/23 25

Page 26: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Distributed Algorithm (3)

Figure 6-15. (b) Process 0 has the lowest timestamp, so it wins. 04/20/23 26

Page 27: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Distributed Algorithm (4)

Figure 6-15. (c) When process 0 is done, it sends an OK also, so 2 can now go ahead.04/20/23 27

Page 28: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Token Ring Algorithm

Figure 6-16. (a) An unordered group of processes on a network. (b) A logical ring constructed in software.

04/20/23 28

Page 29: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Comparison of the Four Algorithms

Figure 6-17. A comparison of three mutual exclusion algorithms.

04/20/23 29

Page 30: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Election Algorithms

The Bully Algorithm

1. P sends an ELECTION message to all processes with higher numbers.

2. If no one responds, P wins the election and becomes coordinator.

3. If one of the higher-ups answers, it takes over. P’s job is done.

04/20/23 30

Page 31: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

The Bully Algorithm (1)

Figure 6-20. The bully election algorithm. (a) Process 4 holds an election. (b) Processes 5 and 6 respond, telling 4 to stop.

(c) Now 5 and 6 each hold an election.04/20/23 31

Page 32: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

The Bully Algorithm (2)

Figure 6-20. The bully election algorithm. (d) Process 6 tells 5 to stop. (e) Process 6 wins and tells everyone.04/20/23 32

Page 33: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

A Ring Algorithm

Figure 6-21. Election algorithm using a ring.04/20/23 33

Page 34: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Elections in Large-Scale Systems (1)

Requirements for superpeer selection:

1. Normal nodes should have low-latency access to superpeers.

2. Superpeers should be evenly distributed across the overlay network.

3. There should be a predefined portion of superpeers relative to the total number of nodes in the overlay network.

4. Each superpeer should not need to serve more than a fixed number of normal nodes.

04/20/23 34

Page 35: COMP 655: Distributed/Operating Systems

Distributed Systems - COMP 655

Elections in Large-Scale Systems (2)

Figure 6-23. Moving tokens in a two-dimensional space using repulsion forces.

04/20/23 35