Distributed Systems: Time & Synchronization Lecture Notes, Study notes of Computer Science

A set of lecture notes from a university course on distributed systems, focusing on the topics of time and synchronization. It covers concepts such as processes and events, physical clocks and synchronization, synchronizing physical clocks, and clock synchronization using a time server. It also introduces algorithms like cristian's algorithm and the berkeley algorithm, and discusses the network time protocol (ntp).

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-arx
koofers-user-arx 🇺🇸

3

(2)

10 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
2006, M. T. Harandi Lecture 4-1
Computer Science 425
Distributed Systems
Lecture 4
Time & Synchronization
Reading: 10.1-10.4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Distributed Systems: Time & Synchronization Lecture Notes and more Study notes Computer Science in PDF only on Docsity!

Computer Science 425

Distributed Systems

Lecture 4

Time & Synchronization

Reading: 10.1 10.

♣ 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.

Processes and Events

Synchronizing Physical Clocks

• Ci(t):^ the reading of the software clock^ i^ when the real time is^ t.

• External synchronization: For a synchronization bound D>0 , and

for source S of UTC time,

for i=1,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 D>0 ,

for i, j=1,2,...,N and for all real times t in I.

Clock Ci agree within the bound D.

∣S  t − Ci t ∣D ,

∣Ci  t − C j  t ∣D

♣ (^) 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:

Cristian’s Algorithm

adjusted-local-time = server-timestamp + (RTT / 2) or = server- timestamp + (RTT – server-latency) /2 local-clock-error = adjusted- local-time – local-time

RTT = response-received-time – request-sent-time

♣ (^) 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

Cristian’s Algorithm (2)

avg-clock-error 0 = local-clock-error

avg-clock-errorn = (Wn * local-clock-error) +

(1 – Wn) * local-clock-errorn-

♣ (^) 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

Berkeley Algorithm

Messages Exchanged Between a Pair of NTP

Peers

Ti

Ti 2 Ti 1

Ti 3

Server B

Server A

Time

m m'

Time

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.

Theoretical Base for NTP

Ti

Ti 2 Ti 1

Ti 3

Server B

Server A

Time

m m'

Time

- 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’ ; d=t+t’

T i − 2 =T i− 3 t o

T i =T i− 1 t '− o

This leads to

di =t t ' =T i − 2 − T i− 3 T i− T i− 1

o=oi  t '− t /2, where

oi = T i − 2 − T i − 3 T i− 1 − T i / 2.

It can also be shown that

oi− di / 2 ≤o≤oi di / 2.

Events Occurring at Three Processes

p 1

p 2

p 3

a b

c d

e f

m (^1)

m (^2)

Physical time

Lamport Timestamps

a (^) b

c d

e f

m (^1)

m (^2)

1 2

3 4

1 5

p 1

p 2

p 3

Physical time

Vector Logical Clocks

 With Lamport Logical Time

e precedes f ⇒ timestamp(e) < timestamp (f), but timestamp(e) < 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(Vreceiver[j] , Vmessag[j]), if j is not self Vreceiver[j] = Vreceiver[j] + 1 otherwise

Vector Timestamps

a (^) b

c d

e f

m (^1)

m (^2)

(1,0,0) (2,0,0)

(2,1,0) (2,2,0)

(0,0,1) (2,2,2)

p 1

p 2

p 3

Physical time

Comparing Vector Timestamps

 (^) VT 1 = VT 2 ,

iff VT 1 [i] = VT 2 [i], i = 1, … , n

 VT 1 < VT 2 ,

iff VT 1 [i] < VT 2 [i], i = 1, … , n

 (^) VT 1 < VT 2 ,

iff VT 1 < VT 2 &

∃ j (1 < j < n & VT 1 [j] < VT 2 [j])

 VT 1 is concurrent with VT 2

iff not (VT 1 < VT 2 OR VT 2 < VT 1 )