Page 1 Clock Synchronization: Physical Clocks Minqi Zhou Distributed Systems Except as otherwise noted, the content of this presentation.

Slides:



Advertisements
Similar presentations
Time in Distributed Systems
Advertisements

Distributed Systems CS Synchronization Lecture 6, Sep 26, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
Distributed Computing
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.
CS6223: Distributed Systems Distributed Time and Clock Synchronization (1) Physical Time.
Computer Science 425 Distributed Systems CS 425 / ECE 428  2013, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2011 August 30, 2011 Lecture 3 Time and Synchronization Reading: Sections
Time and Global States Ali Fanian Isfahan University of Technology
Page 1 Lecturer: Roohollah Abdipour Acknowledgment: Many of the slides are based on slides by Prof. Paul Krzyzanowski at Rutgers University,
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
CS 582 / CMPE 481 Distributed Systems Synchronization.
Distributed Systems Fall 2010 Time and synchronization.
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.
Time and Global States Chapter 11. Why time? Time is an Important and interesting issue in distributes systems. One we can measure accurately. Can use.
Time in Distributed Systems Distributed Systems. Why Time is Important? If you work in the industry, you never have to worry about this You’ll rarely.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 9: Time, Coordination and Replication Dr. Michael R. Lyu Computer.
Distributed Systems CS Synchronization – Part II Lecture 8, Sep 28, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
1 Slides for Chapter 10: Time (and Global State) From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
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.
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.
A Security Analysis of the Network Time Protocol (NTP) Presentation by Tianen Liu.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Time and Coordination March 13, Time and Coordination What is time? :-)  Issue: How do you coordinate distributed computers if there is no global.
Parallel and Distributed Simulation Synchronizing Wallclock Time.
TIME AND GLOBAL STATES Đàm Vĩnh Tường ( ) Nguyễn Lê Anh Đào ( ) Trần Viễn Phúc ( )
1 Time (and Global State). 3 Time – basics zWe want to know when something happened - Physical and logical clocks. zAlgorithms may depend upon clock.
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?
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.
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 Topic 5: Time, Coordination and Agreement
CS 582 / CMPE 481 Distributed Systems Synchronization.
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.
Computer Network Design EEL 6785 Dr. Janusz Zalewski University of Central Florida.
Distributed Systems Lecture 5 Time and synchronization 1.
CSE 486/586 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Web Systems Time and Global State Lecturer Department University.
Topic 7: Time and Global State Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Distributed Computing
Distributed Systems CS
Time and Global States Ali Fanian Isfahan University of Technology
Lecture 5 Time and synchronization
Net 435: Wireless sensor network (WSN)
Time and Clock.
Logical time (Lamport)
Clock Synchronization: Physical Clocks
Distributed Systems CS
Time and Clock.
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:

Page 1 Clock Synchronization: Physical Clocks Minqi Zhou Distributed Systems Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.

Page 2 What’s it for? Temporal ordering of events produced by concurrent processes Synchronization between senders and receivers of messages Coordination of joint activity Serialization of concurrent access for shared objects

Page 3 Physical clocks

Page 4 Logical vs. physical clocks Logical clock keeps track of event ordering –among related (causal) events Physical clocks keep time of day –Consistent across systems

Page 5 Quartz clocks 1880: Piezoelectric effect –Curie brothers –Squeeze a quartz crystal & it generates an electric field –Apply an electric field and it bends 1929: Quartz crystal clock –Resonator shaped like tuning fork –Laser-trimmed to vibrate at 32,768 Hz –Standard resonators accurate to 6 parts per million at 31° C –Watch will gain/lose < ½ sec/day –Stability > accuracy: stable to 2 sec/month –Good resonator can have accuracy of 1 second in 10 years Frequency changes with age, temperature, and acceleration

Page 6 Atomic clocks Second is defined as 9,192,631,770 periods of radiation corresponding to the transition between two hyperfine levels of cesium-133 Accuracy: better than 1 second in six million years NIST standard since 1960

Page 7 UTC UT0 –Mean solar time on Greenwich meridian –Obtained from astronomical observation UT1 –UT0 corrected for polar motion UT2 –UT1 corrected for seasonal variations in Earth’s rotation UTC –Civil time measured on an atomic time scale

Page 8 UTC Coordinated Universal Time Temps Universel Coordonné –Kept within 0.9 seconds of UT1 –Atomic clocks cannot keep mean time Mean time is a measure of Earth’s rotation

