YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Lamport clocks

1

Lamport clocks

Dave [email protected]

Page 2: Lamport clocks

1

Synchronization

● No class Friday– Spring Carnival (“Mobot” races @ noon)

Page 3: Lamport clocks

1

Outline (not)

● Chapter 15 (“Distributed System Structures”)– Zooming past distributed systems

● Process migration!

– Network protocol stacks● “The Internet in one easy lesson”

– You can read it yourselves...● ...and you probably should.

Page 4: Lamport clocks

1

Outline

● Lamport clocks– Covered in 17.1, 17.2 (different focus from today)– Time, Clocks, and the Ordering of Events in a

Distributed System● CACM 21:7 (1978)

Page 5: Lamport clocks

1

Overview

● Light cones● Meeting for beer● “Happened before” partial order● Logical clocks● Advanced techniques

Page 6: Lamport clocks

1

Light cones

● Concept– Effects propagate at or below speed of light

● Objects, light/radio/X-rays, gravity

– Knowledge of events limited the same way– Event propagation modeled by expanding sphere

● Four-dimensional “cone”

Page 7: Lamport clocks

1

Light cones

Space

Tim

e

Page 8: Lamport clocks

1

Light cones

Space

Tim

e

Page 9: Lamport clocks

1

Light cones

Space

Tim

e

Page 10: Lamport clocks

1

Light cones

Space

Tim

e

Page 11: Lamport clocks

1

Light cones

Space

Tim

e

Page 12: Lamport clocks

1

Light cones

Space

Tim

e

Page 13: Lamport clocks

1

Light cones

Space

Tim

e

Page 14: Lamport clocks

1

Light cones

Space

Tim

e

Page 15: Lamport clocks

1

Light cones

● Future light cone– The part of spacetime influenced by an event

● Past light cone– The part of spacetime that could have influenced an

event

Page 16: Lamport clocks

1

Meeting for Beer

● P1 transmits “Panther Hollow Inn” to blackboard

Page 17: Lamport clocks

1

Meeting for Beer

● P1 transmits “Panther Hollow Inn” to blackboard● P1 transmits to P2

– Hey, P2, let's go have a beer.– I have transmitted the bar's name to the blackboard.– See you there!

Page 18: Lamport clocks

1

Meeting for Beer

● P1 transmits “Panther Hollow Inn” to blackboard● P1 transmits to P2

– Hey, P2, let's go have a beer.– I have transmitted the bar's name to the blackboard.– See you there!

● P2 receives P1's message

Page 19: Lamport clocks

1

Meeting for Beer

● P1 transmits “Panther Hollow Inn” to blackboard● P1 transmits to P2

– Hey, P2, let's go have a beer.– I have transmitted the bar's name to the blackboard.– See you there!

● P2 receives P1's message● P2 queries blackboard

Page 20: Lamport clocks

1

Meeting for Beer

● P1 transmits “Panther Hollow Inn” to blackboard● P1 transmits to P2

– Hey, P2, let's go have a beer.– I have transmitted the bar's name to the blackboard.– See you there!

● P2 receives P1's message● P2 queries blackboard● It says “Squirrel Cage” - how???

Page 21: Lamport clocks

1

Meeting for Beer

P1

board

P2

Page 22: Lamport clocks

1

Meeting for Beer

P1

board

P2

Page 23: Lamport clocks

1

Meeting for Beer

P1

board

P2

Page 24: Lamport clocks

1

Meeting for Beer

P1

board

P2

Page 25: Lamport clocks

1

Meeting for Beer

P1

board

P2

Page 26: Lamport clocks

1

Meeting for Beer

P1

board

P2

Page 27: Lamport clocks

1

What went wrong?

● P1 thought– Blackboard update happened before invitation

● P2 thought– Invitation happened before blackboard update

● When does an event “happen”?– When its effects propagate “everywhere relevant”

● What does “happen before” mean?● Could that green node really be so slow?

Page 28: Lamport clocks

1

Universe Model

● System = set of processes● Process = sequence of events● Event

– Internal: ++x;– Message transmission– Message reception

Page 29: Lamport clocks

1

“Happened before” partial order

● A happens before B (A B)– If A and B happen inside a process, in that order– A = transmission, B = reception, of same message– If A B and B C, then A C

● A and B are concurrent when– A ! B and B A

● Observe A ! A

Page 30: Lamport clocks

1

Space-time Diagram●

– inside a process, or– follow a message

● p0 r2● concurrent

– p0, q0, r0– p1, q1– q1, r0– p1, r0

p0

p1

p2

q0

q1

q2

r0

r1

r2

Page 31: Lamport clocks

1

means “possibly causes”

● p0 possibly causes p1– ...by storing something in P's memory

● p0 possibly causes q1– Message could trigger q1

● Concurrent events– ...cannot cause each other

Page 32: Lamport clocks

1

Logical clocks

● Can we assign timestamps to events?● Want

– If A B then C(A) < C(B)

● Events inside Pi

– a b Ci(a) < C

i(b)

● Message from Pi to P

j

– a=Pi's send, b=P

j's receive C

i(a) < C

j(b)

Page 33: Lamport clocks

1

Logical clocks

● Events inside Pi

– Increment Ci() between successive events

● Message from Pi to P

j

– Sender: place timestamp T in message: Ci(send)

– Receiver: ensure Cj(receive) > T

Page 34: Lamport clocks

1

Meeting for Beer

53

3 4

27

Page 35: Lamport clocks

1

Meeting for Beer

53

54 4

27

Page 36: Lamport clocks

1

Meeting for Beer

54

54 4

55

Page 37: Lamport clocks

1

Meeting for Beer

54

54 57

56

Page 38: Lamport clocks

1

Meeting for Beer

54

54 58

59

Page 39: Lamport clocks

1

Meeting for Beer

54

55 59

59

Page 40: Lamport clocks

1

What this means

● P1 wants– <“PHI” on board> happened before <P2 read board>

● Equivalent to “59 < 58” (oops)● The events were concurrent● “PHI” could not cause P2's bar trip

Page 41: Lamport clocks

1

Fixing the problem

● P1 should wait for board to acknowledge● “PHI” causes ACK● ACK causes “Meet me at...”● “Meet me at...” causes bar trip● Then: “PHI” causes bar trip

Page 42: Lamport clocks

1

Extensions

● Define total ordering of system events– Typical (timestamp, process #) tuple comparison

● Process # used to break timestamp ties

● Distributed agreement algorithms– Such as “fair distributed mutual exclusion”

● Requests must be granted “in order”● See text: 17.2

● Adding physical (real-time) clocks

Page 43: Lamport clocks

1

Summary

● Light cones● “Happened before" partial order● Potential causality● Another definition of concurrency● Timestamps track message causality


Related Documents