TIME CLOCKS AND THE ORDERING OF EVENTS IN























- Slides: 23
TIME, CLOCKS AND THE ORDERING OF EVENTS IN A DISTRIBUTED SYSTEM L. Lamport Computer Science Laboratory SRI International
THE PAPER n Addresses the problem of clock drift in distributed systems n Identify main function of computer clocks: to order events n Indicates which conditions clocks must satisfy to fulfill their role n Introduces logical clocks
ORDERING EVENTS n Event ordering linked with concept of causality: ¨ Saying that event a happened before event b is same as saying that event a could have affected the outcome of event b ¨ If events a and b occur on processes that do not exchange any data, their exact ordering is irrelevant
Relation “has happened before” (I) n Smallest relation satisfying the three conditions: ¨ If a and b are events in the same process and a comes before b, then a b ¨ If a is the sending of a message by a process and b its receipt by another process, then a b ¨ If a b and b c then a c
Example (I) Process i X a X Process j X Process k X b c d X e
Example (II) n From first condition ¨ a d ¨ c e n From secondition ¨ a c ¨ b e n From third condition ¨ a e
Relation “has happened before” (II) n We cannot always order events: relation “has happened” before is only a preorder n If a did not happen before b, it cannot causally affect b
Logical clocks n Verify the clock condition: if a b then C<a> < C<b> and the two subconditions: ¨ if a and b are events in process Pi and a comes before b, then Ci<a> < Ci<b> ¨ if a is the sending of a message by process Pi and b its receipt by process Pj then Ci<a> < Cj<b>
Implementation rules n Each process Pi increments its clock Ci between two consecutive events, n If a is the sending of a message m by Pi then m includes a timestamp Tm = Ci<a> When Pj receives m, it sets its clock to a value greater than or equal to its present value and greater than Tm
Defining a total order n We can define a total ordering on the set of all system events a b if either Ci<a> < Cj<b> or Ci<a> = Cj<b> and Pi < Pj n This ordering is not unique
Anomalous behaviors n n Logical clocks have anomalous behaviors in the presence of outside interactions ¨ Carrying a flash drive from one machine to another ¨ Dictating file changes over the phone Must use physical clocks
Example Process i X a X Process j X Process k X b c d outside interaction X e
Strong clock condition n n Let S be set of all systems events plus the relevant external events For all events a, b in S, if a b then C(a) < C(b)
Physical clock conditions n There is a constant << 1 such that for all i: | d Ci(t) / dt - 1 | < The clock is neither too fast nor too slow n There is a constant such that for all i, j: | Ci(t) - Cj(t) | < The clocks are more or less synchronized
Implementation rules n If Pi does not receive a message at time t then Ci(t) is differentiable and d. Ci(t)/dt > 0 n If Pi sends message m at time t then m includes a timestamp Tm = Ci(t) When Pj receives m at time t’, it sets Cj(t’) to maximum of Cj(t’-0) and Tm+ m, where m is the minimum transmission delay
Observations n Like logical clocks, physical clocks cannot be rolled back n Required accuracy of a given physical clock depends on the minimum transmission delay of outside interactions ¨ If it takes 20 minutes to carry a flash drive between two machines, their clocks can be off by up to 20 minutes
Example Process i 11: 30 Xam Process j NO 11: 15 Xam X d OK 11: 30 Xam
A last word n Skip the proof in the appendix
A problem n n n A system of physical clocks consists of two clocks, namely, one that is fast and gains five minutes every hour and another that slow and loses five minutes every hour. Assuming that the clocks are managed by Lamport’s physical clock protocol, what will be the time marked by each clock at 4 pm given that: Both clocks indicated the correct time at noon; The processor on which the fast clock resides received at 2 pm a message from the other processor; No other messages were exchanged between the two processors; and Message transmission delays are negligible
The initial condition Time 12 pm 1 pm 2 pm 3 pm 4 pm Fast clock 12 pm Slow clock 12 pm
The processes do not communicate Time 12 pm 1 pm 2 pm 3 pm 4 pm Fast clock 12 pm 1: 05 pm Slow clock 12 pm 12: 55 pm
A message is exchanged Time 12 pm 1 pm 2 pm 3 pm 4 pm Fast clock 12 pm 1: 05 pm 2: 10 pm Slow clock 12 pm 12: 55 pm 1: 50 pm Message does not affect the fast clock
The final answer Time 12 pm 1 pm 2 pm 3 pm 4 pm Fast clock 12 pm 1: 05 pm 2: 10 pm 3: 15 pm 4: 20 pm Slow clock 12 pm 12: 55 pm 1: 50 pm 2: 45 pm 3: 40 pm























