leslie lamport massachusetts computer associates, inc. presented by lokendra 1

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

Upload: abby-janeway

Post on 29-Mar-2015

234 views

Category:

Documents


0 download

TRANSCRIPT

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

Leslie LamportMassachusetts Computer

Associates, Inc.

Presented by Lokendra

1

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

A common ‘Resource’

Node A Node B

request A request B

A Distributed System

Q. WHICH REQUEST WAS MADE Q. WHICH REQUEST WAS MADE FIRST?FIRST?

2

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

SolutionSolution

A Global Clock ??

Global Synchronization?

A common ‘Resource’

Node A Node B

request A request B

A Distributed System

Q. WHICH REQUEST WAS MADE Q. WHICH REQUEST WAS MADE FIRST?FIRST?

3

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

Individual Clocks?

Are individual clocks accurate, precise?

One clock might run faster/slower?

Q. WHICH REQUEST WAS MADE Q. WHICH REQUEST WAS MADE FIRST?FIRST?A common

‘Resource’

Node A Node B

request A request B

A Distributed System

SolutionSolution

10:00 AM 10:02 AM

4

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

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

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

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

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

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

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

a ‘Happened Before’ b : a→b1. If a and b are events in the same process,

and a comes before b, then a → b.

2. If a :message sentb : 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 concurrent if a -/->b and b -/->a

8

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

9

p1 → p2

p1 → q2

p1 → r4

q2 -/-> p2

q3 -/-> p2

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

A clock Ci for each process Pi to be a function which assigns a number Ci(a) to any event a in that process.

Logical Clock (Ci ) has no relation with the Physical Clock.

Clock Condition:For any event a, b: If a→b, then C(a) < C(b)

Converse NOT True! • Concurrent processes?

Clock Condition is satisfied if :C1. If a and b are events in process Pi, and a comes before

b, then Ci(a) < Ci(b).C2. If a is the sending of a message by process Pi and b is

the receipt of that message by process Pj, thenCi(a) < Cj(b)

10

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

11

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

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

Following implementation rules are proposed to satisfy the clock condition:

IR1. Each process Pi increments Ci between any two successive events.

IR2. (a) If event a is the sending of a message m by process Pi, then the message m contains a timestamp Tm = Ci (a).

(b) Upon receiving a message m, process Pi sets Ci greater than or equal to its present value and greater than Tm.

12

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

13

Correction of clocks

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

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) Ci(a) < Cj(b)(ii) Ci(a) = Cj(b) and Pi< Pj

14

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

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

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

Each process maintains its own request queue:

The Algorithm:1. Resource request:

1. Process Pi sends the message Tm : Pi requests resource to every other 2. Pi also puts the request message on its request queue.

2. Resource request receipt.:1. Pi receives Pi’s request message. 2. Pj then puts the message on its request queue 3. Pj sends an acknowledgement to Pi (timestamped later)

3. Resource release:1. Pi removes request message Tm : Pi requests resource from its queue 2. sends the release message Pi releases resource to every other process.

4. Resource release receipt 1. Pj receive’s Pi’s resource release message. 2. Pj removes the Tm : Pi requests resource from its request queue.

5. Resource allocation. Pi is allocated the resource when:

1. There is a Tm : Pi requests resource message in Pi ’s request queue which is ordered before and other request in the queue by ).

2. Pi has received messages from every other process timestamped later than Tm .16

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

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 : Machine’s state

17

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

18

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

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 eventsLet → 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

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

PC1: | dCi(t)/dt - 1 | < ĸĸ <<1

PC2: For all i,j : |Ci(t) – Cj(t)| < ԑ

2 clocks don’t run at the same rate:• They may drift further

Need of an algorithm that PC2 always holds

20

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

Let μ be a number such that a→b and a occurs at t in Pi and b in Pj, then b occurs later than t+ μ • μ : less than the shortest transmission time

To avoid anomalous behavior, we need:

Ci(t+ μ) – Cj(t) > 0, guaranteed if ԑ/(1- ĸ) ≤ μ

21

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

μm is the minimum delay of a message and is known by the processes

IR1’ : For each i, Ci is differentiable at t and dCi(t)/dt >0

IR2’: • a) Pi sends a message at t, timestamp Tm=Ci(t)• Upon receipt of m, Pj sets Cj(t’) to max (Cj(t’),

Tm+ μm )

22

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

Lamport clocks limitation: • If (ab) 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

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

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 Vi

Vi[i] : number of events that have occurred at iVi[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 P1 and ts(m) is (3, 4, 0) and you are P3, you should already have received exactly 2 messages from P1 and at least 4 from P2

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

25

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

‘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

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

27