Clock Synchronization

Similar documents
Distributed Computing. Synchronization. Dr. Yingwu Zhu

Distributed systems Lecture 4: Clock synchronisation; logical clocks. Dr Robert N. M. Watson

Distributed Systems. Time, Clocks, and Ordering of Events

Time. To do. q Physical clocks q Logical clocks

Distributed Systems 8L for Part IB

DISTRIBUTED COMPUTER SYSTEMS

Time in Distributed Systems: Clocks and Ordering of Events

Clock Synchronization

Distributed Systems. Time, clocks, and Ordering of events. Rik Sarkar. University of Edinburgh Spring 2018

Time. Today. l Physical clocks l Logical clocks

Chapter 11 Time and Global States

Distributed Systems. 06. Logical clocks. Paul Krzyzanowski. Rutgers University. Fall 2017

Agreement. Today. l Coordination and agreement in group communication. l Consensus

CS505: Distributed Systems

Slides for Chapter 14: Time and Global States

Time is an important issue in DS

CS505: Distributed Systems

Distributed Systems Principles and Paradigms. Chapter 06: Synchronization

Distributed Systems Principles and Paradigms

Clocks in Asynchronous Systems

Absence of Global Clock

7680: Distributed Systems

CS 347 Parallel and Distributed Data Processing

What is the Right Answer?

416 Distributed Systems. Time Synchronization (Part 2: Lamport and vector clocks) Jan 27, 2017

Logical Time. 1. Introduction 2. Clock and Events 3. Logical (Lamport) Clocks 4. Vector Clocks 5. Efficient Implementation

CS 425 / ECE 428 Distributed Systems Fall Indranil Gupta (Indy) Oct. 5, 2017 Lecture 12: Time and Ordering All slides IG

Distributed Systems Time and Global State

Our Problem. Model. Clock Synchronization. Global Predicate Detection and Event Ordering

Geometry of Earth Sun System

Time, Clocks, and the Ordering of Events in a Distributed System

Modern Navigation. Thomas Herring

Recap. CS514: Intermediate Course in Operating Systems. What time is it? This week. Reminder: Lamport s approach. But what does time mean?

Distributed Systems Fundamentals

A Chronicle of Timekeeping

Causality and physical time

18.2 Earth Cycles Days and years Calendars Years and days Leap years Calendars throughout human history 20,000 years ago. 7,000 BC. 4,000 BC.

TSCCLOCK: A LOW COST, ROBUST, ACCURATE SOFTWARE CLOCK FOR NETWORKED COMPUTERS

Driving Point Impedance Computation Applying Parallel Processing Techniques

10 0 = 1 1 second. Chapter 1

Figure 10.1 Skew between computer clocks in a distributed system

Say Kids, What Time Is It?

Analog Computing Technique

A quartz watch is a watch that uses a movement powered by a quartz crystal to. Quartz crystals are very accurate.

Coordination. Failures and Consensus. Consensus. Consensus. Overview. Properties for Correct Consensus. Variant I: Consensus (C) P 1. v 1.

Solar Observations Using Total Stations Phenomenal Results by: Sayed R. Hashimi, Professor Surveying Engineering Department Ferris State University

Lecture 8: Time & Clocks. CDK: Sections TVS: Sections

The Measurement of Time

( 1) ( 2) ( 1) nan integer, since the potential is no longer simple harmonic.

CptS 464/564 Fall Prof. Dave Bakken. Cpt. S 464/564 Lecture January 26, 2014

Agreement Protocols. CS60002: Distributed Systems. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Causal Consistency for Geo-Replicated Cloud Storage under Partial Replication

Celestial Navigation. 6. Time Objective Greenwich Mean Time

The History of Time-Keeping

Cuts. Cuts. Consistent cuts and consistent global states. Global states and cuts. A cut C is a subset of the global history of H

Today. Vector Clocks and Distributed Snapshots. Motivation: Distributed discussion board. Distributed discussion board. 1. Logical Time: Vector clocks

Chapter S1 Celestial Timekeeping and Navigation. How do we define the day, month, year, and planetary time periods?

TLT-5200/5206 COMMUNICATION THEORY, Exercise 3, Fall TLT-5200/5206 COMMUNICATION THEORY, Exercise 3, Fall Problem 1.

Integrating External and Internal Clock Synchronization. Christof Fetzer and Flaviu Cristian. Department of Computer Science & Engineering

We started our exploration of time by discussing the deep connection between astronomy and our earliest thoughts on time

Chapter S1 Lecture. The Cosmic Perspective Seventh Edition. Celestial Timekeeping and Navigation Pearson Education, Inc.

