1 CLOCK SYNCHRONIZATION " Synchronization in distributed systems is more complicated than in centralized ones because the former have to use distributed.

Slides:



Advertisements
Similar presentations
Synchronization.
Advertisements

Time in Distributed Systems
Distributed Systems CS Synchronization Lecture 6, Sep 26, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
Time and synchronization (“There’s never enough time…”)
Time and Clock Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
CS6223: Distributed Systems Distributed Time and Clock Synchronization (1) Physical Time.
Time and Global States ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
L-8 Synchronizing Physical Clocks 1 Announcements Proj1 checkpoint – due midnight tonight HW1 checkpoint – due 2/12 2.
Time in Embedded and Real Time Systems Lecture #6 David Andrews
Distributed Systems Fall 2010 Time and synchronization.
1. Explain why synchronization is so important in distributed systems by giving an appropriate example When each machine has its own clock, an event that.
Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley Copyright © George Coulouris, Jean Dollimore, Tim.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Distributed Systems CS Synchronization – Part II Lecture 8, Sep 28, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
Synchronization in Distributed Systems. Mutual Exclusion To read or update shared data, a process should enter a critical region to ensure mutual exclusion.
Clock Synchronization and algorithm
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
Lecture 9: Time & Clocks CDK4: Sections 11.1 – 11.4 CDK5: Sections 14.1 – 14.4 TVS: Sections 6.1 – 6.2 Topics: Synchronization Logical time (Lamport) Vector.
1 Synchronization Part 1 REK’s adaptation of Claypool’s adaptation of Tanenbaum’s Distributed Systems Chapter 5.
Physical Clocks.
Synchronization Chapter 6 Part I Clock Synchronization & Logical clocks Part II Mutual Exclusion Part III Election Algorithms Part IV Transactions.
Lecture 2-1 CS 425/ECE 428 Distributed Systems Lecture 2 Time & Synchronization Reading: Klara Nahrstedt.
1 Physical Clocks need for time in distributed systems physical clocks and their problems synchronizing physical clocks u coordinated universal time (UTC)
ALGORITHMS FOR ISNE DR. KENNETH COSH WEEK 13.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Naming CSCI 4780/6780. Attribute-based Naming Flat and structured names provide location transparency Structured names are also human-friendly Increasingly,
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Parallel and Distributed Simulation Synchronizing Wallclock Time.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
Distributed Systems Principles and Paradigms Chapter 05 Synchronization.
1 Clock Synchronization & Mutual Exclusion in Distributed Operating Systems Brett O’Neill CSE 8343 – Group A6.
Synchronization Distributed System. Why synchronization? Two sharpshooters in a multiplayer online game kill the same target. Which one gets the points?
Time This powerpoint presentation has been adapted from: 1) sApr20.ppt.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Real-Time & MultiMedia Lab Synchronization Distributed System Jin-Seung,KIM.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
ICS362 – Distributed Systems Dr. Ken Cosh Week 6.
Distributed Systems CS Synchronization – Part I Lecture 8, Sep 23, 2013 Mohammad Hammoud.
Distributed Process Coordination Presentation 1 - Sept. 14th 2002 CSE Spring 02 Group A4:Chris Sun, Min Fang, Bryan Maden.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
CS 582 / CMPE 481 Distributed Systems Synchronization.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
6 SYNCHRONIZATION. introduction processes synchronize –exclusive access. –agree on the ordering of events much more difficult compared to synchronization.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Hwajung Lee. Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
Synchronization in Distributed Systems In a single CPU system, critical regions, mutual exclusion and other synchronization problems are generally solved.
Proof of liveness: an example
Prof. Leonardo Mostarda University of Camerino
Distributed Computing
CSC 8320 Advanced Operating Systems Spring 2006
Time and Clock.
Logical time (Lamport)
Time and Clock.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Chapter 5 (through section 5.4)
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Distributed Synchronization
Logical time (Lamport)
Logical time (Lamport)
Chap 5 Distributed Coordination
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Outline Theoretical Foundations
Presentation transcript:

1 CLOCK SYNCHRONIZATION " Synchronization in distributed systems is more complicated than in centralized ones because the former have to use distributed algorithms. " Distributed algorithms have the following properties: 1. The relevant information is scattered among multiple machines. 2. Processes make decisions based only on local information. 3. A single point of failure in the system should be avoided. 4. No common clock or other precise global time source exists.

2 Make When the programmer has finished changing all the source files, he/she starts make, which examines the times which all the source and object files were last modified. If the source file input.c has time 2151 and the corresponding object file input.o has time 2150, make knows that input.c has been changed since input.o was created, and thus input.c must be recompiled. On the other hand, if output.c has time 2144 and output.o has time 2145, no compilation is needed here. When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

