Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

2,712 views

Published on

lamport timestamps, vector clocks

No Downloads

Total views

2,712

On SlideShare

0

From Embeds

0

Number of Embeds

3

Shares

0

Downloads

69

Comments

0

Likes

3

No embeds

No notes for slide

- 1. Logical Clocks Dani Kim (dani.kim@geekple.com)Tuesday, September 20,
- 2. Why use it? • In a distributed system, used to determine the order of eventsTuesday, September 20,
- 3. Lamport timestamps 1/2 • will not be perfectly synchronized • but, simple algorithm • minimal overhead • each process P has its own clock CTuesday, September 20,
- 4. Lamport timestamps 2/2 • Increments counter before each event • When a process sends a message, it includes its counter with the message • On receiving a message, receiver’s counter = max(received counter, own counter) + 1Tuesday, September 20,
- 5. Happend-Before (->) • If ‘a’ and ‘b’ occur on same process, a->b if event ‘a’ occur before ‘b’ • if ‘a’ is the sending of a message and ‘b’ is the reception of the message sent in event ‘a’, a->bTuesday, September 20,
- 6. Concurrent (||) • “not (a->b)” and “not (b->a)” • these events are concurrent • a||bTuesday, September 20,
- 7. Example 1 1 1 P1 P2 P3 P4Tuesday, September 20,
- 8. Example 4 3 2 2 1 1 1 P1 P2 P3 P4Tuesday, September 20,
- 9. Example 5 4 3 2 2 1 1 1 P1 P2 P3 P4Tuesday, September 20,
- 10. Example 5 2 1 4 3 2 1 1 P1 P2 P3 P4Tuesday, September 20,
- 11. Features • If a->b, then C(a) < C(b) • But C(a) < C(b) does not imply a->b • Just C(a) <= C(b) implies “not (b->a)” • “not (b->a)” is equivalent a->b or a||b • (P1, 1) <= (P3, 3), (P1, 1) || (P3, 3)Tuesday, September 20,
- 12. Vector Clocks 1/2 • more powerful of Lamport timestamp • use several clocks instead of a single clockTuesday, September 20,
- 13. Vector Clocks 2/2 • Each time a process experiences an internal event, it increments its own logical clock in the vector by one • Each time a process prepares to send a message, it increments its own logical clock in the vector by one and then send its entire vector along with the message being sent • Each time a process receives a message, it increments its own logical clock in the vector by one and updates each element in its vector by taking the maximum of the value in its own vector clock and the value in the vector in the received message • http://en.wikipedia.org/wiki/Vector_clocksTuesday, September 20,
- 14. Example [0,0,0,1] [0,1,0,0] [1,0,0,0] P1 P2 P3 P4Tuesday, September 20,
- 15. Example [0,1,3,1] [0,1,2,1] [0,1,1,0] [1,2,0,0] [0,0,0,1] [0,1,0,0] [1,0,0,0] P1 P2 P3 P4Tuesday, September 20,
- 16. Example [2,1,3,1] [0,1,3,1] [0,1,2,1] [0,1,1,0] [1,2,0,0] [0,0,0,1] [0,1,0,0] [1,0,0,0] P1 P2 P3 P4Tuesday, September 20,
- 17. Example [2,1,3,1] [1,2,0,0] [1,0,0,0] [0,1,3,1] [0,1,2,1] [0,1,1,0] [0,0,0,1] [0,1,0,0] P1 P2 P3 P4Tuesday, September 20,
- 18. Pseudo code function is_concurrent(own[], other[]) greater=false, less=false FOR i = 0 to numberOfElements by 1 IF own[i] > other[i] THEN greater = true ELSE own[i] < other[i] less = true IF greater AND less THEN RETURN true ELSE RETURN falseTuesday, September 20,
- 19. Features • if x->y, then VC(x) < VC(y) • if VC(x) < VC(y), then x->y • if VC(x) < VC(y), then “not (y->x)”Tuesday, September 20,
- 20. Conclusion • They do not resolve conﬂicts by themselvesTuesday, September 20,
- 21. References • http://en.wikipedia.org/wiki/Vector_clock • http://en.wikipedia.org/wiki/Logical_clockTuesday, September 20,

No public clipboards found for this slide

Be the first to comment