TIME AND GLOBAL STATES Đàm Vĩnh Tường (50403056) Nguyễn Lê Anh Đào (50500558) Trần Viễn Phúc (50404435)

Slides:



Advertisements
Similar presentations
1DT066 D ISTRIBUTED I NFORMATION S YSTEM Time, Coordination and Agreement 1.
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.
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2011 August 30, 2011 Lecture 3 Time and Synchronization Reading: Sections
Time and Global States Ali Fanian Isfahan University of Technology
L-8 Synchronizing Physical Clocks 1 Announcements Proj1 checkpoint – due midnight tonight HW1 checkpoint – due 2/12 2.
Distributed Systems Spring 2009
4. Synchronization Clock synchronization
CS 582 / CMPE 481 Distributed Systems Synchronization.
CS 582 / CMPE 481 Distributed Systems
Distributed Systems Fall 2010 Time and synchronization.
Causality & Global States. P1 P2 P Physical Time 4 6 Include(obj1 ) obj1.method() P2 has obj1 Causality violation occurs when order.
Distributed Systems Fall 2009 Logical time, global states, and debugging.
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.
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.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 9: Time, Coordination and Replication Dr. Michael R. Lyu Computer.
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.
Distribuerede systemer – 5. marts 2001 Presentation based on slides by Coulouris et al.
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.
Distributed Systems Foundations Lecture 1. Main Characteristics of Distributed Systems Independent processors, sites, processes Message passing No shared.
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.
1DT066 D ISTRIBUTED I NFORMATION S YSTEM Time, Coordination and Agreement 1.
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.
Parallel and Distributed Simulation Synchronizing Wallclock Time.
Chapter 10: Time and Global States
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
Distributed Systems Fall 2010 Logical time, global states, and debugging.
1 Time (and Global State). 3 Time – basics zWe want to know when something happened - Physical and logical clocks. zAlgorithms may depend upon clock.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
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.
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.
Distributed Systems Concepts and Design Chapter 11: Time and Global States Steve Wallis, Raymond Ho, Bruce Hammer.
Time and global states Chapter 11. Outline Introduction Clocks, events and process states Synchronizing physical clocks Logical time and logical clocks.
Distributed Systems CS Synchronization – Part I Lecture 8, Sep 23, 2013 Mohammad Hammoud.
Distributed Systems Topic 5: Time, Coordination and Agreement
CS 582 / CMPE 481 Distributed Systems Synchronization.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Lecture 4-1 Computer Science 425 Distributed Systems (Fall2009) Lecture 4 Chandy-Lamport Snapshot Algorithm and Multicast Communication Reading: Section.
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 Systems Lecture 6 Global states and snapshots 1.
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.
Distributed Computing
Time and Global States Ali Fanian Isfahan University of Technology
Lecture 5 Time and synchronization
Time and Clock.
Logical time (Lamport)
Time and Clock.
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)
Chap 5 Distributed Coordination
Jenhui Chen Office number:
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

TIME AND GLOBAL STATES Đàm Vĩnh Tường ( ) Nguyễn Lê Anh Đào ( ) Trần Viễn Phúc ( )

Content  Clocks  Synchronizing physical clocks  Logical time and logical clocks  Global states

Education 2007

Clocks, Events, States  Interaction model  Distributed systems consist of collection of N processes p 1, p 2, …, p N –Each process executes on a single processor –Each process has a state s i which it transforms –Processes communicate by sending messages –Each process executes a series of actions: action is  Message Send operation  Message Receive operation  Operation that transforms p i ’s state –Event is occurrence of a single action that process carries out as executes  Sequence of events –e → e’ if event e occurs before e’ in p i –History of process p i :  History(p i ) = h i =

Clocks  How to timestamp events  Each computer owns physical clock –Counts oscillations occurring in a crystal at a definite frequency  Software clock C i (t) = αH i (t) + β –Approximate measure for real, physical time t for process p i : –H i (t) is hardware clock value –α is scale value –β is offset –I.e. could be 64-bit value of the number of nanoseconds that have elapsed at time t since a convenient reference time –Note that successive events will correspond to different timestamps only if clock resolution is smaller than the time interval between successive events

Clocks  Skew between clocks –Instantaneous difference between the readings of any two clocks  Clock drift –Crystal-based clocks count time at different rates and diverge –Physical variations, temperature may affect  Clock’s drift rate –Change in the offset between clock and nominal perfect reference clock –For ordinary clocks about sec/sec, giving a difference of 1 second every second –For ”high precision” clocks to

Clocks  Coordinated Universal Time (UTC)‏ –Most accurate physical clocks use atomic oscillator  Drift rate about one part in  Output is used as standard for elapsed time, International Atomic Time –International standard for timekeeping  Based on atomic time but leap second is inserted  Signals are synchronized and broadcast regularly from radio stations or satellites

