Download presentation
Presentation is loading. Please wait.
Published byAngela Fox Modified over 9 years ago
1
Time and global states Chapter 11
2
Outline Introduction Clocks, events and process states Synchronizing physical clocks Logical time and logical clocks
3
introduction The importance of time: Time is a quantity we often want to measure accurately.(e.g. e-commerce) Algorithms that depend upon clock synchronization have been developed for several problems in distribution: 1. Maintaining the consistency of distributed data 2. Checking the authenticity of request sent to server 3. Eliminating the processing of duplicate updates
4
Important facts : Two events that are judged to be simultaneous in one frame of reference are not necessarily simultaneous according to observers in other frames of references that are moving relative to it. The relative order of two events can even be reversed for two different observers. But this cannot happen if one event could have caused the other to occur. The notion of physical time is also problematic in a DS because of the limitation in our ability to timestamp events at different nodes sufficiently accurately to know the order in which any pair of events occurred, or whether they occurred simultaneously introduction
5
£ A collection of N processes p i, i = 1,2,.. N s i The state of p i E.g. variables Actions of p i Operations that transform p i ’s state Send or receive message between p j Clocks, events and process states
6
e Event: occurrence of a single action i occur before in p i, e.g. e i e` Total order of events in p i history(p i ) = h i h i = Clocks, events and process states
7
A device that count oscillations occurring in a crystal at a definite frequency Hardware time: H i (t) The counts of oscillation since an original point Software time: C i (t) = H i (t)+ Timestamp of an event Clock in computer Successive events will correspond to different timestamps only if the clock resolution is smaller than the time interval between successive events. The rate at which events occur depends on such factor as the length of the processor instruction cycle
8
Clock drift Crystal oscillate at different rate Clock drift can not be avoided Clock skew The instantaneous difference between the readings of any two clocks Clock skew and clock drift
9
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.1 Skew between computer clocks in a distributed system
10
Rotation of earth on its axis and about the Sun Days, Years, etc Second is 1/86400 astronomical time Standard second Atomic oscillator Drift rate: one part in 10 13 Astronomical Time &International Atomic Time
11
shift between astronomical time and atomic time The period of the Earth’s rotation about its axis is gradually getting longer Tidal friction, atmospheric effects, etc Leap second Atomic time which is inserted a leap second occasionally to keep in step with astronomical time Broadcast UTC to the World E.g., by GPS or WWV Coordinated Universal Time (UTC)
12
C i : p i ’s clock I: an interval of real time External synchronization For a synchronization bound D > 0, and for a source S of UTC time, |S(t)-C i (t)| < D, for i = 1, 2, … N and for all real times t in I Clocks C i are accurate to within the bound D Synchronizing physical clocks
13
Internal synchronization For a synchronization bound D > 0, |C i (t)-C j (t)| < D for i, j =1,2, … N, and for all real times t in I Clocks C i agree within the bound D If the system is externally synchronized with a bound D, then the system is internally synchronized with a bound 2D Synchronizing physical clocks
14
Correctness of a hardware clock H A bounded drift rate , e.g. 10 -6 seconds/second,t and t’ are real time (1 - )(t’ - t) <= H(t’) - H(t) <= ( 1 + )( t’ - t) Correctness of a software clock Monotonicity: t’ > t C(t’) > C(t) Set clock back Errors in the make process Change the clock rate General synchronization issues <= ( 1 + ) H(t’) - H(t) (t’ - t) (1 - ) <=
15
Clock failures Crash failure: stop ticking Arbitrary failure, e.g. Y2K bug General synchronization issues (2)
16
Protocol Sender: send M(t) Receiver: set time to t + T trans Bounds are know in synchronous system min < T trans < max (constant) So, set T trans = (min+max) / 2 Receiver’s clock = t + (min+max) / 2 Synchronization in a synchronous system
17
Clock skew between sender and receiver (max – min ) / 2 Synchronization in a synchronous system(2) t t+maxt +T trans t + min
18
Applying circumstance C/S Round-trip time is short compared with the required accuracy Protocol m r, m t (t), T round Estimated time: t in m t + T round /2 Cristian’s method of synchronizing clocks
19
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.2 Clock synchronization using a time server m r m t p Time server,S
20
Accuracy analysis If the minimum delay of a message transmission is min, then accuracy: (T round /2 – min) Cristian’s method of synchronizing clocks (2) t t +T round -min t +T round /2 t + min t +T round
21
Internal synchronization 1. The master polls the slaves’ clocks 2. The master estimates the slaves’ clocks by round-trip time Similar to Christian’s algorithm 3. The master averages the slaves’ clock values Cancel out the individual clock’s tendencies to run fast or slow The Berkeley algorithms
22
4. The master sends back to the slaves the amount that the slaves’ clocks should adjust by Positive or negative value Avoid further uncertainty due to the message transmission time Slave adjust its clock The Berkeley algorithms (2)
23
External synchronization Enable clients across the Internet to be synchronized accurately to UTC Reliability Can survive lengthy losses of connectivity Redundant server & redundant path between servers Design aims of Network Time Protocol
24
Scalability Enable clients to resynchronize sufficiently frequently to offset the rates of drift found in most computers Security Protect against interference with the time service Design aims of Network Time Protocol (2)
25
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.3 An example synchronization subnet in an NTP implementation 1 2 3 2 33 Note: Arrows denote synchronization control, numbers denote strata.
26
Multicast mode Intend for use on a high speed LAN Assuming a small delay Low accuracy but efficient Procedure-call mode Similar to Christian’s Higher accuracy than multicast Symmetric mode The highest accuracy Synchronization measures
27
Symmetric mode synchronization Assumming t, t’: actual transmission time of m, m’; o: actual B’s clock skew relative to A We have T i-2 = T i-3 + t + o, T i = T i-1 + t’ – o T i T i-1 T i-2 T i-3 Server B Server A Time mm' Time
28
Symmetric mode synchronization (2) T i-2 = T i-3 + t + o, T i = T i-1 + t’ – o Then addition : d i = t + t’ = T i-2 –T i-3 + T i – T i-1 subtraction : o = (T i-2 –T i-3 + T i-1 –T i + t’-t )/2 where o i = (T i-2 –T i-3 + T i-1 –T i ) /2 we have o= o i + (t’-t ) /2
29
Symmetric mode synchronization (2) we have o= o i + (t’-t ) /2 Accuracy analysis Due t, t’ >=0, then o i – (t’+t) /2 <= o <= o i + (t’+t) /2 Then o i - d i /2 <= o <= o i + d i /2 o i is the estimated time d i is the measure of the accuracy
30
NTP servers retain 8 most recent pairs The value o i of that corresponds to the minimum value d i is chosen to estimate o A NTP server exchanges with several peers in addition to with parent Peers with lower stratum numbers are favoured Peers with the lowest synchronization dispersion are favoured Symmetric mode sync. implementation
31
Happen-before relation HB1: If process p i : e i e`, then e e` HB2: For any message m, send(m) receive(m) HB3: IF e, e`and e`` are events such that e e` and e` e``, then e e`` Causal ordering Logical time & logical clocks
32
Example a || e Shortcomings Not suitable to processes collaboration that does not involve messages transmission Capture potential causal ordering Happen-before relation
33
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.5 Events occurring at three processes
34
LC1 L i is incremented before each event is issued at process p i : L i :=L i +1 LC2: (a) When a process p i sends a message m, it piggybacks on m the value t = L i (b) On receiving (m,t), a process P j computes L j := max(L j, t) and then applies LC1 before timestamping the event receive(m) Lamport timestamps algorithm
35
e e` L(e) < L(e`) L(e) < L(e`) e e` or e||e` Lamport timestamps algorithm (2)
36
Useful in some applications Totally ordered logical clocks Assumption T i : local timestamp of e that is an event occurring at p i T j : local timestamp of e` that is an event occurring at p j Define the timestamps of e, e` are (T i, i), (T j, j) Define < (T i, i) < (T j, j) if T i < T j, or T i = T j and i < j
37
Each process p i keeps a vector clock V i VC1: Initially, V i [j]=0, for i, j = 1,2…, N VC2: Just before p i timestamps an event, it sets V i [i] := V i [i] +1 VC3: p i includes the value t= V i in every message it sends VC4: When p i receives a timestamp t in a message, it sets V i [j] :=max(V i [j], t[j]), for j=1,2…,N Vector Clocks - algorithm
38
Compare vector timestamps V = V` iff V [j] = V`[j] for j = 1,2…, N V <= V` iff V [j]<=V`[j] for j = 1,2…, N V < V` iff V [j]< V`[j] for j = 1,2…, N Otherwise V<> V` V(e) V(e`) e||e` Vector Clocks - significance
39
Vector Clocks - example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.