ECE 428/CS 425 Distributed Systems

16
2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya) ECE 428/CS 425 Distributed Systems Lecture 2 Time & Synchronization

description

ECE 428/CS 425 Distributed Systems. Lecture 2 Time & Synchronization. Why synchronization?. Two sharpshooters in a multiplayer online game kill the same target. Which one gets the points? Synchronization required for Fairness Correctness!. Processes and Events. - PowerPoint PPT Presentation

Transcript of ECE 428/CS 425 Distributed Systems

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

ECE 428/CS 425Distributed

Systems

ECE 428/CS 425Distributed

Systems

Lecture 2

Time & Synchronization

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Why synchronization?Why synchronization?

• Two sharpshooters in a multiplayer online game kill the same target. Which one gets the points?

• Synchronization required for

– Fairness

– Correctness!

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

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 Processes and Events

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

In DS each processor has its own timer.

Timers drift from true real time at different rates.

Drift versus Skew

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

Physical Clocks & Synchronization Physical Clocks & Synchronization

Max-Synch-Interval = (Max-Acceptable-Diff) / (MDR * 2)

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Synchronizing Physical ClocksSynchronizing 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.

,)()( DtCtS i

DtCtC ji )()(

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Clock Synchronization Using a Time ServerClock Synchronization Using a Time Server

mr

mtp Time server,S

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

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 Cristian’s Algorithm

adjusted-local-time = server-timestamp t + (RTT / 2) or

= server-timestamp + (RTT – server-latency) /2

local-clock-error = adjusted-local-time – local-time

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

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Cristian’s AlgorithmCristian’s Algorithm

• Message arrives at time T as per the server’s clock. Then:

T >= t + min (min for message from server)

T <= t + (RTT-min) (min for msg to server)

• Client makes its clock = t + RTT/2

Error is bounded by | RTT/2 – min |

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Cristian’s AlgorithmCristian’s Algorithm

Caveat

• RTT estimated by the client using its own clock

• RTT measurement affected by client’s clock drift

• But this effect small if clock drift small relative to real RTT value

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Uses a elected master to synchronize

The elected master 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 Berkeley Algorithm

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Secondry servers, synched by the primary server

The Network Time Protocol (NTP) The Network Time Protocol (NTP)

Primary server, direct synch.

Strata 3, synched by the secondary servers

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.

1

2 2 2

3 3 3 3 3 3

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Messages Exchanged Between a Pair of NTP Peers

Messages Exchanged Between a Pair of NTP Peers

Ti

Ti-1Ti-2

Ti- 3

Server B

Server A

Time

m m'

Time

Each message bears timestamps of recent message events: the local timewhen the previous NTP message was sent and received, and the local timewhen the current message was transmitted.

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Theoretical Base for NTPTheoretical Base for NTP

Ti

Ti-1Ti-2

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

B’s clock = A’clock + o• t and t’: actual transmission times for m and m’• di: estimate of accuracy of oi ; total transmission times for m and m’; d=t+t’ .2/2/

shown that be alsocan It

.2/)(

where,2/)'(

'

toleads This

'

132

132

1

32

doodo

TTTTo

ttooTTTTttd

otTT

otTT

iiii

iiiii

i

iiiii

ii

ii

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Logical Clocks Logical Clocks We are interested in relative time between events (their

order), define relation, Happens-Before () : On the same process: a b, if time(a) < time(b)

If p1 sends m to p2: 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 processes 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

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Events Occurring at Three ProcessesEvents Occurring at Three Processes

p1

p2

p3

a b

c d

e f

m1

m2

Physicaltime

2001, M. T. Harandi, J. Hou (modified by I. Gupta, N. Vaidya)

Lamport TimestampsLamport Timestamps

a b

c d

e f

m1

m2

21

3 4

51

p1

p2

p3

Physical time