3 Logical Clocks / Nearly all computers have a circuit for keeping track of time. / Despite the widespread use of the word "clock" to refer to these devices, they are not actually clocks in the usual sense. / Timer is perhaps a better word. / A computer timer is usually a precisely machined quartz crystal. / Associated with each crystal are two registers, a counter and holding reg. / Each oscillation of the crystal decrements the counter by one. / Each interrupt is called one clock tick. / At every clock tick, the interrupt service procedure adds one to the time stored in memory. In this way, the (software) clock is kept up to date.

4 " With a single computer and a single clock, it does not matter much if this clock is off by a small amount. Since all processes on the machine use the same clock, they will still be internally consistent. " As soon as multiple CPUs are introduced, each with its own clock, the situation changes. " Although the frequency at which a crystal oscillator runs is usually fairly stable, it is impossible to guarantee that the crystals in different computers all run at exactly the same frequency. " This difference in time values is called clock skew. " Programs that expect the time associated with a file, object, process, or message to be correct and independent of the machine on which it iwas generated can fail.

5 Lamport's Algorithm Lamport showed that clock synchronization is possible and presented an algorithm for achieving it. 1 Lamport pointed out that clock synchronization need not be absolute. 1 If two processes do not interact, it is not necessary that their clocks be synchronized. 1 What usually matters is not all processes agree on exactly what time it is. 1 The processes should agree on the order in which events occur. 1 It is not essential that this time also agree with the real time as announced on radio every hour. 1 For running make for example, it is adequate that all machines agree that it is 10:00, even if it is 10:02. 1 For these algorithms, it is conventional to speak of clocks as logical clocks. 1 When the additional constraint is present that the clocks must not only be the same, but also must not deviate from the real time by more than a certain amount, the clocks are called physical clocks.

6 Lamport's Algorithm contd., 1 To synchronize logical clocks, Lamport defined a relation called happens before. 1 The expression a-->b is read "a happens before b" and means that all processes agree that first event a occurs, then afterward, event b occurs. 1. If a and b are events in the same process, and a occurs before b, then a-->b is true. 2. If a is the event of a message being sent by one process, and b is the event of of the message being received by another process, then a-->b is also true. A message cannot be received before it is sent, or even at the same time it is sent since it takes a finite amount of time to arrive. 1 Happens-before is a transitive relation, so if a-->b and b-->c then a-->c. 1 If two events, x and y, happen in different processes that do not exchange messages (not even indirectly via third parties), then x-->y is not true, but neither is y-->x. 1 These events are said to be concurrent, which simply means that nothing can be said (or need be said) about when they happened or which is first.

7 Lamport's Algorithm contd., 1 What we need is a way of measuring time such that for every event, a, we can assign it a time value C(a) on which all processes agree. 1 These times values must have the property that if a-->b, then C (a) < C (b). 1 If a and b are two events within the same process and a occurs before b, then C (a) < C (b) 1 Similarly, if a is the sending of a message by one process and b is the reception of that message by another process, then C (a) and C (b) must be assigned in such a way that everyone agrees on the values of C (a) and C (b) with C (a) < C (b). 1 The clock time, C, must always go forward (increasing), never backward (decreasing).

8 Lamport's Algorithm contd., Three processes run on different machines, each with its own clock, running at its own speed. When the clock has ticked 6 times in process 0, it has ticked 8 times in process 1 and 10 times in process 2. Each clock runs at a constant rate, but the rates are different due to differences in the crystals.

9 Lamport's Algorithm contd., Three processes, each with its own clock. The clocks run at different rates. Lamport's Algorithm corrects the clocks.

10 Lamport's Algorithm contd., 1 At time 6, process 0 sends message A to process 1 1 How long this message takes to arrive depends on whose clock you believe, the clock in process 1 reads 16 when it arrives. 1 If the message carries the starting time, 6, in it, process 1 will conclude that it took 10 ticks to make the journey. 1 Is this value possible? 1 According to this reasoning, message B from 1 to 2 takes 16 ticks. 1 Message C from 2 to 1 leaves at 60 and arrives at Similarly, message D from 1 to 0 leaves at 64 and arrives at Are these values possible? It is this situation that must be prevented.

11 Lamport's Algorithm contd., 1 Lamport's solution follows directly from the happened-before relation. 1 Since C left at 60, it must arrive at 61 or later. 1 Each message carries the sending time, according to the sender's clock. 1 The receiver fast forwards its clock to be one more than the sending time. 1 The figures show that clearly that C now arrives at 61. Similarly, D arrives at With one small addition, this algorithm meets our requirements for global time. 1 Between every two events, the clock must tick at least once. 1 If a process sends or receives two messages in quick succession, it must advance its clock by (at least) one tick in between them.

12 Lamport's Algorithm contd., In some situations, an additional requirement is desirable, no two events ever occur at exactly the same time. If events happen in processes 1 and 2 both with time 40, the former becomes 40.1 and the latter becomes All events in a distributed system subject to the following conditions: 1. If a happens before b in the same process, C (a) < C (b). 2. If a and b represent the sending and receiving of a message, C (a) < C (b). 3. For all events a and b, C (a) = C (b)

