Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Time (and Global State). 3 Time – basics zWe want to know when something happened - Physical and logical clocks. zAlgorithms may depend upon clock.

Similar presentations


Presentation on theme: "1 Time (and Global State). 3 Time – basics zWe want to know when something happened - Physical and logical clocks. zAlgorithms may depend upon clock."— Presentation transcript:

1 1 Time (and Global State)

2

3 3 Time – basics zWe want to know when something happened - Physical and logical clocks. zAlgorithms may depend upon clock synchronization. zNo global notion of time.

4 4 Time – system model zN processes: yEach executes on a single processor. yNo shared memory. yOnly communication means is exchange of messages. zpi has state si. zAn event is the occurrence of a single action, i.e.: y An internal state-transforming action by pi, or y a communication action. ze  i e’ if e occurs before e’ in pi.

5 5 Time – clocks zEach computer has its own physical clock. zThe software clock Ci can be used to timestamp any event at pi. zProblems: Clock skew and clock drift.

6 6 Time – Coordinated Universal Time (UTC) zInternational standard for timekeeping. zBased on atomic time. zSynchronizes with astronomical time using leap seconds. zUTC signals are synchronized and broadcast regularly from land-based radio stations and satellites. zComputers with receivers attached can synchronize their clocks with these timing signals.

7 7 Synchronizing physical clocks – basics zExternal synchronization: For each i, synchronize Ci with an authoritative, external source of time. zInternal synchronization: For each i,j, synchronize Ci and Cj with each other. zOther issues: Correctness, monotonicity, faulty clocks, crash failures, arbitrary failures.

8 8 Synchronizing physical clocks – in a synchronous system zInternal synchronization. zSender sends local time t to receiver. zReceiver ideally sets time to: t + T(trans). zT(trans) in [min,max]. zReceiver sets time to: t + (max+min)/2.

9 9 Synchronizing physical clocks – Cristian’s algorithm m r m t p Time server,S p records total round-trip time T(round); p sets its time to t+T(round)/2; If minimal transmission time is known, accuracy can be calculated. Problem: single point of failure. External synchronization

10 Cristian’s algorithm Compensate for delays yNote times: xrequest sent: T 0 xreply received: T 1 yAssume network delays are symmetric server client time requestreply T0T0 T1T1 T server 10

11 Cristian’s algorithm Client sets time to: server client time requestreply T0T0 T1T1 T server = estimated overhead in each direction 11

12 Error bounds If minimum message transit time (T min ) is known: Place bounds on accuracy of result 12

13 Error bounds server client time requestreply T0T0 T1T1 T server T min Earliest time message arrives Latest time message leaves range = T 1 -T 0 -2T min accuracy of result = 13

14 Cristian’s algorithm: example zSend request at 5:08:15.100 (T 0 ) zReceive response at 5:08:15.900 (T 1 ) yResponse contains 5:09:25.300 (T server ) zElapsed time is T 1 -T 0 5:08:15.900 - 5:08:15.100 = 800 msec zBest guess: timestamp was generated 400 msec ago zSet time to T server + elapsed time 5:09:25.300 + 400 = 5:09.25.700 14

15 Cristian’s algorithm: example If best-case message time=200 msec server client time requestreply T0T0 T1T1 T server 200 800 Error = T 0 = 5:08:15.100 T 1 = 5:08:15.900 T s = 5:09:25.300 T min = 200msec 15

16 16 Synchronizing physical clocks – the Berkeley algorithm zInternal synchronization. zA coordinator computer chosen to act as master. zMaster periodically polls the other computers (the slaves). zSlaves send back their clock values to master. zMaster calculates an average (taking the roundtrip times into account). zMaster sends the amount by which each individual slave’s clock requires adjustment. zThe algorithm eliminates readings from faulty clocks. zAlgorithm has provisions for ignoring readings from clocks whose skew is too great, Compute a fault-tolerant average

