Computer Science 328 Distributed Systems - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Computer Science 328 Distributed Systems

Description:

Synchronizing Physical Clocks ... time server to synchronize clocks. Time server ... Uses a network of time servers to synchronize all processors on a net. ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 20
Provided by: mehdith
Category:

less

Transcript and Presenter's Notes

Title: Computer Science 328 Distributed Systems


1
Computer Science 328Distributed Systems
  • Lecture 5
  • Time Synchronization
  • Reading 10.1-10.4

2
Processes and Events
  • A DS consists of a number of processes.
  • Each process has a state (values of variables).
  • Each process takes actions to change its state,
  • or to communicate (send, receive).
  • An event is the occurrence of an action.
  • Events within a process can be ordered by the
  • time of occurrence.
  • In DS we also need to know the time order of
    events
  • on different processors between different
    processes.

3
Physical Clocks Synchronization
  • In DS each processor has its own timer.
  • Timers drift from true real time at different
    rates.
  • Maximum Drift Rate (MDR) of a clock
  • depends on clock characterization and the
    environment.
  • ?Max difference between two clocks with
  • similar MDR is 2 MDR

Max-Synch-Interval (Max-Acceptable-Diff) / (MDR
2)
4
Synchronizing Physical Clocks
  • Ci(t) the reading of the software clock i when
    the real time is t.
  • External synchronization For a synchronization
    bound Dgt0, and for source S of UTC time,
  • for i1,2,...,N and for all real times t in
    I.
  • Clocks Ci are accurate to within the bound D.
  • Internal synchronization For a synchronization
    bound Dgt0,
  • for i, j1,2,...,N and for all real times t
    in I.
  • Clock Ci agree within the bound D.

5
Cristians Algorithm
  • Uses a time server to synchronize clocks
  • Time server keeps the reference time
  • Clients ask the time server for time adjust
    their clock, based on the response
  • For links with symmetrical latency

RTT response-received-time request-sent-time
adjusted-local-time server-timestamp (RTT /
2) or server-timestamp (RTT
server-latency) /2 local-clock-error
adjusted-local-time local-time
6
Clock Synchronization Using a Time Server
7
Cristians Algorithm (2)
  • For positive clock errors, clock is advanced
    forward accordingly. For negative clock errors,
    the clock should be slowed down, not immediately
    adjusted.
  • For unusually long RTTs, repeat the time request
  • For non-uniform RTTs, use adaptive, weighted
    average

avg-clock-error0 local-clock-error avg-clock-err
orn (Wn local-clock-error) (1
Wn) local-clock-errorn-1
8
Berkeley Algorithm
  • Uses a designated server to synchronize
  • The designated server pools or broadcasts
  • to all machines for their time, adjusts times
    received for RTT latency, averages times, and
    tells each machine how to adjust.
  • In some systems multiple time servers are used.
  • Avg. time is more accurate, but still drifts

9
The Network Time Protocol (NTP)
  • Uses a network of time servers to synchronize all
    processors on a net.
  • Time servers are connected by a synchron- ization
    subnet tree. The root is adjusted directly .
    Each node synchronizes its
  • children nodes.

Primary server, direct synch.
1
Secondry servers, synched by the primary server
2
2
2
Strata 3, synched by the secondary servers
3
3
3
3
3
3
10
Messages Exchanged Between a Pair of NTP Peers
Each message bears timestamps of recent message
events the local time when the previous NTP
message was sent and received, and the local
time when the current message was transmitted.
11
Theoretical Base for NTP
  • oi estimate of the actual offset
  • between the two clocks
  • o true offset of the clock at B
  • relative to that at A
  • t and t actual transmission times
  • for m and m
  • di total transmission times for m
  • and m dtt

12
Logical Clocks
  • We are interested in relative time between
    events (their order), define relation,
    Happens-Before (?)
  • On the same host a ? b, if time(a) lt time(b)
  • If H1 sends m to H2 send(m) ? receive(m)
  • If a ? b and b ? c then a ? c
  • Lamport Algorithm uses this relationship to
    provide a partial ordering of events
  • All hosts use a counter (clock) with initial
    value of zero
  • The counter is incremented by and assigned to
    each event, as its timestamp.
  • A send (message) event carries its timestamp
  • For a receive (message) event the counter is
    updated by Max(receiver-counter,
    message-timestamp) 1

13
Events Occurring at Three Processes
14
Lamport Timestamps
15
Example Lamport Logical Time

Physical Time
1
2
Host 1
8
0
7
1
8
3
Host 2
0
2
2
3
6
Host 3
4
0
10
9
3
5
4
7
Host 4
0
5
6
7
Clock Value
n
timestamp
Message
16
Vector Logical Clocks
  • With Lamport Logical Time
  • e precedes f ? timestamp(e) lt timestamp (f),
    but
  • timestamp(e) lt timestamp (f) ? e precedes f
  • Vector Logical time guarantees this
  • All hosts use a vector of counters (logical
    clocks), ith element is the clock value for host
    i, initially all zero.
  • Each host i, increments the ith element of its
    vector
  • upon an event, and assigns the vector to the
    event.
  • A send(message) event carries its vector
    timestamp (counter vector)
  • For a receive(message) event,
  • Max(Vreceiverj , Vmessagj), if j
    is not self
  • Vreceiverj 1 otherwise

Vreceiverj
17
Vector Timestamps
18
Example Vector Logical Time

Physical Time
Host 1
0,0,0,0
Host 2
0,0,0,0
Host 3
0,0,0,0
Host 4
0,0,0,0
Vector logical clock
n,m,p,q
(vector timestamp)
Message
19
Comparing Vector Timestamps
  • VT1 VT2,
  • iff VT1i VT2i, i 1, , n
  • VT1 lt VT2,
  • iff VT1i lt VT2i, i 1, , n
  • VT1 lt VT2,
  • iff VT1 lt VT2
  • ? j (1 lt j lt n VT1j lt VT2 j)
  • VT1 is concurrent with VT2
  • iff not (VT1 lt VT2 OR VT2 lt VT1)
Write a Comment
User Comments (0)
About PowerShow.com