Time In Distributed Systems
Required Reading:
Optional Reading:
Summary
- Why do we need time?
- Why is measuring time hard in DS?
- Logical Time
- Common Notations
- Concurrent Events
- Lamport’s Scalar Clock
- Vector Clock
- Matrix Clock
Why do we need time?
Ordering:
- is easy in local systems
- helps us decide causality
- allows scheduling fairness and SLOs
Why is measuring time hard in DS?
It’s impossible to know how long network traffic will take
Node clocks are not gauranteed to be synchronized
No gaurantees there won’t be failures
Logical Time
Virtual time measured virtual clocks
- Generate time stamps
- Advance
- Can be used for ordering
Logical Clock can be thought of as a generator of timestamps.
- Scalar (Lamport’s) clocks
- process has knowledge of total number of events
- Vector clocks
- process has knowledge of how many events occured on which process
- Matrix clocks
- process has knowledge of which processes have knowledge about how many events occured at each process
- kind of like read-receipts
… if an event
a
causally affects an eventb
, then the timestamp ofa
must be smaller than the timestamp ofb
. [Logical Time]
Common Notations
generates events
- e sub i of k ‘happens before’ e sub i of k plus 1
- The kth event of the ith process ‘happens before’ the 1 + kth event of the ith process
:= ordered sequence of events in
- History of i
Events
- , have visible output
- at any node,
Concurrent Events
Concurrent Events := two events in which neither event happens before the Other
Lamport’s Scalar Clock
Each node has it’s own implementation of the clock which runs the clock rules to generate timestamps
Nodes only know the value of the timestamp that they computed
Clock Rules
- Process imcrements timestamp on successive events
- If a process receives a message, the new timestamp is the maximum of the message’s timestamp +1 and the processes original timestamp
Vector Clock
Each process maintains its own view of time at other nodes
Matrix Clock
Each process maintains its view about every other process’ view of the global time
Possible to use garbage collection, since we know all processes know everything that has happened past a certain point.