Sie sind auf Seite 1von 15

Synchronization: Theoretical Foundation

Introduction
A DS is a collection of computers that are spatially separated and do not share a common memory Processes communicate by exchanging messages over communication channel Messages are delivered after an arbitrary transmission delay DS suffers some inherent limitations because of lack of common memory and a systemwide common clock How these limitations can be overcome?

Absence of a Global Clock


There is no system-wide common clock in a DS Solutions can be:
Either having a global clock common to al the computers, or Having synchronized clocks, one at each computer

Both of the above solutions are impractical due to following reasons:


If one global clock is provided in the ds:
Two processes will observe a global clock value at different instants due to unpredictable delays So two processes will falsely perceive two different instants in physical time to be a single instant in physical time

if the clocks of different systems are tried to synchronize:


These clocks can drift from the physical time and the drift rate may vary from clock to clock due to technological limitations This may also end up with the same result We cannot have a system of perfectly synchronized clocks

Impact of the absence of global time


Temporal ordering of events is integral to the design and development of DS E.g.
an OS is responsible for scheduling processes A basic criterion used in scheduling is the temporal order in which requests to execute processes arrive Due to the absence of the global time, it is difficult to reason about the temporal order of events in a DS Hence, algorithms for DS are more difficult to design and debug Also, the up-to-date state of the system is harder to collect

Absence of shared memory


Due to the lack of shared memory, an up-to-date state of the entire system is not available to any individual process It is necessary for reasoning about the systems behavior, debugging and recovery A process in a DS can obtain a coherent but partial view or a complete but incoherent view of the system A view is said to be coherent if all the observations of different processes are made at the same physical time A complete view includes the local views (local states) at all the computers and any messages that are in transit in the DS A complete view is also referred to as global state

Example
Local state of A Local state of B

(a)

$500 S1: A

Communication Channel

$200 S2: B

(b)

$450 S1: A

$200 S2: B

(c)

$500

S1: A

$250
7

Lamports Logical Clock: Basic Concepts


Lamport proposed the following scheme to order events in a distributed system using logical clocks.
The execution of processes is characterized by a sequence of events Depending on the application, the execution of a procedure could be one event or the execution of an instruction could be one event When processes exchange messages, sending a message constitutes one event and receiving a message constitutes one event.

Lamports Logical Clock: Happened before relationship


Due to the absence of perfectly synchronized clocks and global time in distributed systems, the order in which two events occur at two different computers cannot be determined based on the local time at which they occur under certain conditions, it is possible to ascertain the order in which two events occur based solely on the behavior exhibited by the underlying computation. The happened before relation(--->) captures the causal dependencies between events, i.e., whether two events are causally related or not. The relation + is defined in the following slide.

Lamports Logical Clock


a b, if a and b are events in the same process and a occurred before b. a b, if a is the event of sending a message m in a process and b is the event of receipt of the same message rn by another process. If a b and b c , then a c , i.e., " " relation is transitive In distributed systems, processes interact with each other and affect the outcome ot events of processes Being able to ascertain order between events is very important for designing, debugging, and understanding the sequence of execution in distributed computation.

Lamports Logical Clock: Events


In general, an event changes the system state, which in turn influences the occurrence and outcome of future events past events influence future events and this influence among causally related events (those events that can be ordered by ) is referred to as causal affects.

Lamports Logical Clock: Events


CASUALLY RELATED EVENTS: Event a

causally affects event b if a b. CONCURRENT EVENTS: Two distinct events a and b are said to be concurrent (denoted by a||b) if a / b and b/ a. For any two events a and b in a system, either a, b a, or a||b

Lamports Logical Clock: Events

e11 P1
Space

e12

e13

e14

e21 P2

e22

e23
Global time

e24

COT3002 Distributed Computing Systems

A.Zaslavsky, Lecture 5:Theoretical Foundations of DS

Lamports Logical Clock:Events


In order to realize the relation , Lamport introduced the following system of logical clocks.
There is a clock Ci at each process Pi in the system. The clock Ci can be thought of as a function that assigns a number Ci(a) to any event a, called the timestamp of event a, at Pi. The numbers assigned by the system of clocks have no relation to physical time, and hence the name logical clocks. The logical clocks take monotonically increasing values. These clocks can be implemented by counters. Typically, the timestamp of an event is the value of the clock when it occurs.

Lamports Logical Clock: Conditions


For any events a and b: if a b, then C(a) < C(b) The happened before relation can now be realized by using the logical clocks if the following two conditions are met:
[C1] For any two events a and b in a process Pi, if a occurs before b, then Ci(a) < Ci(b) [C2] If a is the event of sending a message m in process Pi and b is the event of receiving the same message m at process Pj, then Ci(a) < Cj(b)

The following implementation rules (IR) for the clocks guarantee that the clocks satisfy the correctness conditions Cl and C2:

Lamport Logical Clock: Implementation Rules


[IR1] Clock Ci is incremented between any two successive events in process Pi:
Ci:=Ci+d (d>0) lf a, and b are two successive events in Pi and Ci(b) = Ci(a) + d. a b, then

