CH-05 Time and State in DS
CH-05 Time and State in DS
CH – 05
Time and State in Distributed
Systems
• Although P.c is modified after P.o has been generated, because of the clock drift
the time assigned to P.c is smaller. → P.c will not be recompiled for the new
version!
3
© Baikuntha Acharya (baikunth2a@gmail.com)
Time in Distributed Systems (Cont..)
Types of Clock
✓ Physical Clocks
• Tied to the notion of real time
✓ Logical Clocks
• Derived from the notion of potential cause-effect between events
• Different types
• Lamport's Logical Clock
• Vector Clocks
• …..
4
© Baikuntha Acharya (baikunth2a@gmail.com)
Time in Distributed Systems (Cont..)
Solutions
✓ Logical clocks:
• Physical time might not be important - what is important is the relative order of
events!
5
© Baikuntha Acharya (baikunth2a@gmail.com)
Time in Distributed Systems (Cont..)
Solutions (Cont..)
• Whenever a message is sent between processes, the event of sending the message
occurred before the event of receiving it.
6
© Baikuntha Acharya (baikunth2a@gmail.com)
Physical Clock Synchronization
Synchronize with Time Server
7
© Baikuntha Acharya (baikunth2a@gmail.com)
Physical Clock Synchronization (Cont..)
Cristian's Algorithm
8
© Baikuntha Acharya (baikunth2a@gmail.com)
Physical Clock Synchronization (Cont..)
Berkeley Algorithm
✓ Time Daemon asks all other machines for their clock values:
• Computes average time
✓ Issues:
• Load in central server
11
© Baikuntha Acharya (baikunth2a@gmail.com)
Physical Clock Synchronization (Cont..)
Network Time Protocol (NTP) (Cont..)
✓ Arranged in strata:
• Stratum 0 → Master clock
• 1st stratum: systems connected directly to accurate time source (Satellite, radio, etc)
• …..
• Symmetric mode
• Peer systems can synchronize with each other (usually used with stratum 1 & 2 servers)
12
© Baikuntha Acharya (baikunth2a@gmail.com)
Problems with Physical Time
✓ Relativistic issues:
• If A and B are far apart physically, and two events TA and TB are very close in
time, then which comes first? how do you know?
13
© Baikuntha Acharya (baikunth2a@gmail.com)
Logical Clocks
Lamport’s Logical Clocks
15
© Baikuntha Acharya (baikunth2a@gmail.com)
Implementation - Lamport’s Logical Clocks
✓ [R1]:
✓ [R2]:
• a) When a is the event of sending a message m from process Pi, then the timestamp tm =
CPi(a) is included in m (CPi(a) is the logical clock value obtained after applying rule R1).
• b) On receiving message m by process Pj, its logical clock CPj is updated as follows: CPj :=
max(CPj, tm).
• c) The new value of CPj is used to timestamp the event of receiving message m by Pj
(applying rule R1).
17
© Baikuntha Acharya (baikunth2a@gmail.com)
Lamport’s Logical Clocks (Cont..)
Problems
• We define:
• (CPi(a), i) < (CPj(b), j) if and only if
18
© Baikuntha Acharya (baikunth2a@gmail.com)
Lamport’s Logical Clocks (Cont..)
Problems (Cont..)
• However, the reverse is not always true (if the events occurred in different processes):
• if C(a) < C(b), then a → b is not necessarily true. (it is only guaranteed that b → a is not
true).
19
© Baikuntha Acharya (baikunth2a@gmail.com)
Lamport’s Logical Clocks (Cont..)
Problems (Cont..)
20
© Baikuntha Acharya (baikunth2a@gmail.com)
Vector Clocks
21
© Baikuntha Acharya (baikunth2a@gmail.com)
Vector Clocks (Cont..)
Implementation
✓ [R2]:
a) When a is the event of sending a message m
from process Pi , then the timestamp:
𝑡𝑚 = 𝐶𝑝𝑣𝑖 [𝑖] is included in m.
22
© Baikuntha Acharya (baikunth2a@gmail.com)
Vector Clocks (Cont..)
Causal Ordering from Timestamp
✓ If Send(M1) → Send(M2)
• then every recipient of both messages M1 and M2 must receive M1 before M2.
23
© Baikuntha Acharya (baikunth2a@gmail.com)
References
24
© Baikuntha Acharya (baikunth2a@gmail.com)