Page 9 Physical clocks in computers Real-time Clock: CMOS clock (counter) circuit driven by a quartz oscillator –battery backup to continue measuring time when power is off OS generally programs a timer circuit to generate an interrupt periodically –e. g., 60, 100, 250, 1000 interrupts per second (Linux 2.6+ adjustable up to 1000 Hz) –Programmable Interval Timer (PIT) – Intel 8253, 8254 –Interrupt service procedure adds 1 to a counter in memory

Page 10 Problem Getting two systems to agree on time –Two clocks hardly ever agree –Quartz oscillators oscillate at slightly different frequencies Clocks tick at different rates –Create ever-widening gap in perceived time –Clock Drift Difference between two clocks at one point in time –Clock Skew

Page 11 Sept 18, :00:00

Page 12 Oct 23, :00:00 8:01:248:01:48 Skew = +84 seconds +84 seconds/35 days Drift = +2.4 sec/day Skew = +108 seconds +108 seconds/35 days Drift = +3.1 sec/day

Page 13 Perfect clock UTC time, t Computer’s time, C

Page 14 Drift with slow clock UTC time, t Computer’s time, C skew

Page 15 Drift with fast clock UTC time, t Computer’s time, C skew

Page 16 Dealing with drift Assume we set computer to true time Not good idea to set clock back –Illusion of time moving backwards can confuse message ordering and software development environments

Page 17 Dealing with drift Go for gradual clock correction If fast: Make clock run slower until it synchronizes If slow: Make clock run faster until it synchronizes

Page 18 Dealing with drift OS can do this: Change rate at which it requests interrupts e.g.: if system requests interrupts every 17 msec but clock is too slow: request interrupts at (e.g.) 15 msec Or software correction: redefine the interval Adjustment changes slope of system time: Linear compensating function

Page 19 Compensating for a fast clock UTC time, t Computer’s time, C Linear compensating function applied Clock synchronized skew

Page 20 Compensating for a fast clock UTC time, t Computer’s time, C

Page 21 Resynchronizing After synchronization period is reached –Resynchronize periodically –Successive application of a second linear compensating function can bring us closer to true slope Keep track of adjustments and apply continuously –e.g., U NIX adjtime system call

Page 22 Getting accurate time Attach GPS receiver to each computer ± 1 msec of UTC Attach WWV radio receiver Obtain time broadcasts from Boulder or DC ± 3 msec of UTC (depending on distance) Attach GOES receiver ± 0.1 msec of UTC Not practical solution for every machine –Cost, size, convenience, environment

Page 23 Getting accurate time Synchronize from another machine –One with a more accurate clock Machine/service that provides time information: Time server

Page 24 RPC Simplest synchronization technique –Issue RPC to obtain time –Set time Does not account for network or processing latency clientserver what’s the time? 3:42:19

Page 25 Cristian’s algorithm Compensate for delays –Note times: request sent: T 0 reply received: T 1 –Assume network delays are symmetric server client time requestreply T0T0 T1T1 T server

Page 26 Cristian’s algorithm Client sets time to: server client time requestreply T0T0 T1T1 T server = estimated overhead in each direction

Page 27 Error bounds If minimum message transit time (T min ) is known: Place bounds on accuracy of result

Page 28 Error bounds server client time requestreply T0T0 T1T1 T server T min Earliest time message arrives Latest time message leaves range = T 1 -T 0 -2T min accuracy of result =

Page 29 Cristian’s algorithm: example Send request at 5:08: (T 0 ) Receive response at 5:08: (T 1 ) –Response contains 5:09: (T server ) Elapsed time is T 1 -T 0 5:08: :08: = 800 msec Best guess: timestamp was generated 400 msec ago Set time to T server + elapsed time 5:09: = 5:

Page 30 Cristian’s algorithm: example If best-case message time=200 msec server client time requestreply T0T0 T1T1 T server Error = T 0 = 5:08: T 1 = 5:08: T s = 5:09:25:300 T min = 200msec

Page 31 Berkeley Algorithm Gusella & Zatti, 1989 Assumes no machine has an accurate time source Obtains average from participating computers Synchronizes all clocks to average

Page 32 Berkeley Algorithm Machines run time dæmon –Process that implements protocol One machine is elected (or designated) as the server (master) –Others are slaves

Page 33 Berkeley Algorithm Master polls each machine periodically –Ask each machine for time Can use Cristian’s algorithm to compensate for network latency When results are in, compute average –Including master’s time Hope: average cancels out individual clock’s tendencies to run fast or slow Send offset by which each clock needs adjustment to each slave –Avoids problems with network delays if we send a time stamp

