Summary
In a distributed system, the notion of physical time is weak since each node has its own clock. Hence we need a different way to obtain an ordering of events and a clock that all nodes agree upon independent of each node’s internal clock. In this paper, we assume that sending a message and receiving a message are two events. This allows us to obtain a partial order independent of the physical clock. In particular,
and happens within the same process and happens before is sending a message and is receiving the same message- There is another event
s.t. and
Notice that this ordering definition is only a partial ordering. If for two events
Using this ordering definition, we can define logical clocks. Let
- If
and happens on the same process and comes before , then - If
is the sending of a message from process and is the receiving of the same message from process , then .
The algorithm hence does the following:
- Each process increments its local clock for each event it encounters.
- Each message are tagged with a timestamp of the sender. When a process receives a message from another process, it sets its local clock to be greater than the attached timestamp from the sender and greater than or equal to its current local timestamp.
With such a logical clock, we can construct a total ordering (
One problem remaining is that, with a logical clock, the distributed system is not aware of the time of external events. For example, if client
- There exists a constant
s.t. . - There exists a small constant
s.t. .
The first condition is achieved through hardware: for typical crystal controlled clocks,
Vector Clocks
There are, however, some disadvantages in the logical clock defined in this paper. Recall that when
- For local operations, the process
simply increments its own counter . - When sending a message, in addition to incrementing its own counter
, it will also send the updated (all clocks) along with the message. - Upon receiving the message, the receiver
will first update its own counter . Then, for , it updates the local clock by .
Then for any two events
if for all if and that for some .
A noticeable drawback of vector clocks is that each process is locally keeping a clock for all other processes, leading to higher space overhead. Additionally, it also makes it harder for nodes to enter and exit the distributed system since that means we need to dynamically allocate space for more clocks on each node.
L. Lamport. Time, Clocks, and the Ordering of Events in a Distributed SystemLinks to an external site.. Communications of the ACM, July 1978, pages 558-564.