Physical Clocks.

Slides:



Advertisements
Similar presentations
Lecture 1: Logical, Physical & Casual Time (Part 2) Anish Arora CSE 763.
Advertisements

Synchronization.
Time in Distributed Systems
Logical Clocks.
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.
Time and Global States Ali Fanian Isfahan University of Technology
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.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 9: Time, Coordination and Replication Dr. Michael R. Lyu Computer.
SynchronizationCS-4513, D-Term Synchronization in Distributed Systems CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts,
Synchronization in Distributed Systems CS-4513 D-term Synchronization in Distributed Systems CS-4513 Distributed Computing Systems (Slides include.
1 CLOCK SYNCHRONIZATION " Synchronization in distributed systems is more complicated than in centralized ones because the former have to use distributed.
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 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.
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)
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.
Computer Science Lecture 9, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS Iterative versus Recursive name resolution.
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.
Synchronization Distributed System. Why synchronization? Two sharpshooters in a multiplayer online game kill the same target. Which one gets the points?
Lecture 9: Time and clocks (Chap 11) Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
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.
Distributed Coordination. Turing Award r The Turing Award is recognized as the Nobel Prize of computing r Earlier this term the 2013 Turing Award went.
CLOCK SYNCHRONIZATION SUSMITHA KOTA 21- SEP-2015.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Time and global states Chapter 11. Outline Introduction Clocks, events and process states Synchronizing physical clocks Logical time and logical clocks.
Distributed Systems CS Synchronization – Part I Lecture 8, Sep 23, 2013 Mohammad Hammoud.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems Topic 5: Time, Coordination and Agreement
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.
Hwajung Lee. Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Synchronization in Distributed Systems In a single CPU system, critical regions, mutual exclusion and other synchronization problems are generally solved.
Distributed Systems Lecture 5 Time and synchronization 1.
Distributed Web Systems Time and Global State Lecturer Department University.
Proof of liveness: an example
Prof. Leonardo Mostarda University of Camerino
Distributed Computing
CSC 8320 Advanced Operating Systems Spring 2006
Distributed Systems CS
Time and Global States Ali Fanian Isfahan University of Technology
Logical time (Lamport)
Distributed Systems CS
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems CS
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Distributed Synchronization
Logical time (Lamport)
Logical time (Lamport)
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

Physical Clocks

Topics Physical Clocks Clock Synchronization Algorithms

Readings Van Steen and Tanenbaum: 5.1 Coulouris: 10.3

Introduction Electronic clocks in most servers and network devices keep inaccurate time. Small errors can add up over a long period. Assume two clocks are synchronized on January 1. One of the clocks consistently takes an extra 0.04 milliseconds to increment itself by a second. On December 31 the clocks will differ by 20 minutes

Introduction In some instances it is acceptable to measure time with some accuracy: When we try to determine how many minutes left in an exam Making a soft boiled egg We can be relaxed about time in some instances: The time it takes to drive to Toronto The number of hours studied for an exam

Introduction However, for many applications more precision is needed. Example: Telecommunications Accurate timing is needed to ensure that the switches routing digital signals through their networks all run at the same rate. If not, slow running switches would not be able to cope with traffic and messages would be lost.

Introduction Example: Global Positioning System (GPS) Ship, airplane and car navigation use GPS to determine location. GPS satellites that orbit Earth broadcast timing signals from their clocks. By looking at the signal from four (or more) satellites, the user’s position can be determined. Any tiny error could put you off course by a very long way. A nanosecond of error translates into a GPS error of one foot.

Introduction Other: Need to know when a transaction occurs Equipment on a factory floor may need to know when to turn on or off equipment. Billing services E-mail sorting can be difficult if time stamps are incorrect Tracking security breaches Secure document transmissions

Clock Synchronization In a centralized system: Time is unambiguous. A process gets the time by issuing a system call to the kernel. If process A gets the time and later process B gets the time then the value B gets is higher than (or possibly equal to) the value A got. Example: UNIX make examines the times at which all the source and object files were last modified. If time (input.c) > time(input.o) then recompile input.c If time (input.c) < time(input.o) then no compilation is needed.

Clock Synchronization In a distributed system, achieving agreement on time is not easy. Assume no global agreement on time. Let’s see what happens: Assume that the compiler and editor are on different machines output.o has time 2144 output.c is modified but is assigned time 2143 because the clock on its machine is slightly behind. Make will not call the compiler. The resulting executable will have a mixture of object files from old and new sources.

Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

Clock Synchronization Another example File synchronization after disconnected operation Synchronize workstation and laptop copies of 402-a1.c Disconnect laptop Make some changes to 402-a1.c on the laptop. Reconnect and re-sync, hopefully copying laptop version over the workstation version. If laptop’s clock is behind workstation, the copy might go the other way around

