Timing in Distributed Systems
Timing in Distributed Systems
Systems
Lecture 2
Event ordering in space
star star
event e2
event e1
spaceship
spaceship
observes
observes
e1 before e2
e2 before e1
2
Does accurate time matter?
Important questions:
How accurate does time need to be?
How is time used in a distributed system?
What does “A happened before B” mean in a distributed system?
3
Use of time in distributed systems: examples 1
1. Any source of resource contention e.g. Airline booking
This can be made unlikely to happen, if we ensure that clocks are initialised
accurately
e.g. not from the operator’s watch, but from a “time server”.
Note that some of the above examples require only a means of agreement,
so that all participants in the algorithm make the same decision.
Others require accurate time, or the order of events in the real world,
when causality is at issue.
7
Local clocks must respect true event orderings
X Y
x1
y1
IPC
send ( m, tx )
x2 receive ( m, tx ) at ty
y2
BUT system time adjusted in this way will drift ahead of UTC
- could use counters rather than timestamps if all we need is event ordering
- so-called “Lamport Time”
How can we generate timestamps that are reasonably close to UTC and preserve causal
ordering?
8
Logical clocks
9
Lamport’s Logical Clocks (1)
The "happens-before" relation → can be
observed directly in two situations:
• If a and b are events in the same process, and a
occurs before b, then a → b is true.
• If a is the event of a message being sent by one
process, and b is the event of the message being
received by another process, then a → b
10
Lamport’s Logical Clocks (2)
Three processes, each with its own clock. The clocks run at different rates.
11
Lamport’s Logical Clocks (3)