HNRS 227 Fall 2007 Chapter 14. Earth in Space presented by Prof. Geller 25 October 2007

Verification of clock synchronization algorithm (Original Welch-Lynch algorithm and adaptation to TTA)

Objectives: Students will understand the following: 1. A sundial is a tool for estimating time of day during sunlit hours.

Fundamentals: Frequency & Time Generation

Time Synchronization between SOKUIKI Sensor and Host Computer using Timestamps

A Man With One Watch Knows What Time It Is. George Zampetti, Microsemi Fellow FTD

MASTER CLOCKS 2407MLN1

arxiv: v1 [cs.dc] 22 Oct 2018

Causality and Time. The Happens-Before Relation

A Methodology for Clock Benchmarking

Distributed Algorithms Time, clocks and the ordering of events

Physics 1010: The Physics of Everyday Life. TODAY Clocks How do Aeroplanes Turn?

Accurate Event Composition

The Real-Time Clocks of the 71M65XX Metering ICs

Relativistic Effects

Math and Music Part II. Richard W. Beveridge Clatsop Community College

Outline. EECS Components and Design Techniques for Digital Systems. Lec 18 Error Coding. In the real world. Our beautiful digital world.

Vibrations 8.1. Amplitude, Period, Frequency, and Phase of Vibrations. 338 MHR Unit 4 Waves

Roberto s Notes on Differential Calculus Chapter 8: Graphical analysis Section 1. Extreme points

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

Did you Fall Back Today?

Consistent Global States of Distributed Systems: Fundamental Concepts and Mechanisms. CS 249 Project Fall 2005 Wing Wong

cs/ee/ids 143 Communication Networks

Estimation of clock offset from one-way delay measurement on asymmetric paths

Improvement of Sparse Computation Application in Power System Short Circuit Study

Figure from Mike Rymer, USGS

Week 02. Assist. Prof. Dr. Himmet KARAMAN

Many will remember staring at the

New method for two-point nonuniformity correction of microbolometer detectors

Counters. We ll look at different kinds of counters and discuss how to build them

Secure Communication in Multicast Graphs

Multimedia Systems WS 2010/2011

ROBUST STABILITY AND PERFORMANCE ANALYSIS OF UNSTABLE PROCESS WITH DEAD TIME USING Mu SYNTHESIS

Computers also need devices capable of Storing data and information Performing mathematical operations on such data

ASTR 1010 Astronomy of the Solar System. Course Info. Course Info. Fall 2006 Mon/Wed/Fri 11:00-11:50AM 430 Aderhold Learning Center

Workshop on GNSS Data Application to Low Latitude Ionospheric Research May Fundamentals of Satellite Navigation

Time, Seasons, and Tides

LOCATING CELESTIAL OBJECTS: COORDINATES AND TIME. a. understand the basic concepts needed for any astronomical coordinate system.

Directed Reading. Section: Viewing the Universe THE VALUE OF ASTRONOMY. Skills Worksheet. 1. How did observations of the sky help farmers in the past?

Transcription:

What s it or? Temporal ordering o events produced by concurrent processes Clock Synchronization Synchronization between senders and receivers o messages Coordination o joint activity Serialization o concurrent access or shared objects Logical clocks Assign sequence numbers to messages All cooperating processes can agree on order o events vs. physical clocks: o day Assume no central source Each system maintains its own local clock No total ordering o events No concept o happened-when Happened-beore Lamport s happened-beore notation a b e.g.: event a happened beore event b a: message being sent, b: receipt Transitive: i a b and b c then a c Logical clocks Assign value to each event i a b then clock(a) < clock(b) since cannot run backwards I a and b occur on dierent processes that do not exchange messages, then neither a b nor b a are true These events are concurrent Event counting example Three systems: P 0,, Events a, b, c, Local event counter on each system Systems occasionally communicate 1

Event counting example Event counting example a b 1 j 1 e 3 4 5 6 g h i 1 3 k a b 1 j 1 e 3 4 5 6 g h i 1 3 k Bad ordering: e h k Lamport s algorithm Each message carries a stamp o the sender s clock When a message arrives: i receiver s clock < message stamp set system clock to (message stamp + 1) else do nothing Lamport s algorithm Algorithm allows us to maintain ordering among related events Partial ordering clock must be advanced between any two events Event counting example a b 1 j 1 e 3 4 5 6 g h i 1 7 6 k 7 Summary Algorithm needs a monotonically increasing sotware counter. Incremented or each event o interest. Each such event has a Lamport stamp associated with it. For any two events, where a b: L(a) < L(b)