Clocks Clocks should be synchronized. The question is this: Is it possible to do so? A computer has a timer, not a clock. A timer is a precisely machined quartz crystal oscillating at a frequency that depends on how the crystal was cut and the amount of tension.

Clocks Two registers are associated with the crystal: a counter and a holding register. Each oscillation of the crystal decrements the counter by one. When counter is 0, an interrupt is generated. Each interrupt is called a clock tick. At each clock tick, the interrupt procedure adds one to the time stored in memory. The counter is reinitialized by the value in the holding register. A timer can be programmed to generate an interrupt n times per second.

Clocks On each of the computers, the crystals will run at slightly different frequencies, causing the software clocks gradually to get out of sync. This is called clock skew or clock drift. Ordinary quartz clocks drift by ~ 1 sec in 11-12 days. (10-6 secs/sec). High precision quartz clocks drift rate is ~ 10-7 or 10-8 secs/sec

Physical Clocks Two problems: How do we synchronize computer clocks with real-world clocks? How do we synchronize the computer clocks with each other? To answer these questions, we have to understand how time is measured.

Physical Clocks Since the invention of mechanical clocks (17th century) time is measured astronomically (mean solar day, mean solar second). The event of the sun’s reaching its highest apparent point is called transit of the sun. This event occurs at about noon each day. The interval between two consecutive transits of the sun is called the solar day.

Physical Clocks There are 24 hours in a day Each hour contains 3600 seconds. Each day contains 86400 seconds The solar second is defined as exactly 1/86400th of a solar day.

Physical Clocks Computation of the mean solar day.

Physical Clocks In the 1940’s it was established that the period of the earth’s rotation is not constant. It is believed that 300 million years ago there were about 400 days per year. The length of the year (the time for one trip around the sun) is not thought to have changed; the day has simply become longer. Short term variations in the length of the day also occur.

Physical Clocks Astronomers now compute the length of the day by measuring a large number of days and taking the average before dividing by 86,400. This is called the mean solar second. The invention of the atomic clock in 1948 made it easier to measure time more accurately. This is done by counting the transitions (changing energy state) of the cesium 133 atom. A second is defined as the time it takes the cesium 133 atom to make exactly 9,192,631,770 transitions.

Physical Clocks The atomic time is computed to make the atomic second equal to the mean solar second (in the year of its introduction in 1958). Currently about 50 labs have cesium 133 clocks. Each of them periodically tells the BIH (Bureau International d l’Heure) in Paris how many times its clock ticked. BIH averages these values. This is referred to as International Atomic Time (TAI).

Universal Coordinated Time TAI is stable and available to anyone who wants to go to the trouble of buying a cesium clock. Problem:86,400 TAI seconds is now about 3 msec less than a mean solar day since a solar day is getting longer. Using TAI means that over the course of years, noon would get earlier and earlier, until it would eventually occur in the wee hours of the morning.

Universal Coordinated Time Since the mean solar day gets longer, the BIH made necessary corrections ( by introducing leap seconds) resulting in Universal Coordinated Time (UTC). UTC is provided to those who need precise time: National Institute of Standard Time (NIST) operates a shortwave radio station with call letters WWV from Fort Collins, Colorado with +1 to –1 msec accuracy. Earth satellites also offer a UTC service: accurate to 0.5 msec By telephone from NIST: cheaper but less accurate. Need to compensate for signal propagation delay.

Physical Clock Coordination If one machine has a WWV receiver, the goal becomes keeping all the other machines synchronized to it. If no machines have WWV receivers, each machine keeps track of its own time; the goal is to keep the machines synchronized.

Physical Clock Synchronization Model of system assumed by clock synchronization algorithms: When UTC is t, the value of the clock on machine p is Cp(t). In a perfect world, Cp(t) = t for all p and all t;. dC/dt denotes the ratio of the change in the clock time to actual time. In “perfect world” dC/dt should be one

Physical Clock Coordination The relation between clock time and UTC when clocks tick at different rates.

Physical Clock Coordination Each clock has a maximum drift rate . 1-  dC/dt <= 1+ In time t a clock may drift t Assume two clocks are synchronized at time t. Assume that the clocks drift the maximum possible in t in opposite directions. In t, they are2t apart. To limit drift to  2rDt= Dt= /(2r). resynchronize every d/2r seconds

Christian’s Algorithm One time server (WWV) receiver; all other machines stay synchronized with the time server. Periodically ( no more than /2 seconds), each machine sends a message to the time server asking for the current time. Time server machine responds with CUTC

