PHYSICAL AND LOGICAL TIME EE324 Lecture 11 Last Time– RPC  Why remote procedure calls?  Simple way to pass control and data  Elegant transparent way.

Slides:



Advertisements
Similar presentations
Time and synchronization (“There’s never enough time…”)
Advertisements

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.
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
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Exercises for Chapter 14: TIME.
L-8 Synchronizing Physical Clocks 1 Announcements Proj1 checkpoint – due midnight tonight HW1 checkpoint – due 2/12 2.
Distributed Systems Spring 2009
CS 582 / CMPE 481 Distributed Systems Synchronization.
Distributed Systems Fall 2010 Time and synchronization.
Slides for Chapter 10: Time and Global State
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.
Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley Copyright © George Coulouris, Jean Dollimore, Tim.
Lecture 13 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Last quiz Max: 69 / Median: 52 / Min: 24 In a box outside.
1 Slides for Chapter 10: Time (and Global State) From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
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.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
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.
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.
Lecture 9 – Time Synchronization Distributed Systems.
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.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Mutex EE324 Lecture 11.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
TIME AND GLOBAL STATES Đàm Vĩnh Tường ( ) Nguyễn Lê Anh Đào ( ) Trần Viễn Phúc ( )
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
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.
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.
Lecture 9 – Time Synchronization
Time and global states Chapter 11. Outline Introduction Clocks, events and process states Synchronizing physical clocks Logical time and logical clocks.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems Topic 5: Time, Coordination and Agreement
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.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Hwajung Lee. Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
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.
Distributed Computing
Distributed Systems Time Synchronization.
Time and Global States Ali Fanian Isfahan University of Technology
Distributed Mutex EE324 Lecture 11.
Time Synchronization and Logical Clocks
Time and Clock.
Logical time (Lamport)
Time and Clock.
Exercises for Chapter 11: TIME AND GLOBAL STATES
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Slides for Chapter 11: Time and Global State
Logical time (Lamport)
Logical time (Lamport)
Slides for Chapter 14: Time and Global States
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Outline Theoretical Foundations
Presentation transcript:

PHYSICAL AND LOGICAL TIME EE324 Lecture 11

Last Time– RPC  Why remote procedure calls?  Simple way to pass control and data  Elegant transparent way to distribute application  Goal: provide transparency (or hide complexity)  Hard to provide true transparency  Failures   Performance   Memory access   Etc.  What did we do in the end?  give up and let programmer deal with it 2

Today  Reading: CDK5 chapter / TV chapter  Understanding time in distributed systems  Synchronizing physical clocks (real clocks)  Logical Time/Lamport Clock

Time Example  3 Professors having dinner.  3 counters in different locations.  They sneak out and pay at different counters.  Who made the first payment?

Skew between computer clocks in a distributed system  Computer clocks are not generally in perfect agreement  Skew: the difference between the times on two clocks (at any instant)  Computer clocks are subject to clock drift (they count time at different rates)  Clock drift rate: the difference per unit of time from some ideal reference clock  Ordinary quartz clocks drift by about 1 sec in days. (10 -6 secs/sec).  High precision quartz clocks drift rate is about or secs/sec

Coordinated Universal Time  UTC is an international standard for time keeping  International Atomic Time is based on very accurate physical clocks (drift rate )  It is based on atomic time, but occasionally adjusted to astronomical time  It is broadcast from radio stations on land and satellite (e.g. GPS)  Computers with receivers can synchronize their clocks with these timing signals

Coordinated Universal Time (UTC)  Signals from land-based stations are accurate to about millisecond  Signals from GPS are accurate to about 1 microsecond  Why can't we put GPS receivers on all our computers? 7

Clock Synchronization Algorithms  The relation between clock time and UTC when clocks tick at different rates. 8

Impact of Clock Synchronization  When each machine has its own clock, an event that occ urred after another event may nevertheless be assigned an earlier time. 9

