Time and Clock Primary standard rotation of earth

  • Slides: 18
Download presentation
Time and Clock Primary standard = rotation of earth De facto primary standard =

Time and Clock Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9, 192, 631, 770 orbital transitions of Cs 133 atom. 86400 atomic sec = 1 solar day – 3 ms). What is GPS? There is nothing called simultaneous in the physical world.

Sequential and Concurrent events Sequential = Totally ordered in time. Total ordering is feasible

Sequential and Concurrent events Sequential = Totally ordered in time. Total ordering is feasible in a single process that has only one clock. This is not true in a distributed system. Two issues are important here: ¨ How to synchronize physical clocks ? ¨ Can we define sequential and concurrent events without using physical clocks?

Causality helps determine sequential and concurrent events without using physical clocks. n n n

Causality helps determine sequential and concurrent events without using physical clocks. n n n Joke �Re: joke (�implies causally ordered before) Message sent �message received Local ordering a �b �c (based on the local clock)

Defining causal relationship n Rule 1. If a, b are two events in a

Defining causal relationship n Rule 1. If a, b are two events in a single process P, and the time of a is less than the time of b then a �b. n Rule 2. If a = sending a message, and b = receipt of that message, then a �b. n Rule 3. a �b b �c a �c

Example of causality a �d since (a �b b �c c �d) e �d

Example of causality a �d since (a �b b �c c �d) e �d since (e �f f �d) (Thus �defines a PARTIAL order). Is g �f or f �g? NO. They are concurrent. Concurrency = absence of causal order.

Logical clocks LC is a counter. Its value respects causal ordering as follows a

Logical clocks LC is a counter. Its value respects causal ordering as follows a �b LC(a) < LC(b) Note that LC(a) < LC(b) does NOT imply a �b. Each process maintains its logical clock as follows: LC 1. Each time a local event takes place, increment LC. LC 2. Append the value of LC to outgoing messages. LC 3. When receiving a message, set LC to 1+ max (local LC, message LC)

Total order So, does total order exist in a distributed system? n Let a,

Total order So, does total order exist in a distributed system? n Let a, b be events in processes i and j respectively. Then n a << b iff LC(a) < LC(b) OR LC(a) = LC(b) and i<j n a �b a << b, but the converse is not true. It is important to define a total order for some applications. n n Causal order is strengthened to define a total order (<<) among events. The (id, LC) value sent out with each message is called its timestamp.

Vector clock Causality detection can be an important issue is applications like group communication.

Vector clock Causality detection can be an important issue is applications like group communication. Logical clocks do not detect causal ordering. Vector clocks do. a �b VC(a) < VC(b)

Vector clocks Example [3, 3, 4, 5, 3, 2, 1, 4] < [3, 3,

Vector clocks Example [3, 3, 4, 5, 3, 2, 1, 4] < [3, 3, 4, 5, 3, 2, 2, 5] Define. VC(a) < VC(b) iff But, i : 0 ≤ i ≤ N-1 : VC(a)[i] ≤ VC(b)[i], and [3, 3, 4, 5, 3, 2, 1, 4] and [3, 3, 4, 5, 3, 2, 2, 3] are not comparable j : 0 ≤ j ≤ N-1 : VC(a)[j] < VC(b)[j],

Implementing VC {Actions of process j} VC 1. Increment VC[j]) for each local event.

Implementing VC {Actions of process j} VC 1. Increment VC[j]) for each local event. VC 2. Append local VC to every outgoing message. VC 3. When a message with a vector timestamp T arrives, first increment the jth component VC[j] of the local vector clock, and then update it as follows: k: 0 ≤ k ≤ N-1: : VC[k] : = max(T[k], VC[k]).

Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With

Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With atomic clocks becoming affordable, should we care about physical clock synchronization? Can’t we use GPS?

Classification Types of Synchronization ¨ ¨ ¨ External Synchronization Internal Synchronization Phase Synchronization Types

Classification Types of Synchronization ¨ ¨ ¨ External Synchronization Internal Synchronization Phase Synchronization Types of clocks Unbounded 0, 1, 2, 3, . . . Bounded 0, 1, 2, . . . M-1, 0, 1, . . . Unbounded clocks are not realistic, but are easier to deal with in algorithms

Terminologies n What are these? Drift rate Clock skew Resynchronization interval R n Challenges

Terminologies n What are these? Drift rate Clock skew Resynchronization interval R n Challenges (Drift is unavoidable) Accounting for propagation delay Processing delay Faulty clocks

Internal synchronization A simple averaging algorithm Some clocks may be faulty Step 1. Read

Internal synchronization A simple averaging algorithm Some clocks may be faulty Step 1. Read every clock in the system. Step 2. Discard outliers and substitute them by the value of the local clock. Step 3. Update the clock using the average of these values. Synchronization is maintained if n > 3 t+1 where t is the number of faulty (may be 2 -faced) clocks. Why?

Internal synchronization A simple averaging algorithm If there are t faulty clocks, then the

Internal synchronization A simple averaging algorithm If there are t faulty clocks, then the maximum difference between the averages computed by two non-faulty nodes is be 3 t /n To keep the clocks synchronized, So, Some clocks may be faulty 3 t /n < 3 t < n

Cristian’s method Time server Client pulls data from a time server. For accuracy, it

Cristian’s method Time server Client pulls data from a time server. For accuracy, it computes the round trip time (RTT), and compensates for this delay while adjusting its own clock

Network Time Protocol Tiered architecture Time server Broadcast mode -least accurate Procedure call -medium

Network Time Protocol Tiered architecture Time server Broadcast mode -least accurate Procedure call -medium accuracy Peer-to-peer mode -higher level servers use this for max accuracy

P 2 P mode of NTP T 2 Q Let Q’s time be ahead

P 2 P mode of NTP T 2 Q Let Q’s time be ahead of P’s time by . Then T 3 T 2 = T 1 + TPQ + T 4 = T 3 + TQP - P T 1 T 4 RTT y = TPQ + TQP = T 2 +T 4 -T 1 -T 3 = (T 2 -T 4 -T 1 +T 3) / 2 -(TPQ - TQP) /2 x Between y/2 and -y/2 Ping several times, and obtain the smallest value of y. Use it to calculate