Synchronizing Physical Clocks  External synchronization –Processes’ clocks C i are synchronized with authoritative, external source of time –For a synchronization bound D > 0 and for source S of UTC time  |S(t) - C i (t) | < D for i= 1,2,…,N and for all t  Clocks C i are accurate within the bound D  Internal synchronization –Clocks are synchronized with each other to a known degree of accuracy –For a synchronization bound D > 0  |C i (t) - C j (t)| < D for i, j = 1, 2, …, N and for all t  Clocks C i are agreed within the bound D  Clocks that are internally synchronized are not necessarily externally synchronized  If system is externally synchronized within bound D then the same system is internally synchronized with bound of 2D

Synchronizing Physical Clocks  Correctness for clocks –Hardware clock H is correct if its drift rate falls within a known bound ρ > 0 –Error in measuring the interval between real times t and t’ (t’ > t) is bounded  (1- ρ)(t’-t) ≤ H(t’) - H(t) ≤ (1+ ρ)(t’-t)‏  Forbids jumps in the value of hardware clocks –Monotonicity  t’>t => C(t’) > C(t)‏ –Hybrid correctness condition  Clock obeys monotonicity condition  Drift rate is bounded between synchronization points  Allow clock value to jump ahead at synchronization points

Synchronization in Synchronous System  Internal synchonization between two processes  Bounds are known for –Drift rate of clocks –Maximum message transmission delay –Time to execute each step of process  One process sends time t on its local clock to other in a message –Receiver process sets its clock to time t + T trans –T trans is time taken to transmit m  Is subject to variation and is unknown  Minimum transmission time min can be measured or conservatively estimated: no other processes are executed or no other network traffic exist  Let uncertainty in message transmission time be u = max – min  If receiver sets its clock to t + (max + min)/2, then the skew is at most u/2  Optimum bound that can be achieved on clock skew when synchronizing N clocks is u(1 - 1/N)‏  Most distributed systems in practice are asynchronous

Cristian’s Method  Uses UTC-synchronized time server to synchronize computers externally  Upon request server process S supplies the time according to its clock  Round trip times for messages exchanged between pairs of processes are often reasonably short  Method achieves asynchronization only if observed round-trip times are sufficiently short in compared with required accuracy  Steps –Process p requests the time in message m r –Process p receives time value t in a message m t –Process p records the total round-trip time T round m r m t p Time server,S

Cristian’s Method  T round should be in order of 1-10 milliseconds on LAN –Clock with drift rate of sec/sec varies by at most sec  Simple estimate of the time to which p should set its clock is t + T round /2 –Normally reasonable accurate assumption unless two messages are transmitted over different networks  If min is known or can be conservatively estimated, accuracy can be determined –Earliest point at which S could have placed the time in m t was min after p dispached m r –Latest point was min before m t arrived at p –Time by S’s clock when reply message arrives is in range [ t + min, t + T round – min] –Width of range is T round - 2min –Accuracy is +/- (T round /2 - min)‏

Cristian’s Method  Discussion –Problem associated with all services implemented by single server  A group of synchronized time servers  Client could multicast its request –Faulty time server replies with spurious time values –Imposter time server that replies with deliberately incorrect time –Really only suitable for deterministic LAN environment or Intranet

Berkeley Algorithm  For internal synchronization  Coordinator computer acts as master –Polls the other computers, called slaves, whose clocks are to be synchronized –Slaves send back their clock values –Master estimates their local clocks by observing round-trip times and averages the values  Average cancels out individual clock’s tendencies to run fast or slow –Master sends to slaves amount by which each individual slave’s clock requires adjustment  Eliminates readings from faulty clocks –Master takes a fault-tolerant average  Experiment involving 15 computers –Whose clocks were synchronized to within about msec –Local clock’s drift rate less than 2x10 -5 –Maximum round-trip time 10 msec  If master fails, another can be elected to take over and function

Berkeley Education 2007

Network Time Protocol  An architecture for a time service  Protocol to distribute time information over the Internet  Provides a service enabling clients across Internet to be synchronized accurately to UTC  Provides a reliable service that can survive lengthy losses of connectivity  Enables clients to resynchronize sufficiently frequently to offset the rates of drift found in most computers  Provides protection against interference with time service, whether malicious or accidental  Service is provided by a network of servers across the Internet –Primary servers and secondary servers –Forms hierarchy called synchronization subnet; levels are strata –Lowest-level servers execute in users’ workstations –If a strata 1 server fails, it may become a stratum 2 secondary server

Network Time Protocol (NTP)  A time service for the Internet - synchronizes clients to UTC Figure 10.3 Reliability from redundant paths, scalable, authenticates time sources Primary servers are connected to UTC sources Secondary servers are synchronized to primary servers Synchronization subnet - lowest level servers in users’ computers

