Logical Clocks - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Logical Clocks

Description:

We are interested in relative time between events ... If a b and b c then a c. Lamport Algorithm uses this relationship to provide a partial ordering of events: ... – PowerPoint PPT presentation

Number of Views:148
Avg rating:3.0/5.0
Slides: 11
Provided by: MehdiTH3
Category:
Tags: bb | clocks | logical

less

Transcript and Presenter's Notes

Title: Logical Clocks


1
Logical Clocks
  • We are interested in relative time between
    events (their order), define relation,
    Happens-Before (?)
  • On the same process a ? b, if time(a) lt time(b)
  • If p1 sends m to p2 send(m) ? receive(m)
  • If a ? b and b ? c then a ? c
  • Lamport Algorithm uses this relationship to
    provide a partial ordering of events
  • All processes use a counter (clock) with initial
    value of zero
  • The counter is incremented by and assigned to
    each event, as its timestamp.
  • A send (message) event carries its timestamp
  • For a receive (message) event the counter is
    updated by Max(receiver-counter,
    message-timestamp) 1

2
Events Occurring at Three Processes
3
Lamport Timestamps
4
Example Lamport Logical Time

Physical Time
1
2
Host 1
4
0
3
1
4
3
Host 2
0
2
2
3
3
Host 3
4
0
7
3
5
6
4
6
Host 4
0
5
6
8
Clock Value
n
timestamp
Message
5
Example Concurrent Events

Physical Time
1
2
Host 1
4
0
3
1
4
3
Host 2
0
2
2
3
3
Host 3
4
0
7
3
5
6
4
6
Host 4
0
5
6
8
Clock Value
n
timestamp
Message
6
Vector Logical Clocks
  • With Lamport Logical Time
  • e precedes f ? timestamp(e) lt timestamp (f),
    but
  • timestamp(e) lt timestamp (f) ? e precedes f
  • Vector Logical time guarantees this
  • All hosts use a vector of counters (logical
    clocks), ith element is the clock value for host
    i, initially all zero.
  • Each host i, increments the ith element of its
    vector
  • upon an event, and assigns the vector to the
    event.
  • A send(message) event carries its vector
    timestamp (counter vector)
  • For a receive(message) event,
  • Max(Vreceiverj , Vmessagj), if j
    is not self
  • Vreceiverj 1 otherwise

X
Vreceiverj
7
Vector Timestamps
8
Example Vector Logical Time

Physical Time
Host 1
0,0,0,0
Host 2
0,0,0,0
Host 3
0,0,0,0
Host 4
0,0,0,0
Vector logical clock
n,m,p,q
(vector timestamp)
Message
9
Comparing Vector Timestamps
  • VT1 VT2,
  • iff VT1i VT2i, i 1, , n
  • VT1 lt VT2,
  • iff VT1i lt VT2i, i 1, , n
  • VT1 lt VT2,
  • iff VT1 lt VT2
  • ? j (1 lt j lt n VT1j lt VT2 j)
  • VT1 is concurrent with VT2
  • iff not (VT1 lt VT2 OR VT2 lt VT1)

10
Summary
  • Time synchronization for distributed systems
  • Cristians algorithm
  • Berkeley algorithm
  • NTP
  • Relative order of events
  • Lamports logical clocks
  • Vector clocks
  • Next topic Global Snapshots.
Write a Comment
User Comments (0)
About PowerShow.com