Presentation is loading. Please wait.

Presentation is loading. Please wait.

Leslie Lamport Massachusetts Computer Associates, Inc. Presented by Lokendra 1.

Similar presentations

Presentation on theme: "Leslie Lamport Massachusetts Computer Associates, Inc. Presented by Lokendra 1."— Presentation transcript:

1 Leslie Lamport Massachusetts Computer Associates, Inc. Presented by Lokendra 1

2 A common Resource Node A Node B request A request B A Distributed System Q. WHICH REQUEST WAS MADE FIRST? 2

3 Solution A Global Clock ?? Global Synchronization? A common Resource Node A Node B request A request B A Distributed System Q. WHICH REQUEST WAS MADE FIRST? 3

4 Individual Clocks? Are individual clocks accurate, precise? One clock might run faster/slower? Q. WHICH REQUEST WAS MADE FIRST? A common Resource Node A Node B request A request B A Distributed System Solution 10:00 AM 10:02 AM 4

5 Synchronization in a Distributed System! Event Ordering : Which event occurred first? How to sync the clocks across the nodes? Can we define notion of happened-before without using physical clocks? 5

6 Develop a logical model of event ordering (without the use of physical clocks) Might result into Anomalous Behavior? Bring in Physical Clocks to integrate with the logical model Fix anomalous behavior Make sure that the Physical Clocks are synced. 6

7 The system is composed of a collection of processes Each process consists of a sequence of events (instructions/subprogram) Process P : instr1 instr2 instr3 … (Total Order) Sending and Receiving messages among processes Send : an event Receive : an event 7

8 a Happened Before b : ab 1. If a and b are events in the same process, and a comes before b, then a b. 2. If a :message sent b : receipt of the same message then a b. 3. If a b and b c then a c. 4. Two distinct events a and b are said to be c oncurrent if a -/->b and b -/->a 8

9 9 p1 p2 p1 q2 p1 r4 q2 -/-> p2 q3 -/-> p2

10 A clock C i for each process P i to be a function which assigns a number C i (a) to any event a in that process. Logical Clock ( C i ) has no relation with the Physical Clock. Clock Condition: For any event a, b: If ab, then C(a) < C(b) Converse NOT True! Concurrent processes? Clock Condition is satisfied if : C1. If a and b are events in process P i, and a comes before b, then C i (a) < C i (b). C2. If a is the sending of a message by process P i and b is the receipt of that message by process P j, then C i (a) < C j (b) 10

11 11 A clock ticks through every event The clicks happen between the events

12 Following implementation rules are proposed to satisfy the clock condition: IR1. Each process P i increments Ci between any two successive events. IR2. (a) If event a is the sending of a message m by process P i, then the message m contains a timestamp T m = C i (a). (b) Upon receiving a message m, process P i sets C i greater than or equal to its present value and greater than T m. 12

13 13 Correction of clocks

14 One more relation < to break ties, arbitrary total order of events The total order relation => is defined as: a => b, if and only if (i) C i (a) < C j (b) (ii) C i (a) = C j (b) and P i < P j 14

15 I. A process using the resource must release it before it can be given to another process. II. Requests for the resource must be granted in the order in which they were made. I. Does not indicate what should be done when two processes request for the resource at the same time? III. If every process using the resource eventually releases it, then every request is eventually granted (no starvation) 15

16 Each process maintains its own request queue: The Algorithm: 1. Resource request: 1. Process P i sends the message T m : P i requests resource to every other 2. P i also puts the request message on its request queue. 2. Resource request receipt.: 1. P i receives P i s request message. 2. P j then puts the message on its request queue 3. P j sends an acknowledgement to P i (timestamped later) 3. Resource release: 1. P i removes request message T m : Pi requests resource from its queue 2. sends the release message P i releases resource to every other process. 4. Resource release receipt 1. P j receives P i s resource release message. 2. Pj removes the T m : P i requests resource from its request queue. 5. Resource allocation. P i is allocated the resource when: 1. There is a T m : P i requests resource message in P i s request queue which is ordered before and other request in the queue by ). 2. P i has received messages from every other process timestamped later than T m. 16

17 NOTE: Each process independently follows these rules There is no central synchronizing process or central storage. Can be viewed as State Machine C x S S C : set of commands for eg resource request S : Machines state 17

18 18

19 Two possible ways to avoid such anomalous behavior: 1. Give the user the responsibility for avoiding anomalous behavior. When the call is made, b be given a later timestamp than a. 2. Let S : set of all system events Š : Set containing S + relevant external events Let denote the happened before relation for Š. Strong Clock Condition: For any events a; b in Š : if a b then C(a) < C(b) One can construct physical clocks, running quite independently, and having the Strong Clock Condition, therefore eliminating anomalous behavior. 19

20 PC1: | dC i (t)/dt - 1 | < ĸ ĸ <<1 PC2: For all i,j : |C i (t) – C j (t)| < 2 clocks dont run at the same rate: They may drift further Need of an algorithm that PC2 always holds 20

21 Let μ be a number such that a b and a occurs at t in P i and b in P j, then b occurs later than t+ μ μ : less than the shortest transmission time To avoid anomalous behavior, we need: C i (t+ μ ) – C j (t) > 0, guaranteed if /(1- ĸ) μ 21

22 μ m is the minimum delay of a message and is known by the processes IR1 : For each i, C i is differentiable at t and dC i (t)/dt >0 IR2: a) P i sends a message at t, timestamp T m =C i (t) Upon receipt of m, Pj sets Cj(t) to max (Cj(t), T m + μ m ) 22

23 Lamport clocks limitation: If (a b) then C(a) < C(b) but Reverse is not true!! Nothing can be said about events by comparing time- stamps! If C(A) < C(B), then ?? Need to maintain causality Causal delivery : If send(m) -> send(n) => deliver(m) -> deliver(n) Need a time-stamping mechanism such that: If T(A) < T(B) then A should have causally preceded B 23

24 24 (1, 0, 0)(2, 0, 0)(3, 5, 2) e11 e12 e13 (0, 1, 0) (2, 2, 0)(2, 3, 1) (2, 5, 2) (0, 0, 1) (0, 0, 2) e21 e22 e23 e24 e31 e32 P1 P2 P3 (2,4,2) e25 Each process i maintains a vector V i V i [i] : number of events that have occurred at i V i [j] : number of events i knows have occurred at process j Less than or equal: ts(a) ts(b) if ts(a)[i] is ts(b)[i] for all i. For eg [ (3,3,5) (3,4,5) ] ts(e11) = (1, 0, 0) and ts(e22) = (2, 2, 0), which shows e11 e22 Causal Delivery : if m is sent by P 1 and ts(m) is (3, 4, 0) and you are P 3, you should already have received exactly 2 messages from P 1 and at least 4 from P 2

25 25

26 Happens Before is just partial ordering To make it total, arbitrary ties method can be used But can lead to Anomalous behavior But we can use synchronized clocks to resolve 26

27 27

Download ppt "Leslie Lamport Massachusetts Computer Associates, Inc. Presented by Lokendra 1."

Similar presentations

Ads by Google