Cristian's Algorithm Getting the current time from a time server.

Christian’s Algorithm CUTC could be smaller then requestor’s clock. Must not set the clock backwards (would this work for the makefile example?). Suppose that a timer is set to generate 100 interrupts per second. Each interrupt would add 10 msec to the time. Instead the interrupt routine could add only 9 msec each time until the correction has been made. A clock can be advanced gradually by adding 11 msec at each interrupt.

Christian’s Algorithm Problem with client setting the clock to CUTC It takes a nonzero amount of time for the time server’s reply to get back to the sender. The delay may be large and it varies with network load. T0: Starting time of the client’s request T1: be the time that the client receives an answer (measured using the same clock). The best estimate of the message passing propagation time is this: (T1-T0)/2 The new time should be CUTC + (T1-T0)/2

Christian’s Algorithm Problem with client setting the clock to CUTC (continued) Also should take into account time it takes the time server to handle the interrupt and process the incoming message. This is the interrupt handle time, I. The new time should be based on T1-T0 -I Christian suggested sending several messages and the fastest reply would be the most accurate since it presumably encountered the least traffic.

Christian’s Algorithm Single server may fail and thus render synchronization impossible (on a temporary basis). Christian suggests a group of synchronized time servers, each with a receiver for UTC time signals. A client multicasts its request to all servers and uses only the first reply obtained.

Christian’s Algorithm A faulty time server or an imposter time server that replied with deliberately incorrect times, could wreak havoc in a computer systems. It has been shown that if f is the number of faulty clocks out of a total of N, then we must have N > 3f. The problem with faulty clocks is partially addressed by the Berkeley algorithm.

Berkeley Algorithm Suitable when no machine has a WWV receiver. The time server (daemon) is active: Time daemon polls every machine periodically to ask what time is there Based on the answers, it computes an average time Tells all other machines to advance their clocks to the new time or slow their clocks down until some specified reduction has been achieved. Propagation is taken into account. The time daemon’s time is set manually by operator periodically.

The Berkeley Algorithm The time daemon asks all the other machines for their clock values using a polling mechanism and providing “current time” The machines answer indicating how they differ from time sent. The time daemon tells everyone how to adjust their clock based on a calculation of the “average time value”.

The Berkeley Algorithm The master takes a fault-tolerant average. A subset of clocks is chosen that do not differ from one another by more than a specified amount and the average is taken of readings from only these clocks. Should the master fail, then another can be elected (discussed later) using one of the election algorithms.

Network Time Protocols (NTP) Christian’s method and Berkeley algorithm intended for intranets NTP intended to provide the ability to externally synchronize clients across the Internet to UTC.

Network Time Protocol (NTP) The NTP service is provided by a network of servers located across the Internet. Primary servers receive UTC. Secondary servers are synchronized with primary servers. The servers are connected in a logical hierarchy called a synchronization subnet whose levels are called strata.

An example synchronization subnet in an NTP implementation 1 2 3 Note: Arrows denote synchronization control, numbers denote strata.

Network Time Protocols (NTP) Layered client-server architecture, based on UDP message passing. The clocks belonging to servers with high stratum numbers are liable to be less accurate than those with low stratum numbers since errors are introduced at each level of synchronization. If a strata 1 server fails, it may become a strata 2 server that is being synchronized through another strata 1 server. Accuracy: range of 1-50 msec

Network Time Protocols (NTP) A 1999 survey of NTP servers shows the following: 175,000 servers running NTP in the Internet 300 are stratum 1 servers Over 20,000 are stratum 2 servers Over 80,000 are stratum 3 servers

Using Coordination Algorithms Cristian’s method and the Berkeley algorithm are intended primarily for use within an intranet. NTP is intended for the Internet.

Is it Enough to Synchronize Physical Clocks? Values received by a UTC receiver is accurate within a range. At best we can synchronize clocks to within 10-30 milliseconds of each other. We have to synchronize frequently, to avoid clock drift. The synchronization algorithms are good, but not always sufficient.

Is it Enough to Synchronize Physical Clocks? Replication of data and processing is an approach often used for reliability and performance reasons. Reliability If one replica is unavailable or crashes, use another Avoid single points of failure Performance Placing copies of data close to the processes using them can improve performance through reduction of access time. If there is only one copy, then the server could become overloaded.

Is it Enough to Synchronize Physical Clocks? Problems with replication include: Whenever a copy is modified, that copy becomes different from the rest. Modifications have to be carried out on all copies to ensure consistency. Assume that update 1 is issued at 10:00 and update 2 is issued at 10:00:0001. Due to network delays, replica 2 receives update 2 before update 1. How is replica 2 to know that there is an earlier update?