Distributed Systems. 05. Clock Synchronization. Paul Krzyzanowski. Rutgers University. Fall 2017

Similar documents
Distributed Systems. Clock Synchronization: Physical Clocks. Paul Krzyzanowski

Clock-Synchronisation

INTERNATIONAL JOURNAL OF ENGINEERING SCIENCES & RESEARCH TECHNOLOGY

Time. COS 418: Distributed Systems Lecture 3. Wyatt Lloyd

TIME ATTRIBUTION 11/4/2018. George Porter Nov 6 and 8, 2018

Time Synchronization and Logical Clocks

Distributed Systems COMP 212. Lecture 17 Othon Michail

Time Synchronization and Logical Clocks

CSE 124: TIME SYNCHRONIZATION, CRISTIAN S ALGORITHM, BERKELEY ALGORITHM, NTP. George Porter October 27, 2017

Lecture 12: Time Distributed Systems

Distributed Systems Exam 1 Review Paul Krzyzanowski. Rutgers University. Fall 2016

Lecture 10: Clocks and Time

殷亚凤. Synchronization. Distributed Systems [6]


Distributed Systems Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2016

Last Class: Naming. Today: Classical Problems in Distributed Systems. Naming. Time ordering and clock synchronization (today)

Synchronization. Distributed Systems IT332

Last Class: Naming. DNS Implementation

Distributed Coordination 1/39

Synchronisation in. Distributed Systems. Co-operation and Co-ordination in. Distributed Systems. Kinds of Synchronisation. Clock Synchronization

Distributed Clock Synchronization Algorithms: A Survey

Time in Distributed Systems

Synchronization Part 1. REK s adaptation of Claypool s adaptation of Tanenbaum s Distributed Systems Chapter 5

Middleware and Distributed Systems. Time. Martin v. Löwis. Mittwoch, 22. Februar 12

CSE 5306 Distributed Systems. Synchronization

Distributed Systems. Pre-Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2015

Distributed Systems. Time, clocks, and Ordering of events. Rik Sarkar. University of Edinburgh Fall 2014

Verteilte Systeme (Distributed Systems)

Configuring Precision Time Protocol (PTP)

2017 Paul Krzyzanowski 1

Implementing NTP. Support was added for IPv6 addresses, VRFs, multicast-based associations, and burst and iburst modes for poll-based associations.

Implementing NTP. Release 3.8.0

Network Time Protocol

CS 417: the one-hour study guide for exam 2

CSE 123: Computer Networks Alex C. Snoeren. HW 2 due Thursday 10/21!

The Flooding Time Synchronization Protocol

DISTRIBUTED REAL-TIME SYSTEMS

Synchronization. Clock Synchronization

Synchronization of Network Devices Time by GPS Based Network Time Protocol Output

Wireless Communication Bluetooth, Timing

Precision Time Protocol Software Configuration Guide for IE 4000, IE 4010, and IE 5000 Switches

Synchronization. Chapter 5

Implementing a NTP-Based Time Service within a Distributed Middleware System

PTP Implementation Challenges and Best Practices

Distributed Systems 11. Consensus. Paul Krzyzanowski

CSE 5306 Distributed Systems

Chapter 6 Ti T me m s ynchronization

Wireless Sensor Networks: Clustering, Routing, Localization, Time Synchronization

Clock and Time. THOAI NAM Faculty of Information Technology HCMC University of Technology

Distributed Systems. 10. Consensus: Paxos. Paul Krzyzanowski. Rutgers University. Fall 2017

IEEE 1588 Hardware Assist

Timing in Packet Networks. Stefano RUffini 9 March 2015

IEEE-1588 STANDARD FOR A PRECISION CLOCK SYNCHRONIZATION PROTOCOL FOR NETWORKED MEASUREMENT AND CONTROL SYSTEMS

Selected Questions. Exam 2 Fall 2006

Delivering Sub-Microsecond Accurate Time to Linux Applications Around the World

Lecture 9: Bridging & Switching"

Table of Contents 1 NTP Configuration 1-1

TIME AND SYNCHRONIZATION. I. Physical Clock Synchronization: Motivation and Challenges