13 Physical Clocks " Lamport's algorithm gives an unambiguous event ordering. " In some systems (e.g., real-time systems), the actual clock time is important. " An external physical clock is required. " How time is actually measured is important. " Time can be measured astronomically. " The event of the sun's reaching its highest apparent point in the sky is called the transit of the sun. " The interval between two consecutive transits of the sun is called the solar day. " The solar second is defined as exactly 1/86400th of a solar day. " The period of the earth's rotation is not constant. The earth is slowing down due to tidal friction and atmospheric drag.

14 Physical Clocks Contd., " 300 million years ago there were about 400 days per year. " Mean solar second is calculated by measuring a large number of days and taking the average before dividing by 86,400. " With the invention of the atomic clock in 1948, it became possible to meas- ure time much more accurately. " The physicists defined the second to be the time it takes the cesium 133 atom to make exactly 9,192,631,770 transitions. " Currently, about 50 laboratories around the work have cesium 133 clocks. " The BIH (Bureau International De I'Heure) averages these to produce International Atomic time (TAI). TAI is just the mean number of ticks of the cesium 133 clocks since midnight on Jan. 1, 1958 (the beginning of time) divided by 9,192,631,770.

15 International Atomic Time There is a serious problem with TAI; 86,400 TAI secons is now about 3 msec less than a mean solar day. Usin TAI for keeping time would mean that over the course of the years, noon would get earlier and earlier, until it would even- tually occur in the wee hours of the morning. TAI seconds are of constant length, unlike solar seconds.

16 BIH and UTC BIH solves the problem by introducing leap seconds whenever the discrepancy between TAI and solar time grows to 800 msec. It rise to a time based on constant TAI seconds but which stays in phase with the apparent motion of the sun, it is called Universal Coordinated Time (UTC) UTC is the bases of all modern civil timekeeping. To provide UTC to people who need precise time, the National Institute of Standard Time (NIST) operates a shortwave radio station with call letters WWV from Fort Collins, Colorado. Several earth satellites also offer a UTC service.

17 Clock Synchronization Algorithms " If one machine has a WWV receiver, the goal becomes keeping all the other machines synchronized to it. " If no machine have WWV receivers, each machine keeps track of its own time. " Each machine is assumed to have a timer that causes an interrupt H times a second " When timer goes off, the interrupt handler adds 1 to a software clock that keeps track of the number of ticks (interrupts) C. " When the UTC time is t, the value of the clock on machine p is C p (t). " In a perfect case, we would have C p (t) = t for all p and all t. In other words, dC/dt ideally should be 1. " Theoretically, a timer with H=60 should generate 216,00 ticks per hour. In practice, the relative error obtainable with modern timer chips is about A particular machine can get a value in the range 215,998 to 216,002 ticks per hour. 1 - á <= (dC/dt) <= 1 + á

18 Clock Synchronization Algorithms Contd., The constant á is specified by the manufacturer and is knows as the maximum drift rate. If two clocks are drifting from UTC in the opposite directions, at a time dt after they were synchronized, they may be as much as 2 á dt apart. If the operating system designers want to guarantee that no two clocks ever differ by more that r, clocks must be resynch (in software) at least every r/2 á sec.

19 Cristian's Algorithm A machine with the WWV receiver is called a time server. The major problem is that the time must never run backward. The minor problem is that it takes a nonzero amount of time for the time sever's reply to get back to the sender. The amount of the interval from T(0) to T(1) that was devoted to message propagation is T (1) - T (0) - I.

20 The Berkeley Algorithm: Polling every machine periodically to ask what time it is there. In Berkely Unix the time server is active unlike the other Unix, where the time server is always passive (machines ask it for the time periodically) Averaging Algorithms: After a machine broadcasts its time, it starts a local timer to collect all other broadcast that arrive during some interval S. When all the broadcast arrive, an algorithm is run to compute a new time from them. Multiple External Time Sources: For systems in which extremely accurate synchronization with UTC is required. The Other Algorithms

" The Network Time Protocol (NTP) is used to synchronize the time of a computer client or server to another server or reference time source. " Time source - Radio or satellite receiver or modem. - It provides client accuracies typically within a millisecond on - LANs and up to a few tens of milliseconds on WANs. " Time is relative to a primary server synchronized to Coordinated Universal Time (UTC) via a Global Positioning Service (GPS) receiver. " Example: Typical NTP configurations utilize multiple redundant servers and diverse network paths, in order to achieve high accuracy and reliability. Some configurations include cryptographic authentication to prevent accidental or malicious protocol attacks. " Network Time Protocol (NTP) uses port 123 of TCP and UDP services. The Network Time Protocol (NTP) 21