Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Logical clocks

Logical clocks

dgkim84

July 18, 2012
Tweet

More Decks by dgkim84

Other Decks in Technology

Transcript

  1. Why use it? • In a distributed system, used to

    determine the order of events 5VFTEBZ 4FQUFNCFS 
  2. Lamport timestamps 1/2 • will not be perfectly synchronized •

    but, simple algorithm • minimal overhead • each process P has its own clock C 5VFTEBZ 4FQUFNCFS 
  3. 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) + 1 5VFTEBZ 4FQUFNCFS 
  4. 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->b 5VFTEBZ 4FQUFNCFS 
  5. Concurrent (||) • “not (a->b)” and “not (b->a)” • these

    events are concurrent • a||b 5VFTEBZ 4FQUFNCFS 
  6. Example 1 P1 P2 P3 P4 1 1 2 2

    3 4 5VFTEBZ 4FQUFNCFS 
  7. Example 1 P1 P2 P3 P4 1 1 2 2

    3 4 5 5VFTEBZ 4FQUFNCFS 
  8. Example 1 P1 P2 P3 P4 1 1 2 2

    3 4 5 5VFTEBZ 4FQUFNCFS 
  9. 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) 5VFTEBZ 4FQUFNCFS 
  10. Vector Clocks 1/2 • more powerful of Lamport timestamp •

    use several clocks instead of a single clock 5VFTEBZ 4FQUFNCFS 
  11. 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_clocks 5VFTEBZ 4FQUFNCFS 
  12. Example [1,0,0,0] P1 P2 P3 P4 [0,1,0,0] [0,0,0,1] [1,2,0,0] [0,1,1,0]

    [0,1,2,1] [0,1,3,1] [2,1,3,1] 5VFTEBZ 4FQUFNCFS 
  13. Example [1,0,0,0] P1 P2 P3 P4 [0,1,0,0] [0,0,0,1] [1,2,0,0] [0,1,1,0]

    [0,1,2,1] [0,1,3,1] [2,1,3,1] 5VFTEBZ 4FQUFNCFS 
  14. 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 false 5VFTEBZ 4FQUFNCFS 
  15. 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)” 5VFTEBZ 4FQUFNCFS