Network Time Protocol  Servers synchronize with one other in one of three modes: –Multicast  For use on a high-speed LAN  Server periodically multicast the time to other servers  They set their clocks assuming a small delay –Procedure-call  Similar to operation of Christian’s algorithm  Server accepts requests from other computers and replies with timestamp  Suitable where higher accuracies are required or where multicast is not supported in hardware –Symmetric  For servers that supply time information in LANs and by higher levels of synchronization subnet  Where highest accuracies are needed  A pair of servers operating in symmetric mode exchange messages bearing timing information  Messages are delivered using UDP protocol

Network Time Protocol  Procedure-call and symmetric modes –Processes exchange a pairs of messages –Each message bears timestamps of recent message events  Local times when the previous NTP message was sent and received  Local time when the current message was transmitted  Messages m and m’ are sent between servers T i T i-1 T i-2 T i-3 Server B Server A Time mm' 2005

Network Time Protocol  For each pair of messages sent between two servers the NTP calculates –Offset o i : an estimate for the actual offset between two clocks –Delay d i : the total transmission time for two messages –If the true offset of the clock at B relative to that at A is o and actual transmission times for m and m’ are t and t’ respectively  Delay: –T i-2 = T i-3 + t + o and T i = T i-1 + t’ – o leads to –d i = t + t’ = T i-2 - T i-3 + T i - T i-1  Offset –o = o i + (t’ - t)/2, where o i = (T i-2 - T i-3 + T i-1 - T i )/2  Using t, t’ ≥ 0 it can be shown that o i - d i /2 ≤ o ≤ o i + d i /2 – o i is an estimate for o, and d i is a measure of the accuracy of estimate

Network Time Protocol  Servers apply a data filtering algorithm to successive pairs –8 most recent pairs are retained –The value of o i that corresponds to the minimum value d i is chosen to estimate o  NTP server engages in message exchanges with several peers and applies a peer-selection algorithm –Peer with unreliable values may be changed –Peers with lower stratum are more favoured than those in higher strata  NTP employs a phase lock loop model –Modifies the local clock’s update frequency in accordance with observations of its drift rate  Synchronization accuracies in order of tens of msecs over Internet and 1 msec on LAN

Logical time and clocks  Can't synchronize physical clocks perfectly  Absolute time might not be necessary, just need ordering of events  Logical clocks: Lamport, 1978  Happened-before relationship among events  Potential causal ordering

What are Logical Clocks ?  A logical clock is a mechanism for capturing chronological sequence and causal relationships of events in a distributed system.  Clock Implementation –Data structure –Clock Update Protocol  Logical clock algorithms of note are: –Scalar clocks –Vector clocks –Matrix clocks

Happen-before relation  e -> e' –two events occur in the same process –a message is sent between two processes  Happened-before relation: –HB1: if e -> e' in process i, then e -> e' –HB2: for any message m, send(m) -> receive(m) –HB3: if e -> e' and e' -> e'', then e -> e''

Events occurring at three processes

Happen-before vs. causality  e || e' if the two events aren't in a particular order (concurrent)‏  potential causality: e -> e’ doesn't mean that e causes e'  naturally, if e causes e’, e -> e’

Logical Clocks (1/2) ‏

Logical Clocks (2/2) ‏

Lamport timestamps (Fig 11.6) ‏

Total Ordering with Logical Clocks

Vector clocks  Lamport clocks: C(e) e'  each process keeps its own vector clock V i  piggyback timestamps on messages

Vector clocks  updating vector clocks: –VC1: Initially, V i [ j ] := 0 for p i, j=1.. N (N processes)‏ –VC2: before p i timestamps an event, V i [ i ] := V i [ i ]+1 –VC3: p i piggybacks t = V i on every message it sends –VC4: when p j receives a timestamp t, it sets V j [ k ] := max(V j [ k ], t[ k ]) for k=1..N (merge operation)‏

Vector timestamps (Fig 11.7) ‏

Vector clocks  At p i –V i [i] is the number of events p i timestamped locally –V i [j] is the number of events that have occurred at p j (that has potentially affected p i )‏ –Could more events than V i [j] have occurred at p j ?

Comparing vector timestamps  V = V’ iff – V[j] = V’[j], j = 1.. N  V <= V’ iff – V[j] <= V’[j], j = 1.. N  V < V' iff –V <= V' and V != V‘  Different from < in all elements

Vector timestamps  if e -> e', then V(e) < V(e')‏  if V(e) e'. (Exercise 11.13)‏ –Figure 11.7  neither V(c) = V(e)‏  c || e  Disadvantage compared to Lamport timestamps?

Global States  Detecting global 2005