Problem 1: Identical stamps a b e 1 3 4 5 6 g h i 1 6 7 j k 1 7 a b, b c, : local events are sequenced i c, d, d g, : Lamport imposes a send receive relationship Concurrent events (e.g., a, i) may have the same stamp or not Creating unique stamps (total ordering) We can orce each stamp to be unique Deine global logical stamp (T i, i) T i represents local Lamport stamp i represents process number (globally unique) E.g. (host address, process ID) Compare stamps: (T i, i) < (T j, j) i and only i T i < T j or T i = T j and i < j Does not relate to event ordering Unique (totally ordered) stamps a b e 1.1.1 3.1 4.1 5.1 6.1 g h i 1. 6. 7. j 1.3 k 7.3 Problem : Detecting causal relations I L(e) < L(e ) Cannot conclude that e e Looking at Lamport stamps Cannot conclude which events are causally related Solution: use a vector clock Vector clocks Rules: 1. Vector initialized to 0 at each process V i [j] = 0 or i,j=1,, N. Process increments its element o the vector in local vector beore stamping event: V i [i] = V i [i] +1 3. Message is sent rom process P i with V i attached to it 4. When P j receives message, compares vectors element by element Sets local vector to higher o two values V j [i] = max(v i [i], V j [i]) or i=1,, N Comparing vector stamps Deine V=V i V [i] = V [i]) or i=1,, N V V i V [i] V [i]) or i=1,, N For any two events e, e i e e then V(e) < V(e ) Just like Lamport s algorithm i V(e) < V(e ) then e e Two events are concurrent i neither V(e) V(e ) nor V(e ) V(e) 3

a b e (1,0,0) a b e (1,0,0)(,0,0) a b e (1,0,0)(,0,0) a b (,1,0) e b (,0,0) b (,0,0) c (,1,0) (1,0,0)(,0,0) a b (,1,0)(,,0) e b (,0,0) c (,1,0) d (,,0) (1,0,0)(,0,0) a b (,1,0)(,,0) (0,0,1) e b (,0,0) c (,1,0) d (,,0) e (0,0,1) 4

(1,0,0)(,0,0) a b (,1,0)(,,0) (0,0,1) (,,) e (1,0,0)(,0,0) a b (,1,0)(,,0) (0,0,1) (,,) e b (,0,0) c (,1,0) d (,,0) e (0,0,1) (,,) b (,0,0) c (,1,0) d (,,0) e (0,0,1) (,,) concurrent events (1,0,0)(,0,0) a b (,1,0)(,,0) (0,0,1) (,,) e (1,0,0)(,0,0) a b (,1,0)(,,0) (0,0,1) (,,) e b (,0,0) c (,1,0) d (,,0) e (0,0,1) (,,) concurrent events b (,0,0) c (,1,0) d (,,0) e (0,0,1) (,,) concurrent events (1,0,0)(,0,0) a b (,1,0)(,,0) (0,0,1) (,,) e b (,0,0) c (,1,0) d (,,0) e (0,0,1) (,,) concurrent events Physical clocks 5

Logical vs. physical clocks Logical clock keeps track o event ordering among related (causal) events Useul to have the system keep good real Set to o day Consistent across systems A brie history o keeping Sundial Earliest orm o keeping Origin o dial Latin dies, medieval Latin dialis Divide daylight into equal segments Temporal (temporary) hours Summer hours were longer than winter hours! Water clock Best solution until perection o pendulum c. 1700 Problems: Hole should not get clogged or worn Outlow should not increase with the pressure o more water Calibration diicult Romans used sundial to calibrate water clocks Temporal hours Always 1 hours daylight Hourglass 8 th century Sand does not evaporate Useul in colder climates Sand does not reeze Columbus noted by a ½ hour hourglass Mechanical First need or mechanical Summon people or prayer Alarm clocks Early clocks were bells Mechanical indicators Single hour hand Clock dial invented in 1344 15 minute subdivisions Low accuracy Weight-driven clocks: c. 1400 Verge escapement or regulation 6

