Time and Synchronization

Slides:



Advertisements
Similar presentations
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.
Advertisements

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
CS 582 / CMPE 481 Distributed Systems Synchronization.
Distributed Systems Fall 2010 Time and synchronization.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley Copyright © George Coulouris, Jean Dollimore, Tim.
Distributed Systems CS Synchronization – Part II Lecture 8, Sep 28, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
CS542: Topics in Distributed Systems Diganta Goswami.
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.
Distributed Systems Foundations Lecture 1. Main Characteristics of Distributed Systems Independent processors, sites, processes Message passing No shared.
Synchronization Chapter 6 Part I Clock Synchronization & Logical clocks Part II Mutual Exclusion Part III Election Algorithms Part IV Transactions.
Lecture 2-1 CS 425/ECE 428 Distributed Systems Lecture 2 Time & Synchronization Reading: Klara Nahrstedt.
Lecture 3-1 Computer Science 425 Distributed Systems Lecture 3 Logical Clock and Global States/ Snapshots Reading: Chapter 11.4&11.5 Klara Nahrstedt.
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.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
1 Distributed Systems CS 425 / CSE 424 / ECE 428 Global Snapshots Reading: Sections 11.5 (4 th ed), 14.5 (5 th ed)  2010, I. Gupta, K. Nahrtstedt, S.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
CSE 486/586 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
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.
Lecture 5-1 Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013 Indranil Gupta (Indy) September 10, 2013 Lecture 5 Time and Synchronization.
Time and global states Chapter 11. Outline Introduction Clocks, events and process states Synchronizing physical clocks Logical time and logical clocks.
Distributed Systems Topic 5: Time, Coordination and Agreement
CS 582 / CMPE 481 Distributed Systems 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.
Lecture 12-1 Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2012 Indranil Gupta (Indy) October 4, 2012 Lecture 12 Mutual Exclusion.
Distributed Systems Lecture 5 Time and synchronization 1.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
Indranil Gupta (Indy) Topic: Time and Ordering Lecture A: Introduction and Basics Cloud Computing concepts All slides © IG.
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.
Proof of liveness: an example
Time, Clocks, and Global State Part-2
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
CSE 486/586 Distributed Systems Time and Synchronization
Time and Synchronization
CSE 486/586 Distributed Systems Logical Time
Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013
Time and Clock.
Logical time (Lamport)
湖南大学-信息科学与工程学院-计算机与科学系
Lecture 12: Time and Ordering
Distributed Systems CS
Time and Clock.
CS 425 / ECE 428  2013, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou.
Chapter 5 (through section 5.4)
Physical clock synchronization
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Lecture 8 Processes and events Local and global states Time
Logical time (Lamport)
Logical time (Lamport)
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
Outline Theoretical Foundations
Presentation transcript:

Time and Synchronization Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2010 Indranil Gupta (Indy) September 7, 2010 Lecture 5 Time and Synchronization Reading: Sections 11.1-11.4  2010, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou

Why synchronization? You want to catch the 10 Gold West bus at the Illini Union stop at 6.05 pm, but your watch is off by 15 minutes What if your watch is Late by 15 minutes? What if your watch is Fast by 15 minutes? Synchronization is required for Correctness Fairness

Why synchronization? Servers in the cloud need to timestamp events Server A and server B in the cloud have different clock values You buy an airline ticket online via the cloud It’s the last airline ticket available on that flight Server A timestamps your purchase at 9h:15m:32.45s What if someone else also bought the last ticket (via server B) at 9h:20m:22.76s? What if Server A was > 10 minutes ahead of server B? Behind? How would you know what the difference was at those times? Synchronization is required for Fairness Correctness

Basics – Processes and Events An Asynchronous Distributed System (DS) consists of a number of processes. Each process has a state (values of variables). Each process takes actions to change its state, which may be an instruction or a communication action (send, receive). An event is the occurrence of an action. Each process has a local clock – events within a process can be assigned timestamps, and thus ordered linearly. But – in a DS, we also need to know the time order of events across different processes. Clocks across processes are not synchronized in an asynchronous DS (unlike in a multiprocessor/parallel system, where they are). So… Process clocks can be different Need algorithms for either (a) time synchronization, or (b) for telling which event happened before which Software timers

Physical Clocks & Synchronization In a DS, each process has its own clock. Clock Skew versus Drift Clock Skew = Relative Difference in clock values of two processes Clock Drift = Relative Difference in clock frequencies (rates) of two processes A non-zero clock drift will cause skew to continuously increase. Maximum Drift Rate (MDR) of a clock Absolute MDR is defined relative to Coordinated Universal Time (UTC) MDR of a process depends on the environment. Max drift rate between two clocks with similar MDR is 2 * MDR Max-Synch-Interval = (MaxAcceptableSkew—CurrentSkew) / (MDR * 2)

Synchronizing Physical Clocks Ci(t): the reading of the software clock at process i when the real time is t. External synchronization: For a synchronization bound D>0, and for source S of UTC time, for i=1,2,...,N and for all real times t. Clocks Ci are accurate to within the bound D. Internal synchronization: For a synchronization bound D>0, for i, j=1,2,...,N and for all real times t. Clocks Ci agree within the bound D. External synchronization with D  Internal synchronization with 2D Internal synchronization with D  External synchronization with ??

Clock Synchronization Using a Time Server p Time server,S

Cristian’s Algorithm Uses a time server to synchronize clocks Time server keeps the reference time (say UTC) A client asks the time server for time, the server responds with its current time, and the client uses the received value T to set its clock But network round-trip time introduces an error… Let RTT = response-received-time – request-sent-time (measurable at client) Also, suppose we know (1) the minimum value min of the client-server one-way transmission time [Depends on what?] (2) that the server timestamped the message at the last possible instant before sending it back Then, the actual time could be between [T+min,T+RTT— min] What are the two extremes?