10 Need for Precision Time  Social networking services  Stock market buy and sell orders  Secure document timestamps (with cryptographic certification)  Aviation traffic control and position reporting  Radio and TV programming launch and monitoring  Intruder detection, location and reporting  Multimedia synchronization for real-time teleconferencing  Interactive simulation event synchronization and ordering  Network monitoring, measurement and control  Early detection of failing network infrastructure devices and air conditioning equipment  Differentiated services traffic engineering  Distributed network gaming and training

Today  Reading: CDK5 chapter / TV chapter  Understanding time in distributed systems  Synchronizing physical clocks (real clocks)  Logical Time/Lamport Clock

Perfect networks  Messages always arrive, with propagation delay exactly d  Sender sends time T in a message  Receiver sets clock to T+d  Synchronization is exact

Synchronous networks  Messages always arrive, with propagation delay at most D  Sender sends time T in a message  Receiver sets clock to T + D/2  Synchronization error is at most D/2

Synchronization in the real world  Real networks are asynchronous  Propagation delays are arbitrary  Real networks are unreliable  Messages don’t always arrive

Cristian’s Time Sync m r m t p Time server,S  A time server S receives signals from a UTC source  Process p requests time in m r and receives t in m t from S  p sets its clock to t + T round /2  Window: [t +min, t + T round – min]  Size: T round – 2 min  Accuracy: ± (T round /2 - min)  Min is the minimum transmission time of a message. T round is the round trip time recorded by p min is an estimated minimum round trip time 15

Berkeley algorithm  Cristian’s algorithm  a single time server might fail. Must use a group of synchronized servers.  Assumes the server’s clock is always perfect.  Berkeley algorithm (also 1989)  An algorithm for internal synchronization of a group of computers  Master uses Cristian’s algorithm to get time from many slaves  It takes an average (can discard outliers).  It sends the required adjustment to the slaves  If master fails, can elect a new master to take over (not in bounded time) 16

The Berkeley Algorithm (1)  The time daemon asks all the othe r machines for their clock values.  Master uses Cristian’s algorithm to get time from many slaves

The Berkeley Algorithm (2)  The machines answer.  Master uses Cristian’s algorithm to get time from many slaves

The Berkeley Algorithm (3)  The time daemon tells everyone how to adjust their clock.

The Network Time Protocol (NTP) Note: Arrows denote synchronization control, numbers denote strata.

NTP Protocol  All modes use UDP  Each message bears timestamps of recent events:  Local times of Send and Receive of previous message  Local times of Send of current message  Recipient notes the time of receipt T i (we have T i-3, T i-2, T i-1, T i )  In symmetric mode there can be a non-negligible delay between messa ges 21 T i T i-1 T i-2 T i-3 Server B Server A Time mm' Time

Accuracy of NTP  For each pair of messages between two servers, NTP estimates an offset o, between the tw o clocks and a delay d i (total time for the two messages, which take t and t’) T i-2 = T i-3 + t + o and T i = T i-1 + t’ - o  This gives us (by adding the equations) : d i = t + t’ = T i-2 - T i-3 + T i - T i-1  Also (by subtracting the equations) o = o i + (t’ - t )/2 where o i = (T i-2 - T i-3 + T i-1 - T i )/2  Using the fact that t, t’>0 it can be shown that o i - d i /2 ≤ o ≤ o i + d i /2.  Thus o i is an estimate of the offset and d i is a measure of the accuracy  NTP servers filter pairs, estimating reliability from variation, allowing them to selec t peers. Select o i that corresponds to the minimum value d i to estimate o.  Accuracy of 10s of millisecs over Internet paths (1 on LANs) 22

How To Change Time  Can’t just change time  Why not?  Change the update rate for the clock  Changes time in a more gradual fashion  Prevents inconsistent local timestamps 23

Summary  Real synchronization is imperfect.  Clocks never exactly synchronized.  Often inadequate for distributed systems  might need totally-ordered events  might need millionth-of-a-second precision

Today  Reading: CDK5 chapter / TV chapter  Understanding time in distributed systems  Synchronizing physical clocks (real clocks)  Logical Time/Lamport Clock

Lamport’s Logical Clocks (1) The "happens-before" relation → can be observed directly in two situations :  If a and b are events in the same process, and a occurs before b, then a → b is true.  If a is the event of a message being sent by one process, and b is the eve nt of the message being received by another process, then a → b 26