[IR2] If event a is the sending of message m by process Pi, then message m is assigned a timestamp tm, = Ci(a) (note that the value of Ci(a) is obtained after applying rule IRI). On receiving the same message m by process Pj, Cj is set to a value greater than or equal to its present value and greater than tm Cj := max(Cj, tm + d) (d > 0)

Lamports logical Clock: How does it advance?


Lamport's happened before relation, () defines an irreflexive partial order among the events The set of all the events in a distributed computation can be totally ordered (the ordering relation is denoted by ) using the above system of clocks as follows:
If a is any event at process Pi and b is any event at process Pj then a b if and only if either
Ci(a) < Cj(b) or Ci(a) = Cj(b) and Pi < Pjwhere < is any arbitrary relation that totally orders the processes to break ties A simple way to implement < is to assign unique identification numbers to each process and then Pi < Pj , if i < j.

Lamports logical Clock: How does it advance?


e11 P1
Space
Clock values

e12
(2) (2)

e13
(3)

e14
(4) (3)

e15
(5)

e16
(6) (4)

e17
(7) (7)

(1) (1)

e21 P2

e22

e23

e24

e25

Global time

Lamports Logical Clock: Limitations


In Lamport's system of logical clocks, if a b then C(a) < C(b) But, the reverse is not necessarily true if the events have occurred in different processes i.e. if a and b are events in different processes and C(a) < C(b), then a b is not necessarily true; events a and b may be causally related or may not be causally related So, Lamport's system of clocks is not powerful enough to capture such situations

Lamports Logical Clock: Limitations


e11 P1 P2
Space (1)

e12
(2)

e21
(1)

e22
(3)

P3

e31
(1)

e32
(2) Global time

e33
(3)

Vector Clock
The system of vector clocks was independently proposed by Fidge and Mattern:
Let n be the number of processes in a distributed system Each process Pi is equipped with a clock Ci(a), which is an integer vector of length n The clock Ci can be thought of as a function that assigns a vector Ci(a) to any event a Ci(a) is referred to as the timestamp of event e1 at Pi. Ci[I] the ith entry of Ci, corresponds to Pi's own logical time Ci[j] is Pi's best guess of the logical time at Pj. More specifically, at any point in time, the jth entry of Ci indicates the time of occurrence of the last event at Pj which "happened before" the current point in time at Pi This "happened before" relationship could be established directly by communication from Pj to Pi or indirectly through communication with other processes.

The figure illustrates an example of how clocks advance and the dissemination of time occurs in a system using vector clocks (d is assumed to be 1 and all clock values are initially zero) Thus, the system of vector clocks allows us to order events and decide whether two events are causally related or not by simply looking at the timestamps of the events If we know the processes where the events occur, the above test can be further simplified

(1,0,0)

(2,0,0)

(3,4,1)

P1
Space

e11
(0,1,0)

e12
(2,2,0) (2,3,1)

e13
(2,4,1)

P2 e21 P3
(0,0,1)

e22 e31
Global time

e23
(0,0,2)

e24 e32

Global State
Recording the consistent global state is a challenging task due to the absence of a global clock and shared memory A global state is a combination of local states of all machines and the channel A recorded global state may be inconsistent if n>n,
Where n is the number of messages sent by A along the channel before As state was recorded And, n is the number of messages sent by A along the channel before the channels state is recorded

Similarly, a consistent global state requires n=n

Example
Local state of A Local state of B

(a)

$500 S1: A

C1:Empty
$200

C2:Empty C1:Transfer $50

S2: B

(b)

$450 S1: A

$200

C2:Empty C1:Empty

S2: B

(c)

$500

$250

C2:Empty

25

Definitions
Local State: For a site Si, its local state at a given time is defined by the local context of the distributed application, denoted by, LSi Global State: A global state GS of a system is a collection of the local states of its sites GS={LS1, LS2, LS3,,LSn{, where n is the no. of sites, in the system Consistent Global State: For every received message a corresponding sent event is recorded in the global state

Inconsistent global state: in an inconsistent global state, there is atleast one message whose received event is recorded but its send event is not recorded in the global state Transitless state: A global state is transitless if and only if, all communication channels are empty. Strongly consistent state: A state is strongly consistent if it is consistent and transitless
In a strongly consistent state, not only the send events of all the recorded received events are recorded, but the receive events of all the recorded send events are also recorded

Global State:

S1 S2 S3

LS11 LS21

LS12 LS22 LS23

LS31

LS32

LS32

Chandy-Lamports Global State Recording Algorithm


First proposal to capture a consistent global state Algorithm uses a marker to initiate the algorithm and the marker has not effect on the underlying computation Communication channels are assumed to be FIFO Recorded global state is also referred to as a snapshot of the system state

Algorithm
Marker Sending Rule for a process P
P records its state For each outgoing channel C from P on which a marker has not been already sent, P sends a marker along C before P sends further messages along C

Marker Receiving Rule for a process Q


If Q has not recorded its state, then begin Record the state of C as an empty sequence Follow the Marker Sending Rule end Else Record the state of C as the sequence of messages received along C after Qs state was recorded and before Q received the marker along C

Das könnte Ihnen auch gefallen