CS 3700 Networks and Distributed Systems Time and Logical Clocks Revised 10/03/15.

Slides:



Advertisements
Similar presentations
Time in Distributed Systems
Advertisements

Time and synchronization (“There’s never enough time…”)
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.
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
Distributed Systems Spring 2009
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.
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.
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.
1 CLOCK SYNCHRONIZATION " Synchronization in distributed systems is more complicated than in centralized ones because the former have to use distributed.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
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.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
Distributed Systems Foundations Lecture 1. Main Characteristics of Distributed Systems Independent processors, sites, processes Message passing No shared.
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.
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.
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.
CS 582 / CMPE 481 Distributed Systems Synchronization.
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.
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.
Proof of liveness: an example
Prof. Leonardo Mostarda University of Camerino
Distributed Computing
Time and Clock Primary standard = rotation of earth
CSE 486/586 Distributed Systems Logical Time
Time and Global States Ali Fanian Isfahan University of Technology
Lecture 5 Time and synchronization
CS 3700 Networks and Distributed Systems
CSE 486/586 Distributed Systems Logical Time
Time and Clock.
Logical time (Lamport)
湖南大学-信息科学与工程学院-计算机与科学系
CS 3700 Networks and Distributed Systems
Time and Clock.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Distributed Synchronization
Logical time (Lamport)
Logical time (Lamport)
Chap 5 Distributed Coordination
CSE 486/586 Distributed Systems Logical Time
CSE 486/586 Distributed Systems Time and Synchronization
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

CS 3700 Networks and Distributed Systems Time and Logical Clocks Revised 10/03/15

Global Time 2  In practice, we act like there is a global notion of time  But, time is relative  Einstein showed speed of light constant for all observers  Leads to Relativity of Simultaneity  Basically, impossible to tell if two events are simultaneous  If events are separated by space  But, if events are causally connected, we can preserve ordering

Global Time in Systems 3  For human-scale systems, these time differences don’t matter  Rarely are we going near the speed of light  But these do come to play in computing systems  Must consider relativity of time when designing systems  Examples: High-frequency trading systems – Who bought/sold first? Merging multiple writes to single object Online games – Who shot first? Did you heal before or after the attack?

Defining and Measuring Time Correcting Clocks and NTP Logical Clocks Vector Clocks Outline 4

Historical Clocks 5  Our units of time date from the Sumerians in 2000BC  Humans used a variety of devices to measure time  Sundials  Astronomical clocks  Candle clocks  Hourglasses  Mechanical clocks developed in medieval ages  Typically maintained by monks (church bell tower)

Measuring Real-world Time 6  Originally, each town defined noon locally  Point at which sun highest in the sky  With growth of railroads, this became impractical  Continually have to re-set watches  Hard to set rail schedules  Notion of “time zones” developed  Regions where wall-clock time is the same  Now, need to synchronize clocks

GMT, UT1, and UTC 7  GMT: Greenwich Mean Time  Originally, mean solar time at 0º longitude  This isn’t really “noon” due to Earth’s axial tilt  UT1: Universal Time  Modernized version of GMT  Based on rotation of Earth, ~86,400 seconds/day  UTC: Universal Coordinated Time  UT1 + leap seconds  Minutes can have seconds  Since 1972, 25 leap seconds have been introduced

Electrical Clocks 8  First developed in 1920s  Uses carefully shaped quartz crystal  Pass current, counts oscillations  Most oscillate at 32,768/sec  Easy to count in hardware  Small enough to fit (~4mm)  Typical quartz clock quite accurate  Within 15 sec/30 days (6e-6)  Can achieve 1e-7 accuracy in controlled conditions  Not good enough for today’s applications

Atomic Clocks 9  Based on atomic physics  Cool atoms to near absolute zero  Bombard them with microwaves  Count transitions between energy levels  Most accurate timekeeping devices today  Accurate to within seconds per day  E.g., loses 1 second in 30 million years  SI second now defined in terms of atomic oscillations  9,192,631,770 transitions of cesium-133 atom

International Atomic Time 10  Atomic clocks used to define a number of time standards  TAI: International Atomic Time  Avg. of 200 atomic clocks, corrected for time dilation  Essentially, a count of the number of seconds passed  Count was 0 on Jan. 1, 1958

Defining and Measuring Time Correcting Clocks and NTP Logical Clocks Vector Clocks Outline 11

Correctness 12  What does it mean for a clock to be correct?  Relative to an “ideal” clock  Clock skew is magnitude, clock drift is difference in rates  Say clock is correct within p if (1-p)(t’-t) ≤ H(t’) - H(t) ≤ (1+p)(t’-t)  (t’-t) True length of interval  H(t’) - H(t) Measured length of interval  (1-p)(t’-t) Smallest acceptable measurement  (1+p)(t’-t) Largest acceptable measurement  Monotonic property: t < t’ ⇒ H(t) < H(t’)

Monotonicity 13  If a clock is running “slow” relative to real time  Can simply re-set the clock to real time  Doesn’t break monotonicity  But, if a clock is running “fast”, what to do?  Re-setting the clock back breaks monotonicity  Imagine programming with the same time occurring twice  Instead, “slow down” clock  Maintains monotonicity

Simple Synchronization 14  If we know message delay T  A sends current time t to B, who sets time to t+T  Typically, don’t know exact delay  May know range on delay min < T < max  B can then set time to t+(max-min)/2  Clocks are then within (max-min)/2 of each other  Can generalize this protocol to many clocks  Overall accuracy still ~(max-min)  But, don’t generally have any bound on delay

Cristian’s Method 15  No assumption of delay bound  A sends request to B of current time  B responds with local time T  A measures RTT  A sets local time to T+RTT/2  Assumes that delay is symmetric  Why?  A can do this many times in a row, use overall min RTT  Rough accuracy is RTT/2 - min, with overall minimum min Time? T RTT Sample A B