Global logical time  Definition (→): We define e → e’ using the following rules:  Local ordering: e → e’ if e → i e’ for any process i  Messages: send(m) → receive(m) for any message m  Transitivity: e → e’’ if e → e’ and e’ → e’’  We say e “happens before” e’ if e → e’

Concurrency  → is only a partial-order  Some events are unrelated  Definition (concurrency): We say e is concurrent with e’ (writte n e║e’) if neither e → e’ nor e’ → e

Lamport logical clocks  Lamport clock L orders events consistent with logical “happens b efore” ordering  If e → e’, then L(e) < L(e’)  But not the converse  L(e) < L(e’) does not imply e → e’  Similar rules for concurrency  L(e) = L(e’) implies e║e’ (for distinct e,e’)  e║e’ does not imply L(e) = L(e’)  i.e., Lamport clocks arbitrarily order some concurrent events

Lamport’s algorithm  Each process i keeps a local clock, L i  Three rules: 1. At process i, increment L i before each event 2. To send a message m at process i, apply rule 1 and then include the cu rrent local time in the message: i.e., send(m,L i ) 3. To receive a message (m,t) at process j, set L j = max(L j,t) and then appl y rule 1 before time-stamping the receive event  The global time L(e) of an event e is just its local time  For an event e at process i, L(e) = L i (e)

Lamport’s Logical Clocks (2)  Three processes, each with its own clock. The clocks run at different rates. 31

Lamport’s Logical Clocks (3)  Lamport’s algorithm corrects the clocks. 32

Lamport’s Logical Clocks  The positioning of Lamport’s logical clocks in distributed systems: typicall in the middleware layer 33

Total-order Lamport clocks  Many systems require a total-ordering of events, not a partial-or dering  Use Lamport’s algorithm, but break ties using the process ID  L(e) = M * L i (e) + i M = maximum number of processes

Vector Clocks  Vector clocks overcome the shortcoming of Lamport logical clocks  L(e) < L(e’) does not imply e happened before e’  Goal  Want ordering that matches causality  V(e) < V(e’) if and only if e → e’  Method  Label each event by vector V(e) [c 1, c 2 …, c n ] c i = # events in process i that causally precede e

Vector Clock Algorithm  Initially, all vectors [0,0,…,0]  For event on process i, increment own c i  Label message sent with local vector  When process j receives message with vector [d 1, d 2, …, d n ]:  Set local each local entry k to max(c k, d k )  Increment value of c j

Vector Clocks  Vector clocks overcome the shortcoming of Lamport logical clocks  L(e) < L(e’) does not imply e happened before e’  Vector timestamps are used to timestamp local events  They are applied in schemes for replication of data 37

Vector Clocks  At p 1  a occurs at (1,0,0); b occurs at (2,0,0); piggyback (2,0,0) on m 1  At p 2 on receipt of m 1 use max ((0,0,0), (2,0,0)) = (2, 0, 0) and add 1 to o wn element = (2,1,0)  Meaning of =, <=, max etc for vector timestamps  compare elements pairwise 38

Vector Clocks  Note that e  e’ implies L(e)<L(e’). The converse is also true  Can you see a pair of parallel events?  c || e( parallel) because neither V(c) <= V(e) nor V(e) <= V(c) 39

Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 Figure 14.6 Lamport timestamps for the events shown in Figure 14.5

Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 Figure 14.7 Vector timestamps for the events shown in Figure 14.5

Important Lessons  Clocks on different systems will always behave differently  Skew and drift between clocks  Time disagreement between machines can result in undesirable behavior  Two paths to solution: synchronize clocks or ensure consistent clocks  Clock synchronization  Rely on a time-stamped network messages  Estimate delay for message transmission  Can synchronize to UTC or to local source 42

Announcements  PA2  Midterm  In the process of making it.  Written exam: take home exam. Honor code. Only textbook and lecture notes. No discussion. No Internet. Will give you about 1.5 days.  Programming part: we will give you more time. Can use the Internet, but no discussion.  PA3