Time ( and Global State )
description
Transcript of Time ( and Global State )
![Page 1: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/1.jpg)
1
Time (and Global State)
![Page 2: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/2.jpg)
![Page 3: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/3.jpg)
3
Time – basics
We want to know when something happened - Physical and logical clocks.
Algorithms may depend upon clock synchronization.No global notion of time.
![Page 4: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/4.jpg)
4
Time – system model
N processes: Each executes on a single processor. No shared memory. Only communication means is exchange of messages.
pi has state si.An event is the occurrence of a single action, i.e.:
An internal state-transforming action by pi, or a communication action.
e i e’ if e occurs before e’ in pi.
![Page 5: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/5.jpg)
5
Time – clocks
Each computer has its own physical clock.The software clock Ci can be used to timestamp any
event at pi.Problems: Clock skew and clock drift.
Network
![Page 6: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/6.jpg)
6
Time – Coordinated Universal Time (UTC)
International standard for timekeeping.Based on atomic time.Synchronizes with astronomical time using leap
seconds.UTC signals are synchronized and broadcast
regularly from land-based radio stations and satellites.
Computers with receivers attached can synchronize their clocks with these timing signals.
![Page 7: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/7.jpg)
7
Synchronizing physical clocks – basics
External synchronization: For each i, synchronize Ci with an authoritative, external source of time.
Internal synchronization: For each i,j, synchronize Ci and Cj with each other.
Other issues: Correctness, monotonicity, faulty clocks, crash failures, arbitrary failures.
![Page 8: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/8.jpg)
8
Synchronizing physical clocks – in a synchronous system
Internal synchronization.Sender sends local time t to receiver.Receiver ideally sets time to: t + T(trans).T(trans) in [min,max].Receiver sets time to: t + (max+min)/2.
![Page 9: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/9.jpg)
9
Synchronizing physical clocks – Cristian’s algorithm
mr
mtp 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
![Page 10: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/10.jpg)
Cristian’s algorithm
Compensate for delays Note times:
request sent: T0
reply received: T1
Assume network delays are symmetric
server
clienttime
request reply
T0 T1
Tserver
10
![Page 11: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/11.jpg)
Cristian’s algorithm
Client sets time to:server
clienttime
request reply
T0 T1
Tserver
= estimated overhead in each direction
11
![Page 12: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/12.jpg)
Error bounds
If minimum message transit time (Tmin) is known:
Place bounds on accuracy of result
12
![Page 13: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/13.jpg)
Error bounds
server
clienttime
request reply
T0 T1
Tserver
Tmin Tmin
Earliest time message arrives
Latest time message leaves
range = T1-T0-2Tmin
accuracy of result =
13
![Page 14: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/14.jpg)
Cristian’s algorithm: example
Send request at 5:08:15.100 (T0)
Receive response at 5:08:15.900 (T1) Response contains 5:09:25.300 (Tserver)
Elapsed time is T1 -T0
5:08:15.900 - 5:08:15.100 = 800 msec
Best guess: timestamp was generated400 msec ago
Set time to Tserver+ elapsed time
5:09:25.300 + 400 = 5:09.25.70014
![Page 15: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/15.jpg)
Cristian’s algorithm: example
If best-case message time=200 msec
server
clienttime
request reply
T0 T1
Tserver
200 200
800
Error =
T0 = 5:08:15.100T1 = 5:08:15.900Ts = 5:09:25.300Tmin = 200msec
15
![Page 16: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/16.jpg)
16
Synchronizing physical clocks – the Berkeley algorithm
Internal synchronization. A coordinator computer chosen to act as master.Master periodically polls the other computers (the slaves). Slaves send back their clock values to master.Master calculates an average (taking the roundtrip times
into account).Master sends the amount by which each individual slave’s
clock requires adjustment. The algorithm eliminates readings from faulty clocks. Algorithm has provisions for ignoring readings from clocks
whose skew is too great, Compute a fault-tolerant average
![Page 17: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/17.jpg)
Berkeley Algorithm: example
3:25 2:50 9:10
3:00
1. Request timestamps from all slaves
3:252:50
9:10
17
![Page 18: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/18.jpg)
Berkeley Algorithm: example
3:25 2:50 9:10
3:00
2. Compute fault-tolerant average:
3:252:50
9:10
18
![Page 19: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/19.jpg)
Berkeley Algorithm: example
3:25 2:50 9:10
3:00
3. Send offset to each client
-0:20+0:15
-6:05
19
![Page 20: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/20.jpg)
20
Synchronizing physical clocks – the Network Time Protocol (NTP) aims
Provide a service enabling clients across the Internet to be synchronized accurately to UTC.
Provide a reliable service that can survive lengthy losses of connectivity.
Enable clients to resynchronize sufficiently frequently to offset the rates of drift found in most computers.
Provide protection against interference with the time service, whether malicious or accidental.
![Page 21: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/21.jpg)
21
Synchronizing physical clocks – NTP architecture
1
2
3
2
3 3
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.).
![Page 22: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/22.jpg)
22
Synchronizing physical clocks – NTP peers message exchange
Ti
Ti-1Ti-2
Ti- 3
Server B
Server A
Time
m m'
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.
![Page 23: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/23.jpg)
SNTP
Roundtrip delay:
d = (T4-T1) - (T2-T3)
server
clienttime
request reply
T1
T2
T4
T3
Time offset:
23
![Page 24: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/24.jpg)
SNTP example
server
clienttime
request reply
T1=1100
T2=800
T4=1200
T3=850
Time offset:
Offset =
((800 - 1100) + (850 - 1200))/2
=((-300) + (-350))/2
= -650/2 = -325
Set time to T4 + t= 1200 - 325 = 875
24
![Page 25: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/25.jpg)
Cristian’s algorithm
server
clienttime
request reply
T1=1100
T2=800
T4=1200
T3=850
Offset = (1200 - 1100)/2 = 50
Set time to Ts + offset= 825 + 50 = 875
Ts=825
25
![Page 26: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/26.jpg)
26
Logical time and logical clocks – happened-before relation (self study)
If two events occurred at the same process pi, then they occurred in the order in which pi observes them (->i).
Whenever a message is sent between processes, the event of sending the message occurred before the event of receiving the message.
Transitive relation.
![Page 27: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/27.jpg)
27
Logical time and logical clocks – happened-before example (self study)
p1
p2
p3
a b
c d
e f
m1
m2
Physicaltime
![Page 28: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/28.jpg)
28
Logical time and logical clocks – Lamport logical clocks and timestamps (self study)
A Lamport logical clock is a monotonically increasing software counter.
Each process pi keeps its own logical clock Li which is used to apply Lamport timestamps to events.
To capture the happened-before relation ->, processes update their logical clocks and transmit the values of their logical clocks in messages as follows: Before each event at pi: Li := Li+1 When pi sends a message m, it piggybacks t=Li. When pj receives (m,t): Lj := max(Lj,t)+1.
e -> e’ => L(e) < L(e’).
![Page 29: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/29.jpg)
29
Logical time and logical clocks – Lamport timestamps example (self study)
a b
c d
e f
m1
m2
21
3 4
51
p1
p2
p3
Physical time
![Page 30: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/30.jpg)
30
Logical time and logical clocks – Vector timestamps example (self study)
a b
c d
e f
m1
m2
(2,0,0)(1,0,0)
(2,1,0) (2,2,0)
(2,2,2)(0,0,1)
p1
p2
p3
Physical time
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.
![Page 31: Time ( and Global State )](https://reader035.fdocuments.us/reader035/viewer/2022062500/56815125550346895dbf4276/html5/thumbnails/31.jpg)
31
Summary
TimeSynchronization of physical clocks:
In a synchronous system. Cristian’s method. The Berkeley algorithm. The Network Time Protocol (NTP).
Logical time and logical clocks (self study): The happened-before relation. Lamport’s logical clocks and Lamport’s timestamps. Vector timestamps.