Clock Synchronization. Synchronization. Clock Synchronization Algorithms. Physical Clock Synchronization. Tanenbaum Chapter 6 plus additional papers

Replication in Distributed Systems

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

Operation Manual NTP. Table of Contents

SICLOCK TC 400 / TC100 and Redundancy

Precision Time Protocol, and Sub-Microsecond Synchronization

Distributed Systems COMP 212. Revision 2 Othon Michail

Precision Time Protocol Software Configuration Guide for IE 2000U and Connected Grid Switches

IEEE 1588 PTP clock synchronization over a WAN backbone

IP SLAs QFP Time Stamping

Residential Ethernet: Time-of-day timer synchronization. Maintained by David V James

HP 6125G & 6125G/XG Blade Switches

Basic vs. Reliable Multicast

HP 6125 Blade Switch Series

Chapter 6 Synchronization

Proseminar Distributed Systems Summer Semester Paxos algorithm. Stefan Resmerita

Ad hoc and Sensor Networks Time Synchronization

Tutorial on Time-Synchronization for AAA2C based on IEEE Std 802.1AS -2011

Precise computer clock setting with MS Windows

Chapter 16: Switched Ethernet in Automation. Wenbo Qiao

Time in Distributed Systems

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

Coordination 1. To do. Mutual exclusion Election algorithms Next time: Global state. q q q

Chapter 6 Synchronization (1)

Irish NTP Subnet. Performance Issues. Hugh Melvin & Paraic Quinn. Dept. of Information Technology NUI,G

Distributed Synchronization. EECS 591 Farnam Jahanian University of Michigan

Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

Distributed Systems. 09. State Machine Replication & Virtual Synchrony. Paul Krzyzanowski. Rutgers University. Fall Paul Krzyzanowski

2. Time and Global States Page 1. University of Freiburg, Germany Department of Computer Science. Distributed Systems

Some portions courtesy Srini Seshan or David Wetherall

Implementing NTPv4 in IPv6

Configuring PTP. Information About PTP. This chapter contains the following sections:

Version 2.6. Product Overview

Distributed Systems (5DV147)

CS /15/16. Paul Krzyzanowski 1. Question 1. Distributed Systems 2016 Exam 2 Review. Question 3. Question 2. Question 5.

SETTING UP AN NTP SERVER AT THE ROYAL OBSERVATORY OF BELGIUM

PTP650 Synchronous Ethernet and IEEE1588 Primer

Virtualize Everything but Time

Globally Synchronized time via Datacenter Networks

Configuring NTP. Information About NTP. This chapter contains the following sections:

HP 5920 & 5900 Switch Series

µtasker Document µtasker SNTP (Simple Network Time Protocol)

Transcription:

Distributed Systems 05. Clock Synchronization Paul Krzyzanowski Rutgers University Fall 2017 2014-2017 Paul Krzyzanowski 1

Synchronization Synchronization covers interactions among distributed processes Clocks Mutual exclusion Leader election Message consistency Agreement Identifying when something happened Only one entity can do an operation at a time Who coordinates activity? Does everyone have the same view of events? Can everyone agree on a proposed value? All of these are trivial in non-distributed systems All of these are tricky in distributed systems 2

Clock Synchronization 3

Why? Allow a process to identify "now" in a way that's consistent with other processes on other systems Temporal ordering of events from concurrent processes Example: replication & identifying latest versions Last writer wins or latest version wins 4

Simple approach to replication Data store P 0 x = 1 P 1 x = 8 Replica data store x = 1 5

Simple approach to replication Arrives first Data store P 0 x = 8 Inconsistent replicas! P 1 x = 8 Arrives first Replica data store x = 4 6

Simple approach to replication Send a time stamp with each modification request Only newer timestamps can override older data Data store x=8 overrides x=4 P 0 x = 8, T = 7:02 P 1 x = 8, T=7:02 Arrives first Replica data store x = 8, T = 7:02 x=4 does NOT override x=8 There are problems with this but physical clocks help this work most of the time 7

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

Physical clocks 9

