Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState...

31
--- - - - Time This powerpoint presentation has been adapted from: 1) www.cse.buffalo.edu/~bina/cse486/.../ TimeGlobalStatesApr20.ppt

Transcript of Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState...

Page 1: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

Time

This powerpoint presentation has been adapted from:1) www.cse.buffalo.edu/~bina/cse486/.../

TimeGlobalStatesApr20.ppt

Page 2: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Contents

Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks

Page 3: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Contents

Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks

Page 4: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Why time is important in distributed systems?A quantity that needs to be measured

accurately• to know at what time of day a particular event

occurred at a particular computer• is important for auditing purposes• to maintain the consistency of distributed data

Introduction

Page 5: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Contents

Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks

Page 6: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

How to timestamp events in terms of their execution?Consider the following notations

• ϸ– A collection of N processes pi, i = 1,2, .. N (p executes on a single

processor)

• si

– The state of pi (each p has a state, the state changed when it is executed)

• Actions of pi

– Operations that transform pi’s state (p executes with a series of actions.

– Send or receive message between pi

Clocks, events and process states

Page 7: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

e• Event: occurrence of a single action

Relation between the events(i)• The series of events for a single process p• e.g., e i e` : e occurs before e` at pi

history(pi ) = hi = <ei0, ei

1, ei2, …>

• The series of event e in process pi

Clocks, events and process states

Page 8: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

How to timestamp the events (e)?Clock in computer:

• Each computer has its own physical clock• Is a device that counts oscillations occurring in a

crystal at a definite frequency• The OS reads the node’s hardware time: Hi(t)

» The counts of oscillation since an original point• Then, scale it and add offset to produce software

clock, Ci(t) = Hi(t)+» To timestamp of an event

Clocks, events and process states

Page 9: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Computer clocks tend not to be in a perfect agreement.Clock drift

• Clocks count time at different rates

Clock skew• The instantaneous (direct) difference between the readings of any

two clocks

Why? Oscillators are subject to physical variations • Frequency, temperature

Clocks, events and process states

Network

Page 10: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

How to synchronize computer clocks?Use external source that provide highly accurate

timeUse atomic oscillatorUsed by International Atomic Time

Clocks, events and process states

Page 11: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

What is the international standard for time keeping?Coordinated Universal Time (UTC)

• Based on atomic time• Time is coordinated with astronomical time• UTC signal is broadcasted from land-based radio station to

satellites covering many parts of the world

Clocks, events and process states

Page 12: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Contents

Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks

Page 13: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

How to know at what time of the day an event occurs? Two types of synchronization:

• External• Internal

Notations:• Ci : pi’s clock• I : an interval of real time

Synchronizing physical clocks

Page 14: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

External synchronizationFor a synchronization bound D > 0, and for a source S of UTC

time, |S(t)-Ci(t)| < D, for i = 1, 2, … N and for all real times t in IClocks Ci are accurate to within the bound D

Internal synchronizationFor a synchronization bound D > 0, |Ci(t)-Cj(t)| < D for i, j =1,2, …

N, and for all real times t in IClocks Ci agree within the bound D

Clocks that are internally synchronized are not necessarily externally synchronized If the system ϸ is externally synchronized with a bound D, then the same

system is internally synchronized with a bound of 2D.

Synchronizing physical clocks

Page 15: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Synchronization in a synchronous system there will be a minimum time of transmission where no other processes

executed at the same time and no other network traffic existed. Maximum time of transmission in synchronous mode is always set (i.e.,

time out is applied) Protocol

• Sender: send M(t)• Receiver: set time to t + Ttrans

Bounds are known in synchronous system• min < Ttrans < max (constant)

Optimum transmission time, • Ttrans = (min+max) / 2• Receiver’s clock = t + (min+max) / 2

Synchronizing physical clocks

t t+maxt +Ttranst + min

Page 16: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

The common practice in distributed system is asynchronous;The factors lead to message delay are not bounded

(no upper bound max)The Internet is asynchronousTtrans = min + x, where x ≥ 0, the value of x is not

knownMethods for synchronizing clock in asynchronous

distributed systems:• Cristian’s method• The Berkeley algorithms• The Network Time Protocol

Synchronizing physical clocks

Page 17: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Cristian’s method of synchronizing clocksUse time serverProtocol

• mr – process p requests the time from server • mt – process receives the time (t is inserted in the

message)• Tround - process p records the round-trip (send request-get

reply)• Estimated time: t + Tround/2

Synchronizing physical clocks

mr

mtp Time server,S

Page 18: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Cristian’s method of synchronizing clocksAccuracy analysis

• If the minimum delay of a message transmission is min, then accuracy: (Tround/2 – min)

Synchronizing physical clocks

t

t +Tround-min

t +Tround/2

t + min

t +Tround

Page 19: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time and Global State

The Berkeley algorithmsInternal synchronization using a coordinator

computer (master). Other computers that their clocks need to be synchronized is known as slaves1. The master polls the slaves’ clocks2. The master estimates the slaves’ clocks by round-

trip time3. The master averages the slaves’ clock values4. The master sends back to the slaves the amount

that the slaves’ clocks should adjust5. Slave adjust its clock

Synchronizing physical clocks

Page 20: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

The Network Time Protocol (NTP)An architecture for a time service and a protocol to

distribute time information over the InternetAims:

• External synchronization– Enable clients across the Internet to be synchronized accurately to

UTC• Reliability

– Can survive lengthy losses of connectivity» Redundant server & redundant path between servers

• Scalability– Enable clients to resynchronize sufficiently frequently to offset the

rates of drift found in most computers• Security

– Protect against interference with the time service

Synchronizing physical clocks

Page 21: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

NTP service is provided by servers located across the InternetPrimary servers are connected directly to a time

source, e.g. radio clock receiving UTCSecondary servers are synchronized to primary

servers

Synchronizing physical clocks

Page 22: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Network Time Protocol Architecture

Synchronizing physical clocks

1

2

3

2

3 3

Note: Arrows denote synchronization control, numbers denote strata.

Page 24: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

3 modes of NTP synchronization:Multicast mode

• Intended for use on a high speed LAN• One or more servers multicast the time to other servers

in the LAN• Low accuracy but sufficient

Procedure-call mode• Similar to Christian’s• Higher accuracy than multicast

Symmetric mode• Use by the servers that supply time information in LANs• The highest accuracy

Synchronizing physical clocks

Page 25: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Contents

Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks

Page 26: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Events in a single process is ordered uniquely by times shown in the local clock

Clock is unable to be synchronized perfectly. Hence physical time is not accurate to determine the occurrence of events

Logical time and logical clocks

Page 27: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Happened-before relationIt is also sometimes known as the relation of

causal ordering or potential causal ordering.

Logical time and logical clocks

Page 28: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Logical clocks- a simple mechanism to capture HB order numerically. Known as Lamport timestamps algorithm (it is a software counter).LC1

• Li is incremented before each event is issued at process pi : Li :=Li+1

LC2: (a) When a process pi sends a message m, it

adjoin the value t = Li on m(b) On receiving (m,t), a process Pj computes Lj :=

max(Lj, t) and then applies LC1 before timestamping the event receive(m)

Logical time and logical clocks

Page 29: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Totally ordered logical clocks algorithmAssumption

Ti : local timestamp of e that is an event occurring at pi

Tj : local timestamp of e` that is an event occurring at pj

The timestamps of two events e and e` are (Ti, i), (Tj, j)When (Ti, i) < (Tj, j), if and only if Ti < Tj , or Ti = Tj and i < j

Logical time and logical clocks

Page 30: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

---

---

---

Time

Vector Clocks algorithmEach process pi keeps a vector clock Vi

VC1: Initially, Vi[j]=0, for i, j = 1,2…, NVC2: Just before pi timestamps an event, it sets

Vi[i] := Vi[i] +1VC3: pi includes the value t= Vi in every message it

sendsVC4: When pi receives a timestamp t in a message,

it sets Vi[j] :=max(Vi[j], t[j]), for j=1,2…,N

Logical time and logical clocks

Page 31: Time This powerpoint presentation has been adapted from: 1)bina/cse486/.../TimeGlobalState sApr20.ppt.

---

---

---

End of the Chapter…