Presentation is loading. Please wait.

Presentation is loading. Please wait.

DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S

Similar presentations


Presentation on theme: "DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S"— Presentation transcript:

1 DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S. TANENBAUM MAARTEN VAN STEEN Chapter 6 Synchronization (Revised for CS6580) Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

2 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. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

3 Clock Synchronization Algorithms
Figure 6-5. The relation between clock time and UTC when clocks tick at different rates. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

4 Figure 6-6. Getting the current time from a time server.
Network Time Protocol Figure 6-6. Getting the current time from a time server. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

5 Network Time Protocol (NTP)
Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks with primary servers synchronizing to primary sources: GPS satellite (worldwide), GOES satellite, WWV radio (US), MSF radio (UK), Modem time service (NIST, PTB Germany, etc.) NTP uses a hierarchical, layered system of levels of clock sources. Each level is called a “stratum” with a level number i.e. 0, 1, 2, 3. The level indicates its distance from the reference clock. Stratum 0: devices such as atomic clocks (caesium), GPS clocks or radio clocks. Stratum 1, 2, 3 are time servers with high numbered servers sending NTP requests. NTP supports upto 256 strata Clients and servers operate in master/slave, symmetric, or multicast modes. Redundant severs exist for reliability Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

6 Network Time Protocol (Cont.)
Network Time Protocol (NTP) uses UDP on port 123 as its transport layer. NTP just provides UTC time, no time zone. NTPv4 is the current implementation and can maintain time to within 10 milliseconds over the Internet and can achieve accuracies of 200 microseconds in local area networks. A simple implementation of NTP i.e. Simple Network Time Protocol (SNTP) is often used in some embedded devices and applications where high accuracy timing is not required. NTP uses 64-bit timestamps (32-bit seconds and 32-bit fractional second). NTP uses an epoch Jan.1, 1900 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

7 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 Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

8 Lamport’s Logical Clocks (2)
Figure 6-9. (a) Three processes, each with its own clock. The clocks run at different rates. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

9 Lamport’s Logical Clocks (3)
Figure 6-9. (b) Lamport’s algorithm corrects the clocks. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

10 Lamport’s Logical Clocks (4)
Figure The positioning of Lamport’s logical clocks in distributed systems. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

11 Lamport’s Logical Clocks (5)
Updating counter Ci for process Pi Before executing an event Pi executes Ci ← Ci + 1. 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. 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. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

12 Example: Totally Ordered Multicasting
Figure Updating a replicated database and leaving it in an inconsistent state. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

13 Mutual Exclusion A Centralized Algorithm (1)
Figure (a) Process 1 asks the coordinator for permission to access a hared resource. Permission is granted. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

14 Mutual Exclusion A Centralized Algorithm (2)
Figure (b) Process 2 then asks permission to access the same resource. The coordinator does not reply. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

15 Mutual Exclusion A Centralized Algorithm (3)
Figure (c) When process 1 releases the resource, it tells the coordinator, which then replies to 2. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

16 A Distributed Algorithm (1)
Three different cases: If the receiver is not accessing the resource and does not want to access it, it sends back an OK message to the sender. If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. 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. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

17 A Distributed Algorithm (2)
Figure (a) Two processes want to access a shared resource at the same moment. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

18 A Distributed Algorithm (3)
Figure (b) Process 0 has the lowest timestamp, so it wins. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

19 A Distributed Algorithm (4)
Figure (c) When process 0 is done, it sends an OK also, so 2 can now go ahead. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

20 A Token Ring Algorithm Figure (a) An unordered group of processes on a network. (b) A logical ring constructed in software. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

21 A Comparison of the Four Algorithms
Figure A comparison of three mutual exclusion algorithms. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

22 Election Algorithms The Bully Algorithm
P sends an ELECTION message to all processes with higher numbers. If no one responds, P wins the election and becomes coordinator. If one of the higher-ups answers, it takes over. P’s job is done. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

23 The Bully Algorithm (1) Figure 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. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

24 The Bully Algorithm (2) Figure The bully election algorithm. (d) Process 6 tells 5 to stop. (e) Process 6 wins and tells everyone. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

25 Figure 6-21. Election algorithm using a ring.
A Ring Algorithm Figure Election algorithm using a ring. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved


Download ppt "DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S"

Similar presentations


Ads by Google