Problem: Get two systems to agree on time Why is it hard? 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 Relative offset Short-term variation in frequency Jitter Also note: astronomical time vs. relative time Time of day vs. count of seconds from epoch 10

Dealing with drift Not good idea to set a clock back Illusion of time moving backwards can confuse message ordering and software development environments Go for gradual clock correction If fast: Make the clock run slower until it synchronizes If slow: Make the clock run faster until it synchronizes 11

Dealing with drift The OS can do this: 1. Redefine the rate at which system time is advanced with each interrupt or 2. Read the counter but compensate for drift Adjustment changes slope of system time: Linear compensation function 12

Compensating for a fast clock Computer s time, C offset Clock synchronized Linear compensation function applied UTC time, t 13

Compensating for a fast clock Computer s time, C Now we re drifting again! UTC time, t 14

Resynchronizing After synchronization period is reached Resynchronize periodically Successive application of a second linear compensating function can bring us closer to true slope Long-term clock stability is not guaranteed The system clock can still drift based on changes in temperature, pressure, humidity, and age of the crystal Keep track of adjustments and apply continuously e.g., BSD adjtimex & Linux adjtimex system calls and hwclock command 15

Going to sleep RTC keeps on ticking when the system is off (or sleeping) OS cannot apply correction continually Estimate drift on wake-up and apply a correction factor 16

Getting accurate time Attach GPS receiver to each computer Accurate to ~ 40 ns Not practical solution for every machine Cost, power, convenience, environment Accuracy gets worse near buildings, bridges, trees, 17

Synchronize from a time server Simplest synchronization technique Send a network request to obtain the time Set the time to the returned value client what s the time? 3:42:19 time server Does not account for network or processing latency 18

Cristian s algorithm Compensate for delays Note times: request sent: T 0 reply received: T 1 Assume network delays are symmetric server T server client request reply T 0 T 1 time 19

Cristian s algorithm Client sets time to: T server server client request reply T 0 T 1 T " T $ 2 = time estimated overhead in each direction T new =T server + T 1 T 0 2 20

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

Error bounds T server server client request reply T 0 T 1 time Earliest time message arrives T min T min Latest time message leaves range = T 1 - T 0-2T min accuracy of result = ± T 1 T 0 2 T min 22

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:25.300 (T server ) Elapsed time is T 1 -T 0 5:08:15.900-5:08:15.100 = 800 ms Note: 1 000 ms = 1 s 1 000 000 µs = 1s Best guess: timestamp was generated 400 ms ago Set time to T server + elapsed time 5:09:25.300 + 400 = 5:09.25.700 23

Cristian s algorithm: example If best-case message time=200 ms server T server T 0 = 5:08:15.100 T 1 = 5:08:15.900 T s = 5:09:25:300 T min = 200 ms client request reply T 0 T 1 200 200 time 800 Error = ± 900 100 2 200 = ± 800 2 200 = ±200 24

Berkeley Algorithm Gusella & Zatti, 1989 Assumes no machine has an accurate time source Obtains average from participating computers Synchronizes all clocks to a fault-tolerant average 25

Berkeley Algorithm: example 3:00 master 2:50 3:25 2:50 9:10 1. Request timestamps from all slaves 26

Berkeley Algorithm: example 3:00 master 2:50 3:25 2:50 9:10 2. Compute fault-tolerant average: 3 : 25 + 2 : 50 + 3 : 00 3 = 3 : 05 Suppose max =0:45 27

Berkeley Algorithm: example 3:00 master +0:15 3:25 2:50 9:10 3. Send offset to each client 28

Network Time Protocol, NTP 1991, 1992 Internet Standard, version 3: RFC 1305 June 2010 Internet Standard, version 4: RFC 5905-5908 IPv6 support Improve accuracy to tens of microseconds Dynamic server discovery 29

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 Provide scalable service Enable huge numbers of clients to synchronize frequently Offset effects of clock drift Provide protection against interference Authenticate source of data 30

NTP servers Arranged in strata Stratum 0 = master clock 1 st stratum: systems connected directly to accurate time source 2 nd stratum: systems synchronized from 1 st stratum systems 15 th stratum: systems synchronized from 14 th stratum systems 0 1 2 3 4 Synchronization Subnet 31