Synchronization in the Real-world 16  Network Time Protocol (NTP) developed in 80s with goals  Keep machines synchronized to UTC  Deal with lengthy losses of connectivity  Enable clients to synchronized frequently (scalable)  Avoid security attacks  NTP deployed widely today  Uses 64-bit value, epoch is 1/1/1900 (rollover in 2036)  LANs: Precision to 1ms  Internet: Precision to 10s of ms

NTP Hierarchy 17  Based on hierarchy of accuracy, called strata  Stratum 0: High-precision atomic clocks  Stratum 1: Hosts directly connected to atomic clocks  Stratum 2: Hosts that run NTP with stratum 1 hosts  Stratum 3: Hosts that run NTP with stratum 2 hosts  …  Stratum x hosts often synch with other stratum x hosts  Provides redundancy

NTP in Practice 18  Run on UDP port 123  Most Internet hosts support NTP  Accuracy on general Internet is ~10ms  Up to 1ms on local networks, ideal conditions  Many networks run local NTP servers  E.g., time.ccs.neu.edu  NTP has recently been a vector for DDoS attacks  Best practice is for servers to filter requests outside local network

Defining and Measuring Time Correcting Clocks and NTP Logical Clocks Vector Clocks Outline 19

Logical Ordering 20  Problem: even with NTP, time synchronization is still approximate  In a cluster of machines, clocks may be skewed by 1ms or more  Some applications cannot tolerate such high skew  Goal: Be able to provide some synchronization of events  Create a new abstraction: Logical ordering  Remove real-world time from equation  Base ordering on causality  Logical clocks are based on the simple principles:  1. Events observed by a single process are ordered  2. Any message must be sent before it is received

Example of Logical Ordering 21  Each host can order all events it observes  B observes m1 received before m3 sent  Can “interleave” timelines via messages  Cannot make statement about all pairs of events  E.g., m5 send and m1 receive can’t be ordered A B C D m1 m2 m3 m4 m5

Happened-before Relation 22  Formalize logical clocks via happened-before ( → ) relation  If e1 precedes e2 on single host, then e1 → e2  e1 → e2 and e2 → e3, then e1 → e3 (transitivity)  If neither e1 → e2 nor e2 → e1, then e1 and e2 are concurrent  Say e1 || e2 A B C D m1 m2 m3 m4 m5

Limits of Happened-before 23  Cannot capture external events  Only considers message-passing  Two events may be concurrent in our system  If e1 || e2, it does not imply causality  Potential causality is implied  E.g., process may receive message before unrelated event  But, still pretty useful  How to implement logical ordering in a real system?

Logical Clocks 24  Turing Award winner Leslie Lamport invented a way to create logical clock from ordering  Define logical clock to be a monotonically increasing value  Number is abstract, meaningless value by itself  Each host i maintains internal logical clock Li  Li is incremented after each event  Li logical timestamp is included in each message sent  Upon receipt of message with logical timestamp t Li = max(Li, t) + 1

No Reverse Implication 25  We can observe that e1 → e2 ⇒ L(e1) < L(e2)  If e1 happened before e2, then logical clocks ordered  But the reverse is not true  L(e1) < L(e2) ⇏ e1 → e2  For example, L(e) < L(b), but e ↛ b  In fact, e concurrent with all but f A B C a b c d e f

Defining and Measuring Time Correcting Clocks NTP Logical Clocks Vector Clocks Outline 26

Vector Clocks 27  Developed to overcome lack of reverse implication  Want L(e1) < L(e2) ⇒ e1 → e2  Processes keep local vector clock Vi  Array of logical clocks of length N (# processes)  Initially [0,0, … 0]  Similar update procedure to logical clocks  Vi[i] is incremented after each event  Vi is inserted into each message sent  Upon receipt of message with vector clock Vk Vi[x] = max(Vi[x], Vk[x]), for all x

Vector Clock Example 28  Invariant: Vi[b] is the number of events in process P b that happened before the current state of process P a A B C D m1 m2 m3 m4 m5 m6m6 [1,0,0,0] [2,3,0,0] [3,3,4,0] [1,1,0,0] [1,2,0,0] [1,3,0,0] [1,2,3,0] [1,2,4,0] [0,0,1,0] [0,0,2,0] [0,0,1,1] [0,0,2,2] Vector Key: [L A, L B, L C, L D ] ? ? ?

Comparing Vector Timestamps 29  Given two vector timestamps Vi and Vj  Vi = Vj iff Vi[x] = Vj[x] for all x  Vi < Vj iff Vi[x] < Vj[x] for all x  For example: (2,4,1) < (3,5,9)  But, other pairs incomparable  E.g., (2,4,1) and (3,1,7)  As with logical clocks e1 → e2 ⇒ L(e1) < L(e2)  And also L(e1) < L(e2) ⇒ e1 → e2

Vector vs. Logical Clocks 30  Vector clocks augment logical clocks  Use generalization of same mechanism  Both can say when certain events happened before each other  But, only vector clocks allow you to compare events across processes  Challenges with vector clocks  Larger messages, more complexity  Often don’t know total number of processes (N)  N may change while your system is executing  Vector clocks can be extended to matrix clocks  Your logical clock + others’

The Future? 31  Spanner: Google’s Globally-Distributed Database  Corbett et al., OSDI 2012  nner-osdi2012.pdf nner-osdi2012.pdf  Highly available, highly consistent, load balanced database  Special “time master” servers equipped with GPS antenna and atomic clocks  Apparently atomic clocks aren’t too expensive (for Google)  Cluster machines synchronize with the masters every 30 seconds