Global States  Essential problem is the absence of global time –Perfect clock synchronization cannot be achieved -> global states cannot be observed from recorded state at agreed time  Global state from local states recorded at different real times?  History of process p i : h i = –each event e i k is either an internal action of process or sending or receiving a message over communication channels  S i k is the state of process p i immediately before the kth event occurs  Processes record sending and receiving of all messages as part of their state  Global history: H = h 0 h 1 … h N-1  Cut of the system’s execution is a subset of its global history that is union of prefixes of process history: –C = h 1 c 1 h 2 c 2... h N c N

Global States  Inconsistent cut –I.e. p 2 includes the receipt of the message m 1, but at p 1 it does not include the sending of message  Consistent cut –I.e. Includes both sending and receipt of message m 1, includes sending but not receipt of message m 2 –Cut C is consistent if, for each event e such it contains, it also contains all events happened-before that event  For all events e C, f → e => f C m 1 m 2 p 1 p 2 Physical time e 1 0 Consistent cut Inconsistent cut e 1 1 e 1 2 e 1 3 e 2 0 e 2 1 e

Global States  Consistent global state –State that corresponds to a consistent cut –Global system state S = (s 1, s 2,.., s N )‏  Global state sequences –Execution of system as series of transitions between global states of the system  S 0 → S 1 → S 2 →...  In each transition precisely one event occurs at some single process in the system  Linearization is an ordering of events in a global history that is consistent with happened-before relation on H  S’ is reachable from a state S if there is a linearization that passes through S and then S’

Chandy-Lamport Algorithm  A snapshot algorithm for determining global states of distributed systems  Goal is to record a set of process and channel states for a set of processes p i such that even though the combination of recorded states may never have occurred at the same time, the recorded global state is consistent  Algorithm records state locally at processes  Assumes that –Neither channels or processes fail: communication is reliable and message is eventually received exactly once –Channels are unidirectional and provide FIFO-order –Graph of processes and channels is strongly connected (there is a path between any two processes)‏ –Any process may initiate a snapshot at any time –The process continues execution while snapshots take place

Chandy-Lamport Algorithm  Idea –Each process records its state and also for each incoming channel a set of messages sent to it –Process records for each channel any messages that arrived after it recorded its state and before the sender recorded its state –Use of marker messages  Prompt for receiver to save its own state  Means of determining which messages to include in the channel state –Two rules  Marker sending rule –Obligates processes to send a marker after they have recorded their state –Before they send any other messages  Marker receiving rule –If process has not recorded its state (this is the first received marker)‏ Obligates process to record its state – If process has already saved its state Records state of that channel as the set of messages it received on since it saved its state

Chandy-Lamport Algorithm Marker receiving rule for process p i On p i ’s receipt of a marker message over channel c: if (p i has not yet recorded its state) it records its process state now; records the state of c as the empty set; turns on recording of messages arriving over other incoming channels; else p i records the state of c as the set of messages it has received over c since it saved its state. end if Marker sending rule for process p i After p i has recorded its state, for each outgoing channel c: p i sends one marker message over c (before it sends any other message over 2005

Chandy-Lamport Algorithm  2005

Chandy-Lamport Algorithm  2005

Chandy-Lamport Algorithm  Termination: –Assumed that a process that has received a marker message records its state within a finite time and sends marker messages over each outgoing channel within finite time –If there is a path of communication channels and processes from p i to p j, then p j will record its state a finite time after p i recorded its state –Since the communication graph is strongly connected, all processes will have recorded their state and the states of incoming channels a finite time after some process initially records its state

Chandy-Lamport Algorithm  Cut and recorded state is consistent –Let e i and e j be events occuring at p i and p j, and let e i → e j –If e j is in the cut, then e i is in the cut. –That is, if e j occurred before p j recorded its state, then e i must have occurred before p i recorded its state  j=i: obvious.  j≠i: –Assume p i recorded its state before e j occurred –Consider the sequence of H messages m 1, m 2,.., m H giving rise to relation e i → e j –Marker message would have received p j ahead of each of m 1,..., m H and p j would have recorded its state before event e j -> contradicts assumption

Summary  Clocks –Hardware clock value is scaled, and offset is added to it –Clock skew is difference in time values –Clock drift: clocks count time at different rates –UTC is international standard for timekeeping  Synchronizing physical clocks –Christian’s method uses time server –Berkeley algorithm: master computer polls the other computers and collects slaves’ clock values –Network Time Protocol: architecture over Internet  Different levels of servers  Lamport’s clocks –Happened-before relation is captured in logical clocks  Vector clocks are an improvement on Lamport clocks –Each process has own vector clock to timestamp local events –Timestamps are piggybacked in message –We can tell whether two events are ordered by happened-before or are concurrent by comparing their vector timestamps  Global states –Snapshot algorithm