NTP Synchronization Modes Multicast mode for high speed LANs Lower accuracy but efficient Procedure call mode Cristian s algorithm Symmetric mode Peer servers can synchronize with each other to provide mutual backup Usually used with stratum 1 & 2 servers Pair of servers retain data to improve synchronization over time All messages are delivered unreliably with UDP (port 123) 32

NTP Clock Quality Precision Smallest increase of time that can be read from the clock Jitter Difference in successive measurements Due to network delays, OS delays, and clock oscillator instability Accuracy How close is the clock to UTC? 33

NTP messages Procedure call and symmetric mode Messages exchanged in pairs: request & response Time encoded as a 64 bit value: Divide by 2 32 to get the number of seconds since Jan 1 1900 UTC NTP calculates: Offset for each pair of messages (θ) Estimate of time offset between two clocks Delay (δ) Travel time: ½ of total delay minus remote processing time Dispersion Maximum offset error relative to reference clock Use this data to find preferred server: Probe multiple servers each several times Pick lowest dispersion at the lowest stratum if tied 34

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 v3 RFC 2030, October 1996 v4 RFC 5905, June 2010 35

SNTP Example server T 2 T 3 request reply client T 1 T 4 time Round-trip network delay: = T. T " (T - T * ) Time offset: t = (T * T " ) + (T - T. ) 2 36

SNTP Example server T 2 T 3 request reply client T 1 T 4 time Round-trip network delay: = T. T " (T - T * ) Time offset: t = (T * T " ) + (T - T. ) 2 37

SNTP example server T 2 =800 T 3 =850 client request T 1 =1100 reply time T 4 =1200 Offset = ((800-1100) + (850-1200)) / 2 = ((-300) + (-350)) / 2 = -650 / 2 = -325 Set time to T 4 + t = 1200-325 = 875 Time offset: t = (T * T " ) + (T - T. ) 2 38

SNTP = Cristian s algorithm server T 2 T 3 client request T s reply time T 1 T 4 Just define T 0 = T * + T - 2 39

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 Example: ±10 ms and ±20 ms = ±30 ms Adjust for local clock drift Linear compensating function 40

Precision Time Protocol 41

PTP: IEEE 1588 Precision Time Protocol Designed to synchronize clocks on a LAN to submicrosecond precision Designed for LANs, not global: low jitter, low latency Timestamps ideally generated at the MAC or PHY layers to minimize delay and jitter Determine master clock Use a Best Master Clock algorithm to determine which clock in the network is most precise Other clocks become slaves Two phases in synchronization 1. Offset correction 2. Delay correction 42

PTP: Choose the best clock Best Master Clock Distributed election based on properties of clocks Criteria from highest to lowest: Priority 1 (admin-defined hint) Clock class Clock accuracy Clock variance: estimate of stability based on past syncs Priority 2 (admin-defined hint #2) Unique ID (tie-breaker) 43

PTP: Master initiates sync master T 1 time slave T 2 time Master initiates the protocol by sending a sync message containing a timestamp Slave timestamps arrival with a timestamp from its local clock Offset + Delay = T 2 - T 1 44

PTP: Send delay request master T 1 T 4 time slave T 2 T 3 time Slave needs to figure out the network delay. Send a delay request Note the time it was sent. 45

PTP: Receive delay response master T 1 T 4 time slave T 2 T 3 time Master marks the time of arrival and returns it in a delay response Delay response = Delay - Offset = T 4 T 3 46

PTP: Slave computes offset master T 1 T 4 time slave T 2 T 3 time master_slave_difference = T 2 T 1 = delay + offset slave_master_difference = T 4 T 3 = delay offset master_slave_difference slave_master_difference = 2(offset) T 2 T 1 T 4 + T 3 = 2 (offset) offset = (T 2 T 1 T 4 + T 3 ) / 2 47

NTP vs. PTP Range NTP: nodes widely spread out on the Internet PTP: local area networks Accuracy NTP usually several milliseconds on WAN PTP usually sub-microsecond on LAN 48

The end 2014-2017 Paul Krzyzanowski 49