Better clocks 1510: Spring clock Slowed down when mainspring unwound Spiral pulley (usee) created in 155 to exert constant orce 1577: minute hand created Generally useless clocks not accurate enough 1656: Pendulum clock Christiaan Huygens 1 min/day; reined to <10 sec/day Minute hand used regularly c. 1680 Accurate Accurate clock needed or computing longitude at sea Use sextant or latitude Cannot use pendulum or clockwork mechanism 175: dead beat escapement Accurate to 1 second per day 1889:Accurate to 0.01 second/day 1761: marine chronometer with spring and balance wheel escapement Kept to 1/5 second per day on sea Determine longitude to within ½ degree 191: dual pendulum clock Accurate to several milliseconds per day Electrical clocks 1840, 1906: Battery Clocks sel-contained battery clock 1916: Synchronous Electric Motor Clock Based on requency o power source Quartz Clocks 1880: Piezoelectric eect Curie brothers Squeeze a quartz crystal & it generates an electric ield Apply an electric ield and it bends 199: Quartz crystal clock Resonator shaped like tuning ork Laser-trimmed to vibrate at 3,768 Hz Standard resonators accurate to 6 parts per million at 31 C Watch will gain/lose < ½ sec/day Stability > accuracy: stable to sec/month Good resonator can have accuracy o 1 second in 10 years Atomic clocks Second is deined as 9,19,631,770 periods o radiation corresponding to the transition between two hyperine levels o cesium-133 Accuracy: better than 1 second in six million years NIST standard since 1960 UTC UT0 Mean solar on Greenwich meridian Obtained rom astronomical observation UT1 UT0 corrected or polar motion UT UT1 corrected or seasonal variations in Earth s rotation UTC Civil measured on an atomic scale 7

UTC Coordinated Universal Time Temps Universel Coordonné Kept within 0.9 seconds o UT1 Atomic clocks cannot keep mean Mean is measure o Earth s rotation Physical clocks in computers CMOS clock (counter) circuit driven by a quartz oscillator battery backup to continue measuring when power is o OS generally programs a r circuit to generate an interrupt periodically e.g., 60 or 100 interrupts per second Programmable Interrupt Controller (PIC) Interrupt service procedure adds 1 to a counter in memory Problem Getting two systems to agree on Two clocks hardly ever agree Quartz oscillators oscillate at slightly dierent requencies Clocks tick at dierent rates Create ever-widening gap in perceived Clock Drit Dierence between two clocks at one point in Clock Skew Perect clock Computer s, C dc = 1 dt UTC, t Drit with slow clock Drit with ast clock Computer s, C skew dc < 1 dt Computer s, C dc > 1 dt skew UTC, t UTC, t 8

Dealing with drit Assume we set computer to true Not good idea to set clock back Illusion o moving backwards can conuse message ordering and sotware development environments Dealing with drit Go or gradual clock correction I ast: Make clock run slower until it synchronizes I slow: Make clock run aster until it synchronizes Dealing with drit OS can do this: Change rate at which it requests interrupts e.g.: i system requests interrupts every 17 msec but clock is too slow: request interrupts at (e.g.) 15 msec Adjustment changes slope o system : Linear compensating unction Compensating or a ast clock Computer s, C dc > 1 dt skew Clock synchronized Linear compensating unction applied UTC, t Compensating or a ast clock Computer s, C UTC, t dc < 1 dt Resynchronizing Ater synchronization period is reached Resynchronize periodically Successive application o a second linear compensating unction can bring us closer to true slope Keep track o adjustments and apply continuously e.g., UNIX adj system call 9

Getting accurate Attach GPS receiver to each computer ±1 mseco UTC Attach WWV radio receiver Obtain broadcasts rom Boulder or DC ± 3 msec o UTC (depending on distance) Attach GOES receiver ±0.1 mseco UTC Getting accurate Synchronize rom another machine One with a more accurate clock Machine that provides inormation Time Not practical solution or every machine Cost, size, convenience, environment RPC Simplest synchronization technique Issue RPC to obtain Set Does not account or network or processing latency what s the? 3:4:19 Cristian s algorithm Compensate or delays Note s: request sent: T 0 reply received: T 1 Assume network delays are symmetric request T reply T 0 T 1 Cristian s algorithm T request reply T 0 T 1 T 1 T0 = estimated overhead in each direction Error bounds I minimum message transit (T min ) is known: Place bounds on accuracy o result Client sets to: T1 T0 Tnew = T + 10