Page 34 Berkeley Algorithm Algorithm has provisions for ignoring readings from clocks whose skew is too great –Compute a fault-tolerant average If master fails –Any slave can take over

Page 35 Berkeley Algorithm: example 3:252:509:103:00 1. Request timestamps from all slaves 3:25 2:50 9:10

Page 36 Berkeley Algorithm: example 3:252:509:103:00 2. Compute fault-tolerant average: 3:25 2:50 9:10

Page 37 Berkeley Algorithm: example 3:252:509:103:00 3. Send offset to each client -0:20 +0:15 -6:

Page 38 Network Time Protocol, NTP 1991, 1992 Internet Standard, version 3: RFC 1305

Page 39 NTP Goals Enable clients across Internet to be accurately synchronized to UTC despite message delays –Use statistical techniques to filter data and gauge quality of results Provide reliable service –Survive lengthy losses of connectivity –Redundant paths –Redundant servers Enable clients to synchronize frequently –offset effects of clock drift Provide protection against interference –Authenticate source of data

Page 40 NTP servers Arranged in strata –1 st stratum: machines connected directly to accurate time source –2 nd stratum: machines synchronized from 1 st stratum machines –… S YNCHRONIZATION S UBNET

Page 41 NTP Synchronization Modes Multicast mode –for high speed LANS –Lower accuracy but efficient Procedure call mode –Similar to Cristian’s algorithm Symmetric mode –Intended for master servers –Pair of servers exchange messages and retain data to improve synchronization over time All messages delivered unreliably with UDP

Page 42 NTP messages Procedure call and symmetric mode –Messages exchanged in pairs NTP calculates: –Offset for each pair of messages Estimate of offset between two clocks –Delay Transmit time between two messages –Filter Dispersion Estimate of error – quality of results Based on accuracy of server’s clock and consistency of network transit time Use this data to find preferred server: –lower stratum & lowest total dispersion

Page 43 NTP message structure Leap second indicator –Last minute has 59, 60, 61 seconds Version number Mode (symmetric, unicast, broadcast) Stratum (1=primary reference, 2-15) Poll interval –Maximum interval between 2 successive messages, nearest power of 2 Precision of local clock –Nearest power of 2

Page 44 NTP message structure Root delay –Total roundtrip delay to primary source –(16 bits seconds, 16 bits decimal) Root dispersion –Nominal error relative to primary source Reference clock ID –Atomic, NIST dial-up, radio, LORAN-C navigation system, GOES, GPS, … Reference timestamp –Time at which clock was last set (64 bit) Authenticator (key ID, digest) –Signature (ignored in SNTP)

Page 45 NTP message structure T 1 : originate timestamp –Time request departed client (client’s time) T 2 : receive timestamp –Time request arrived at server (server’s time) T 3 : transmit timestamp –Time request left server (server’s time)

Page 46 NTP’s validation tests Timestamp provided ≠ last timestamp received –duplicate message? Originating timestamp in message consistent with sent data –Messages arriving in order? Timestamp within range? Originating and received timestamps ≠ 0? Authentication disabled? Else authenticate Peer clock is synchronized? Don’t sync with clock of higher stratum # Reasonable data for delay & dispersion

Page 47 SNTP Simple Network Time Protocol –Based on Unicast mode of NTP –Subset of NTP, not new protocol –Operates in multicast or procedure call mode –Recommended for environments where server is root node and client is leaf of synchronization subnet –Root delay, root dispersion, reference timestamp ignored RFC 2030, October 1996

Page 48 SNTP Roundtrip delay: d = (T 4 -T 1 ) - (T 2 -T 3 ) server client time requestreply T1T1 T2T2 T4T4 T3T3 Time offset:

Page 49 SNTP example server client time requestreply T 1 =1100 T 2 =800 T 4 =1200 T 3 =850 Time offset: Offset = (( ) + ( ))/2 =((-300) + (-350))/2 = -650/2 = -325 Set time to T 4 + t = = 875

Page 50 Cristian’s algorithm server client time requestreply T 1 =1100 T 2 =800 T 4 =1200 T 3 =850 Offset = ( )/2 = 50 Set time to T s + offset = = 875 T s =825

Page 51 Key Points: Physical Clocks Cristian’s algorithm & SNTP –Set clock from server –But account for network delays –Error: uncertainty due to network/processor latency: errors are additive ±10 msec and ±20 msec = ±30 msec. Adjust for local clock skew –Linear compensating function

Page 52 The end.