Upload
prudence-parsons
View
217
Download
0
Tags:
Embed Size (px)
Citation preview
1
Time (and Global State)
4
Time – basics
We want to know when something happened - Physical and logical clocks.
Algorithms may depend upon clock synchronization.No global notion of time.
5
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.
6
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
7
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.
8
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.
9
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.
10
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
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
11
Cristian’s algorithm
Client sets time to:server
clienttime
request reply
T0 T1
Tserver
= estimated overhead in each direction
12
Error bounds
If minimum message transit time (Tmin) is known:
Place bounds on accuracy of result
13
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 =
14
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.70015
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
16
17
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
Berkeley Algorithm: example
3:25 2:50 9:10
3:00
1. Request timestamps from all slaves
3:252:50
9:10
18
Berkeley Algorithm: example
3:25 2:50 9:10
3:00
2. Compute fault-tolerant average:
3:252:50
9:10
19
Berkeley Algorithm: example
3:25 2:50 9:10
3:00
3. Send offset to each client
-0:20+0:15
-6:05
20
21
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.
22
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.).
23
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.
SNTP
Roundtrip delay:
d = (T4-T1) - (T2-T3)
server
clienttime
request reply
T1
T2
T4
T3
Time offset:
24
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
25
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
26
27
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.
28
Logical time and logical clocks – happened-before example (self study)
p1
p2
p3
a b
c d
e f
m1
m2
Physicaltime
29
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’).
30
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
31
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.
32
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.