Error bounds request T min Earliest message arrives T reply T 0 T 1 T min range = T 1 -T 0 -T min T T accuracy o result = ± Latest message leaves 1 0 Tmin Cristian s algorithm: example Send request at 5:08:15.100 (T 0 ) Receive response at 5:08:15.900 (T 1 ) Response contains 5:09:5.300 (T ) Elapsed is T 1 -T 0 5:08:15.900-5:08:15.100 = 800 msec Best guess: stamp was generated 400 msec ago Set to T + elapsed 5:09:5.300 + 400 = 5:09.5.700 Cristian s algorithm: example I best-case message =00 msec T request reply T 0 T 1 00 00 800 T 0 = 5:08:15.100 T 1 = 5:08:15.900 T s = 5:09:5:300 T min = 00msec Berkeley Algorithm Gusella & Zatti, 1989 Assumes no machine has an accurate source Obtains average rom participating computers Synchronizes all clocks to average 900 100 800 Error = ± 00 = ± 00 = ± 00 Berkeley Algorithm Machines run dæmon Process that implements protocol One machine is elected (or designated) as the (master) Others are slaves Berkeley Algorithm Master polls each machine periodically Ask each machine or Can use Cristian s algorithm to compensate or network latency When results are in, compute average Including master s Hope: average cancels out individual clock s tendencies to run ast or slow Send oset by which each clock needs adjustment to each slave Avoids problems with network delays i we send a stamp 11

Berkeley Algorithm Berkeley Algorithm: example Algorithm has provisions or ignoring readings rom clocks whose skew is too great Compute a ault-tolerant average 3:00 3:5:50 9:10 I master ails Any slave can take over 3:5 :50 9:10 1. Request stamps rom all slaves Berkeley Algorithm: example Berkeley Algorithm: example 3:00 3:5:50 9:10-0:0 +0:15 3:00-6:05 +0.15 3:5 :50 9:10 3:5 :50 9:10. Compute ault-tolerant average: 3:5 + :50 + 3:00 = 3:05 3 3. Send oset to each Network Time Protocol, NTP 1991, 199 Internet Standard, version 3: RFC 1305 NTP Goals Enable s across Internet to be accurately synchronized to UTC despite message delays Use statistical techniques to ilter data and gauge quality o results Provide reliable service Survive lengthy losses o connectivity Redundant paths Redundant s Enable s to synchronize requently oset eects o clock drit Provide protection against intererence Authenticate source o data 1

NTP s Arranged in strata 1 st stratum: machines connected directly to accurate source nd stratum: machines synchronized rom 1 st stratum machines SYNCHRONIZATION SUBNET 1 3 4 NTP Synchronization Modes Multicast mode or high speed LANS Lower accuracy but eicient Procedure call mode Similar to Cristian s algorithm Symmetric mode Intended or master s Pair o s exchange messages and retain data to improve synchronization over All messages delivered unreliably with UDP NTP messages Procedure call and symmetric mode Messages exchanged in pairs NTP calculates: Oset or each pair o messages Estimate o oset between two clocks Delay Transmit between two messages Filter Dispersion Estimate o error quality o results Based on accuracy o s clock and consistency o network transit Use this data to ind preerred : lower stratum & lowest total dispersion NTP message structure Leap second indicator Last minute has 59, 60, 61 seconds Version number Mode (symmetric, unicast, broadcast) Stratum (1=primary reerence, -15) Poll interval Maximum interval between successive messages, nearest power o Precision o local clock Nearest power o 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 Reerence clock ID Atomic, NIST dial-up, radio, LORAN-C navigation system, GOES, GPS, Reerence stamp Time at which clock was last set (64 bit) Authenticator (key ID, digest) Signature (ignored in SNTP) NTP message structure T 1 : originate stamp Time request departed ( s ) T : receive stamp Time request arrived at ( s ) T 3 : transmit stamp Time request let ( s ) 13

NTP s validation tests Timestamp provided last stamp received duplicate message? Originating stamp in message consistent with sent data Messages arriving in order? Timestamp within range? Originating and received stamps 0? Authentication disabled? Else authenticate Peer clock is synchronized? Don t sync with clock o higher stratum # Reasonable data or delay & dispersion SNTP Simple Network Time Protocol Based on Unicast mode o NTP Subset o NTP, not new protocol Operates in multicast or procedure call mode Recommended or environments where is root node and is lea o synchronization subnet Root delay, root dispersion, reerence stamp ignored RFC 030, October 1996 SNTP SNTP example request T 1 T T 3 reply T 4 request T =800 T 1 =1100 T 3 =850 reply T 4 =100 Roundtrip delay: d=(t 4 -T 1 )-(T -T 3 ) Time oset: (T T1 ) + (T3 = T ) 4 t Oset = ((800-1100)+(850-100))/ =((-300) + (-350))/ = -650/ = -35 Set to T 4 +t = 100-35 = 875 Time oset: (T T1 ) + (T3 = T ) 4 t Cristian s algorithm request T =800 T 3 =850 T 1 =1100 T s =85 reply T 4 =100 The End Oset = (100-1100)/ = 50 Set to T s + oset = 85+50 = 875 14