Physical Clocks Topics r Physical Clocks r Clock















































- Slides: 47
Physical Clocks
Topics r Physical Clocks r Clock Synchronization Algorithms
Readings r Van Steen and Tanenbaum: 5. 1 r Coulouris: 10. 3
Introduction r Electronic clocks in most servers and network devices keep inaccurate time. r Small errors can add up over a long period. r Assume two clocks are synchronized on January 1. m One of the clocks consistently takes an extra 0. 04 milliseconds to increment itself by a second. m On December 31 the clocks will differ by 20 minutes
Introduction r In some instances it is acceptable to measure time with some accuracy: m When we try to determine how many minutes left in an exam m Making a soft boiled egg r We can be relaxed about time in some instances: m The time it takes to drive to Toronto m The number of hours studied for an exam
Introduction r However, for many applications more precision is needed. r Example: Telecommunications m Accurate timing is needed to ensure that the switches routing digital signals through their networks all run at the same rate. m If not, slow running switches would not be able to cope with traffic and messages would be lost.
Introduction r Example: Global Positioning System (GPS) m Ship, airplane and car navigation use GPS to determine location. m GPS satellites that orbit Earth broadcast timing signals from their clocks. m By looking at the signal from four (or more) satellites, the user’s position can be determined. m 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 r Other: m Need to know when a transaction occurs m Equipment on a factory floor may need to know when to turn on or off equipment. m Billing services m E-mail sorting can be difficult if time stamps are incorrect m Tracking security breaches m Secure document transmissions
Clock Synchronization r In a centralized system: m 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. m 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 r In a distributed system, achieving agreement on time is not easy. r Assume no global agreement on time. Let’s see what happens: m Assume that the compiler and editor are on different machines m output. o has time 2144 m output. c is modified but is assigned time 2143 because the clock on its machine is slightly behind. m Make will not call the compiler. m The resulting executable will have a mixture of object files from old and new sources.
Clock Synchronization r When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.
Clock Synchronization r Another example m File synchronization after disconnected operation • • m If Synchronize workstation and laptop copies of 402 -a 1. c Disconnect laptop Make some changes to 402 -a 1. c on the laptop. Reconnect and re-sync, hopefully copying laptop version over the workstation version. laptop’s clock is behind workstation, the copy might go the other way around
Clocks r Clocks should be synchronized. The question is this: Is it possible to do so? r A computer has a timer, not a clock. r 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 r Two registers are associated with the crystal: a counter and a holding register. m Each oscillation of the crystal decrements the counter by one. When counter is 0, an interrupt is generated. m Each interrupt is called a clock tick. m 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. m A timer can be programmed to generate an interrupt n times per second.
Clocks r 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. r Ordinary quartz clocks drift by ~ 1 sec in 1112 days. (10 -6 secs/sec). r High precision quartz clocks drift rate is ~ 107 or 10 -8 secs/sec
Physical Clocks r Two problems: m How do we synchronize computer clocks with real-world clocks? m How do we synchronize the computer clocks with each other? r To answer these questions, we have to understand how time is measured.
Physical Clocks r Since the invention of mechanical clocks (17 th century) time is measured astronomically (mean solar day, mean solar second). r The event of the sun’s reaching its highest apparent point is called transit of the sun. r This event occurs at about noon each day. r The interval between two consecutive transits of the sun is called the solar day.
Physical Clocks r There are 24 hours in a day m Each hour contains 3600 seconds. m Each day contains 86400 seconds r The solar second is defined as exactly 1/86400 th of a solar day.
Physical Clocks r Computation of the mean solar day.
Physical Clocks r In the 1940’s it was established that the period of the earth’s rotation is not constant. r It is believed that 300 million years ago there were about 400 days per year. r 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. r Short term variations in the length of the day also occur.
Physical Clocks r 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. r The invention of the atomic clock in 1948 made it easier to measure time more accurately. r 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 r The atomic time is computed to make the atomic second equal to the mean solar second (in the year of its introduction in 1958). r Currently about 50 labs have cesium 133 clocks. r Each of them periodically tells the BIH (Bureau International d l’Heure) in Paris how many times its clock ticked. r BIH averages these values. This is referred to as International Atomic Time (TAI).
Universal Coordinated Time r TAI is stable and available to anyone who wants to go to the trouble of buying a cesium clock. r Problem: 86, 400 TAI seconds is now about 3 msec less than a mean solar day since a solar day is getting longer. r 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 r Since the mean solar day gets longer, the BIH made necessary corrections ( by introducing leap seconds) resulting in Universal Coordinated Time (UTC). r UTC is provided to those who need precise time: m 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. m Earth satellites also offer a UTC service: accurate to 0. 5 msec m By telephone from NIST: cheaper but less accurate. m Need to compensate for signal propagation delay.
Physical Clock Coordination r If one machine has a WWV receiver, the goal becomes keeping all the other machines synchronized to it. r 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 r Model of system assumed by clock synchronization algorithms: m When UTC is t, the value of the clock on machine p is Cp(t). m In a perfect world, Cp(t) = t for all p and all t; . m d. C/dt denotes the ratio of the change in the clock time to actual time. • In “perfect world” d. C/dt should be one
Physical Clock Coordination r The relation between clock time and UTC when clocks tick at different rates.
Physical Clock Coordination r Each clock has a maximum drift rate . 1 - d. C/dt <= 1+ r r r 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 are 2 t apart. To limit drift to m m m 2 Dt= /(2 ). resynchronize every d/2 seconds
Christian’s Algorithm r One time server (WWV) receiver; all other machines stay synchronized with the time server. r Periodically ( no more than /2 seconds), each machine sends a message to the time server asking for the current time. r Time server machine responds with CUTC
Cristian's Algorithm r Getting the current time from a time server.
Christian’s Algorithm r CUTC could be smaller then requestor’s clock. Must not set the clock backwards (would this work for the makefile example? ). m Suppose that a timer is set to generate 100 interrupts per second. m Each interrupt would add 10 msec to the time. m Instead the interrupt routine could add only 9 msec each time until the correction has been made. m A clock can be advanced gradually by adding 11 msec at each interrupt.
Christian’s Algorithm r Problem with client setting the clock to CUTC m It takes a nonzero amount of time for the time server’s reply to get back to the sender. m The delay may be large and it varies with network load. m T 0: Starting time of the client’s request m T 1: be the time that the client receives an answer (measured using the same clock). m The best estimate of the message passing propagation time is this: (T 1 -T 0)/2 m The new time should be CUTC + (T 1 -T 0)/2
Christian’s Algorithm r Problem with client setting the clock to CUTC (continued) m 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. m The new time should be based on T 1 -T 0 -I m Christian suggested sending several messages and the fastest reply would be the most accurate since it presumably encountered the least traffic.
Christian’s Algorithm r Single server may fail and thus render synchronization impossible (on a temporary basis). r Christian suggests a group of synchronized time servers, each with a receiver for UTC time signals. r A client multicasts its request to all servers and uses only the first reply obtained.
Christian’s Algorithm r A faulty time server or an imposter time server that replied with deliberately incorrect times, could wreak havoc in a computer systems. r It has been shown that if f is the number of faulty clocks out of a total of N, then we must have N > 3 f. r The problem with faulty clocks is partially addressed by the Berkeley algorithm.
Berkeley Algorithm r Suitable when no machine has a WWV receiver. r The time server (daemon) is active: m Time daemon polls every machine periodically to ask what time is there m Based on the answers, it computes an average time m Tells all other machines to advance their clocks to the new time or slow their clocks down until some specified reduction has been achieved. m Propagation is taken into account. r The time daemon’s time is set manually by operator periodically.
The Berkeley Algorithm a) b) c) 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 r The master takes a fault-tolerant average. m 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. r Should the master fail, then another can be elected (discussed later) using one of the election algorithms.
Network Time Protocols (NTP) r Christian’s method and Berkeley algorithm intended for intranets r NTP intended to provide the ability to externally synchronize clients across the Internet to UTC.
Network Time Protocol (NTP) r The NTP service is provided by a network of servers located across the Internet. r Primary servers receive UTC. r Secondary servers are synchronized with primary servers. r 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 3 Note: Arrows denote synchronization control, numbers denote strata.
Network Time Protocols (NTP) r Layered client-server architecture, based on UDP message passing. r 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. r If a strata 1 server fails, it may become a strata 2 server that is being synchronized through another strata 1 server. r Accuracy: range of 1 -50 msec
Network Time Protocols (NTP) r A 1999 survey of NTP servers shows the following: m 175, 000 servers running NTP in the Internet m 300 are stratum 1 servers m Over 20, 000 are stratum 2 servers m Over 80, 000 are stratum 3 servers
Using Coordination Algorithms r Cristian’s method and the Berkeley algorithm are intended primarily for use within an intranet. r NTP is intended for the Internet.
Is it Enough to Synchronize Physical Clocks? r Values received by a UTC receiver is accurate within a range. r At best we can synchronize clocks to within 10 -30 milliseconds of each other. r We have to synchronize frequently, to avoid clock drift. r The synchronization algorithms are good, but not always sufficient.
Is it Enough to Synchronize Physical Clocks? r Replication of data and processing is an approach often used for reliability and performance reasons. r Reliability m m If one replica is unavailable or crashes, use another Avoid single points of failure r Performance m Placing copies of data close to the processes using them can improve performance through reduction of access time. m If there is only one copy, then the server could become overloaded.
Is it Enough to Synchronize Physical Clocks? r Problems with replication include: m Whenever a copy is modified, that copy becomes different from the rest. m Modifications have to be carried out on all copies to ensure consistency. r Assume that update 1 is issued at 10: 00 and update 2 is issued at 10: 0001. m Due to network delays, replica 2 receives update 2 before update 1. m How is replica 2 to know that there is an earlier update?















