17 Berkeley Algorithm: example 3:252:509:103:00 1. Request timestamps from all slaves 3:25 2:50 9:10 17

18 Berkeley Algorithm: example 3:252:509:103:00 2. Compute fault-tolerant average: 3:25 2:50 9:10 18

19 Berkeley Algorithm: example 3:252:509:103:00 3. Send offset to each client -0:20 +0:15 -6:05 19

20 20 Synchronizing physical clocks – the Network Time Protocol (NTP) aims zProvide a service enabling clients across the Internet to be synchronized accurately to UTC. zProvide a reliable service that can survive lengthy losses of connectivity. zEnable clients to resynchronize sufficiently frequently to offset the rates of drift found in most computers. zProvide protection against interference with the time service, whether malicious or accidental.

21 21 Synchronizing physical clocks – NTP architecture 1 2 3 2 33 Note: Arrows denote synchronization control, numbers denote strata. - A network of servers located across the Internet. - Primary servers connected directly to time source. - Secondary servers synchronized with primary servers. - Servers connected in logical hierarchy, synchronization subnet. - Three modes of sync.: Multicast, procedure-call, symmetric (H.W.).

22 22 Synchronizing physical clocks – NTP peers message exchange T i T i-1 T i-2 T i-3 Server B Server A Time mm' Time T(i-3): Time when previous message sent. T(i-2): Time when previous message was received. T(i-1): Time when this message (just received) was sent. T(i): Time when this message was received.

23 SNTP Roundtrip delay: d = (T 4 -T 1 ) - (T 2 -T 3 ) server client time requestreply T1T1 T2T2 T4T4 T3T3 Time offset: 23

24 SNTP example server client time requestreply T 1 =1100 T 2 =800 T 4 =1200 T 3 =850 Time offset: Offset = ((800 - 1100) + (850 - 1200))/2 =((-300) + (-350))/2 = -650/2 = -325 Set time to T 4 + t = 1200 - 325 = 875 24

25 Cristian’s algorithm server client time requestreply T 1 =1100 T 2 =800 T 4 =1200 T 3 =850 Offset = (1200 - 1100)/2 = 50 Set time to T s + offset = 825 + 50 = 875 T s =825 25

26 26 Logical time and logical clocks – happened-before relation (self study) zIf two events occurred at the same process pi, then they occurred in the order in which pi observes them (->i). zWhenever a message is sent between processes, the event of sending the message occurred before the event of receiving the message. zTransitive relation.

27 27 Logical time and logical clocks – happened-before example (self study)

28 28 Logical time and logical clocks – Lamport logical clocks and timestamps (self study) zA Lamport logical clock is a monotonically increasing software counter. zEach process pi keeps its own logical clock Li which is used to apply Lamport timestamps to events. zTo capture the happened-before relation ->, processes update their logical clocks and transmit the values of their logical clocks in messages as follows: yBefore each event at pi: Li := Li+1 yWhen pi sends a message m, it piggybacks t=Li. yWhen pj receives (m,t): Lj := max(Lj,t)+1. ze -> e’ => L(e) < L(e’).

29 29 Logical time and logical clocks – Lamport timestamps example (self study)

30 30 Logical time and logical clocks – Vector timestamps example (self study) Vi[i]: The number of events that pi has timestamped; Vi[j]: The number of events that have occurred at pj that pi has potentially been affected by, j <> i.

31 31 Summary zTime zSynchronization of physical clocks: yIn a synchronous system. yCristian’s method. yThe Berkeley algorithm. yThe Network Time Protocol (NTP). zLogical time and logical clocks (self study): yThe happened-before relation. yLamport’s logical clocks and Lamport’s timestamps. yVector timestamps.


Download ppt "1 Time (and Global State). 3 Time – basics zWe want to know when something happened - Physical and logical clocks. zAlgorithms may depend upon clock."

Similar presentations


Ads by Google