Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

logical clock

definition:
A logical clock is a mechanism for capturing chronological and causal relationships in
a distributed system.
o In a system of logical clocks, every process has a logical clock
o Every event is assigned a timestamp and the causality relation between events can be
generally inferred from their timestamps
o The timestamps assigned to events obey the fundamental monotonicity property.
o that is, if an event a causally affects an event b, then the timestamp of a is smaller than
the timestamp of b.
reason why to implement logical clock?
Due to geographical separation of autonomous machines of distributed systems , it can’t have a
physically synchronous global clock, so a logical clock allows global ordering on events from
different processes in such systems.

Implementing logical clocks


Implementation of logical clocks requires addressing two issues:
1. data structures local to every process to represent logical time
2. a protocol (set of rules) to update the data structures to ensure the consistency condition.

Issue 1:
Each process pi maintains data structures that allow it the following two capabilities:
1. A local logical clock that helps process pi measure its own progress.
2. A logical global clock that allows this process to assign consistent timestamps to its local
events.
Issue 2:
The protocol consists of the following two rules:
o R1 This rule governs how the local logical clock is updated by a process when it
executes an event (send, receive, or internal).
o R2 This rule governs how a process updates its global logical clock to update its view of
the global time and global progress.

Applications:
Logical clocks are useful in computation analysis, distributed algorithm design, individual event
tracking, and exploring computational progress.

Scalar time:
DEFINITION:
◦ The scalar time representation was proposed by Lamport in 1978.
◦ As an attempt to totally order events in a distributed system.
◦ Rules R1 and R2 to update the clocks are as follows:
 R1 Before executing an event (send, receive, or internal), process pi executes the
following:
Ci = Ci +d (d > 0)
 R2 Each message piggybacks the clock value of its sender at sending time. When a
process pi receives a message with timestamp Cmsg, it executes the following actions:
1. Ci = max (Ci,Cmsg);
2. execute R1;
3. deliver the message.

Consistency property
◦ Clearly, scalar clocks satisfy the monotonicity and hence the consistency property:
for two events ei and ej , ei→ej ⇒ C(ei) < C(ej ).

No strong consistency
◦ The system of scalar clocks is not strongly consistent;
that is, for two events ei and ej, C(ei) < C(ej) !⇒ ei → ej.
why scalar time is not strongly consistent?
◦ The reason that scalar clocks are not strongly consistent is that the logical local clock
and logical global clock of a process are squashed into one, resulting in the loss causal
dependency information among events at different processes.

Total Ordering
o Scalar clocks can be used to totally order events in a distributed system
o The main problem in totally ordering events is that two or more events at different
processes may have an identical timestamp.

Vector clock
Definition:
◦ The system of vector clocks was developed independently by Fidge, Mattern and
Schmuck.
◦ In the system of vector clocks, the time domain is represented by a set of n-dimensional
non-negative integer vectors.
◦ Rules R1 and R2 to update the clocks are as follows:
 R1 Before executing an event (send, receive, or internal), process pi executes the
following:
Vti[i] = vti[i] +d (d > 0)
 R2 Each message is piggybacked with vector clock vt of its sender at sending time. On
the receipt of such a message (m,vt), process pi executes following sequence of actions:
1. vti[k] = max (vti[k],vt[k]);
2. execute R1;
3. deliver the message.
isomorphism
o If events in a distributed system are timestamped using a system of vector clocks, we
have the following property.
o If two events x and y have timestamps vh and vk, respectively, then
x→y ⇔ vh < vk
x || y ⇔ vh vk
o Thus, there is an isomorphism between the set of partially ordered events produced by a
distributed computation and their vector timestamps

Strong Consistency:
o The system of vector clocks is strongly consistent; thus, by examining the vector
timestamp of two events, we can determine if the events are causally related.
o However, Charron–Bost showed that the dimension of vector clocks cannot be less than
n, the total number of processes in the distributed computation, for this property to hold.
Singhal–Kshemkalyani’s Differential Technique
◦ Singhal–Kshemkalyani’s differential technique is based on the observation that between
successive message sends to the same process, only a few entries of the vector clock at
the sender process are likely to change.
◦ When a process pi sends a message to a process pj , it piggybacks only those entries of
its vector clock that differ since the last message sent to pj .

◦ Thus this technique cuts down the message size, communication bandwidth and buffer
(to store messages) requirements.

Worst case
◦ In the worst of case, every element of the vector clock has been updated at pi since the
last message to process pj , and the next message from pi to pj will need to carry the
entire vector timestamp of size n.

Fowler–Zwaenepoel direct dependency technique:


◦ Fowler–Zwaenepoel direct dependency technique reduces the size of messages by
transmitting only a scalar value in the messages.
◦ No vector clocks are maintained on-the-fly.
◦ Instead, a process only maintains information regarding direct dependencies on other
processes.

Matric clock
A matrix clock is a mechanism for capturing chronological and causal relationships in
a distributed system.
Matrix clocks are a generalization of the notion of vector clocks.[1] A matrix clock maintains
a vector of the vector clocks for each communicating host.
Every time a message is exchanged, the sending host sends not only what it knows about the
global state of time, but also the state of time that it received from other hosts.
This allows establishing a lower bound on what other hosts know, and is useful in applications
such as checkpointing and garbage collection.
 Rules R1 and R2 to update the clocks are as follows:
 R1 Before executing an event (send, receive, or internal), process pi executes the
following:
mti[i,i] = mti[i,i]+d ; d > 0
 R2 Each message m is piggybacked with matrix clock mt. On the receipt of such a
message (m,mt), process pi executes following sequence of actions:
1. mti[i,k] = max( mti[i,k] , mt[j,k] ) ;
2. execute R1;
3. deliver the message.

Virtual time:
“Virtual time is a global, one-dimensional, temporal coordinate system on a distributed
computation to measure the computational progress and to define synchronization.”
Rules:
Virtual time systems are subject to two semantic rules similar to Lamport’s clock conditions:
o Rule 1: Virtual send time of each message < virtual receive time of that message.
o Rule 2: Virtual time of each event in a process < virtual time of next event in that
process.
The above two rules imply that a process sends all messages in increasing order of virtual send
time and a process receives (and processes) all messages in the increasing order of virtual
receive time.
Constraint:
The constraint in the implementation of virtual time can be stated as follows:
“If an event A causes event B, then the execution of A and B must be scheduled in real time so
that A is completed before B starts.”
Characteristics of virtual time:
1. Virtual time systems are not all isomorphic; they may be either discrete or continuous.
2. Virtual time may be only partially ordered (in this implementation, total order is assumed.)
3. Virtual time may be related to real time or may be independent of it.
4. Virtual time systems may be visible to programmers and manipulated explicitly as values, or
hidden and manipulated implicitly according to some system-defined discipline.
5. Virtual times associated with events may be explicitly calculated by user programs or they
may be assigned by fixed rules.
Time Warp Mechanism
The time warp mechanism consists of two major parts: local control mechanism and global
control mechanism.
1. The local control mechanism ensures that events are executed and messages
are processed in the correct order.
2. The global control mechanism takes care of global issues such as global
progress, termination detection, I/O error handling, flow control, etc.

You might also like