Cristian’s Algorithm (2) Client sets its clock to halfway between T+min and T+RTT— min i.e., at T+RTT/2  Expected (i.e., average) skew in client clock time will be = half of this interval = (RTT/2 – min) Can increase clock value, but should never decrease it – Why? Can adjust speed of clock too (take multiple readings) – either up or down is ok. For unusually long RTTs, repeat the time request For non-uniform RTTs, use weighted average Works for smaller rtt’s avg-clock-error0 = local-clock-error avg-clock-errorn = (Wn * local-clock-error) + (1 – Wn) * local-clock-errorn-1

Berkeley Algorithm Uses an elected master process to synchronize among clients, without the presence of a time server The elected master broadcasts to all machines requesting for their time, adjusts times received for RTT & latency, averages times, and tells each machine how to adjust. Multiple leaders may also be used.  Averaging client’s clocks may cause the entire system to drift away from UTC over time  Failure of the master requires some time for re-election, so accuracy cannot be guaranteed Main adv: can elect master

The Network Time Protocol (NTP) Uses a network of time servers to synchronize all processes on a network. Time servers are connected by a synchronization subnet tree. The root is in touch with UTC. Each node synchronizes its children nodes. Primary server, direct synch. 1 Secondry servers, synched by the primary server Main adv: f-t of av. and accuracy. Synch: multicast mode or procedure call mode (~Cristian’s algorithm) or symmetric mode (next slide) 2 2 2 Strata 3, synched by the secondary servers 3 3 3 3 3 3

Messages Exchanged Between a Pair of NTP Peers (“Connected Servers”) -2 - 3 Server B Server A Time m m' Each message bears timestamps of recent message events: the local time when the previous NTP message was sent and received, and the local time when the current message was transmitted.

Theoretical Base for NTP -2 - 3 Server B Server A Time m m' t and t’: actual transmission times for m and m’ o: true offset of the clock at B relative to that at A oi: estimate of the actual offset between the two clocks di: estimate of accuracy of oi ; total transmission times for m and m’; di=t+t’

Logical Clocks Is it always necessary to give absolute time to events? Suppose we can assign relative time to events, in a way that does not violate their causality Well, that would work – that’s how we humans run their lives without looking at our watches for everything we do First proposed by Leslie Lamport in the 70’s Define a logical relation Happens-Before () among events: On the same process: a  b, if time(a) < time(b) If p1 sends m to p2: send(m)  receive(m) (Transitivity) If a  b and b  c then a  c Lamport Algorithm assigns logical timestamps to events: All processes use a counter (clock) with initial value of zero A process increments its counter when a send or an instruction happens at it. The counter is assigned to the event as its timestamp. A send (message) event carries its timestamp For a receive (message) event the counter is updated by max(local clock, message timestamp) + 1 Motivations compared to previous slides: errors, and such fine-grained synch may not be required.

Events Occurring at Three Processes

Lamport Timestamps

Find the Mistake: Lamport Logical Time Physical Time p 1 1 2 4 3 1 4 p 2 3 2 2 3 6 p 3 4 3 5 6 8 4 7 p 4 5 6 7 n Clock Value timestamp Message

Corrected Example: Lamport Logical Time Physical Time p 1 1 2 8 7 1 8 p 2 3 2 2 3 and 7 are logically concurrent events 3 6 p 3 4 3 5 9 10 4 7 p 4 5 6 7 n Clock Value timestamp Message

Vector Logical Clocks X With Lamport Logical Timestamp e “happens-before” f  timestamp(e) < timestamp (f), but timestamp(e) < timestamp (f)  e “happens-before” f Vector Logical time addresses this issue: All processes use a vector of counters (logical clocks), ith element is the clock value for process i, initially all zero. Each process i increments the ith element of its vector upon an instruction or send event. Vector value is timestamp of the event. A send(message) event carries its vector timestamp (counter vector) For a receive(message) event, Max(Vreceiver[j] , Vmessage[j]), if j is not self Vreceiver[j] + 1 otherwise X Vreceiver[j] =

Vector Timestamps

Example: Vector Logical Time Physical Time (1,0,0,0) 1,0,0,0 1,1,0,0 2,0,0,0 2,0,1,0 (2,0,0,0) 4,0,2,2 4,2,4,2 (4,0,2,2) p 1 0,0,0,0 2,0,2,2 3,0,2,2 (2,0,2,2) p 2 1,2,0,0 2,2,3,0 (1,2,0,0) 0,0,0,0 p 3 2,0,2,0 2,0,2,1 (2,0,2,0) 0,0,0,0 2,0,2,3 4,2,5,3 (2,0,2,3) p 4 0,0,0,0 n,m,p,q Vector logical clock (vector timestamp) Message

Comparing Vector Timestamps VT1 = VT2, iff VT1[i] = VT2[i], for all i = 1, … , n VT1 < VT2, iff VT1[i] < VT2[i], for all i = 1, … , n iff VT1 < VT2 &  j (1 < j < n & VT1[j] < VT2 [j]) VT1 is concurrent with VT2 iff (not VT1 < VT2 AND not VT2 < VT1)

Summary, Announcements Time synchronization important for distributed systems Cristian’s algorithm Berkeley algorithm NTP Relative order of events enough for practical purposes Lamport’s logical clocks Vector clocks Next class: Global Snapshots. Reading: 11.5 HW1 due this Thursday at beginning of class MP1 – Real Implementation required (no simulation, no abstraction) Please report your groups to us by this Thursday (subject line: “425 Groups”)