Title: Distributed Computing Notes
1Distributed Computing Notes
2Time and Event Ordering
- Synchronizing clocks
- Lamports Logical Clock
- Event Ordering
- Vector Clock
- Causal Ordering of Events
3Clock Synchronization
- Message passing to synchronize clock
- message transit time not predictable
- can not be used to establish an event order
- Network Time Protocol
4Logical Time and Logical Clocks
- Within a process, events ordered by local clock
- two events within a process occur in the order
they are observed - Distributed events must be ordered using a
logical clock - The act (event) of sending a message occurs
before the event of receiving the message.
5Lamports Logical Clock
Scheme to order event in a distributed system
using logical clocks Process execution
characterized by a sequence of events. Events
can be procedure invocation instruction
execution message exchange sending a
message receiving a message
6Definitions
Ascertain order of two events based on behavior
of underlying computation Happened Before
Relation (?) - Casual relationship between two
events. a ? b, events in same process, a
occurred before b a ? b, a is sending message, b
is receiving message if a ? b and b ? c, then a ?
c (Transitive) Casual affects - past events
influence future events
7Definitions
Causally Related Events - Event a causally
affects event b if a ? b. Concurrent Events ()
- events a and b are concurrent (ab) if a b
and b a. That is, no causal affect. For
any two events in a system either a ? b, b ? a,
or a b Note a ? b only represents a potential
causality.
8Example space-time diagram
e12
e14
e11
e13
e24
e21
e22
e23
9Logical clocks
Clock Ci for each process Pi in system Ci (a)
assigns a timestamp to event a at Pi Logical
clocks take monotonically increasing values
10Logical Clocks - Conditions
If a ? b, then C(a) lt C(b) C1 For any two
events a and b in a process Pi, if a occurs
before b then Ci(a) lt Ci(b) C2 If a is sending
a message m from Pi and b is receiving a message
m at Pj, then Ci(a) lt Cj(b)
11Logical Clocks - Implementation
IR1 Clock Ci is incremented before each event
in Pi Ci Ci 1 if a and b are successive
events in Pi and a ? b, then Ci(b) Ci(a)
1 IR2 If event a is sending message m by Pi,
then m is assigned timestamp tm Ci(a) (obtained
after applying IR1). On receiving (m, t) by Pj,
Cj max(Cj, tm 1)(on receiving m Cj is
incremented by IR1)
12Ordering of Events
Set of all events can be totally ordered (gt) if
a is any event at Pi, b any event at Pj then
agtb ? Ci(a) lt Cj(b) ? (Ci(a) Cj(b) ? Pi ? Pj)
where ? defines an arbitrary relation that orders
P
e11
e12
e14
e13
e13
(2)
(4)
(5)
(3)
(1)
(1)
(5)
(2)
(4)
e21
e22
e23
e24
13Limitations of Lamports Clocks
a ? b ? C(a) lt C(b), but reverse not necessarily
true (rules of inference). For example, if a and
b are in different processes. C(a) lt C(b) ? Note
? represents a conditional relationship (if X
then Y, X is the antecedent and Y is the
consequent). The only time a conditional is
false (invalid) is when the antecedent is true
but the consequent if false.
14Causal Ordering of Messages
Maintaining the same causal relationship that
holds among message send events with the
corresponding message receive events.
Distinguish between causal ordering of events and
messages
e12
e14
e13
e11
e13
e21
e22
e24
e23
e31
e32
e33
e34
15Global State
- Made difficult due to absence of global clock and
shared memory - Definitions
- Si Site i
- LSi Local State for Site i
- send(mij) send event of message mij by Si to Sj
- rec(mij) receive event of message mij by Sj
- time(x) time state x was recorded
- time(send(m)) time event send(m) occured.
16Local State
- Definitions
- Si Site i
- LSi Local State for Site i
- send(mij) send event of message mij by Si to Sj
- rec(mij) receive event of message mij by Sj
- time(x) time state x was recorded
- time(send(m)) time event send(m) occured.
17Local State
- for a message mij sent by Si to Sj
- send(mij) is in LSi iff time(send(mij)) lt
time(LSi) - rec(mij) is in LSi iff time(rec(mij)) lt time(LSj)
- Inconsistent
- inconsistent(LSi, LSj) mij send(mij) not in
LSi and rec(mij) in LSj - Transit
- transit(LSi, LSj) mij send(mij) in LSi and
rec(mij) not in LSj
18Global State
- Global State (GS) collection of the local
states of system sites. GS LSi, LS2, ..., LSn - Does not guarantee consistency
- Consistent Global State A global state GS
LSi, LS2, ..., LSn is consistent iff for all i
and j, 1 lt i,j lt n inconsistent(LSi, LSj) is
the null set. - Consistent State gt every receive event has a
corresponding send event - Inconsistent Stategt there is at least one
receive event for which not send event is recorded
19Global State
- Transitless Global State - All communication
channels are empty. - for all i, j 1lti,jltntransit(LSi, LSj) NULL
- Strongly Consistent State - State is both
consistent and transitless. In other words,
consistent global state with all communications
channels empty.
20Chandy-Lamport (Snapshot) Algorithm
- Uses marker message to initiate algorithm
- Communication channels are FIFO
- Can be initiated by any process
- Several processes can initiate concurrently
- Each initiation requires a unique marker
identifier (process-id, sequence number). - All local state must be collected simple method
is to include identifier in marker and each
process then sends LS to the initiating process.
21Basic Algorithm
- R1 Marker Send Rule - P sends, channel C
- P records its local state (LSp)
- foreach outgoing channel C send marker before
sending another message - R2 Marker Receive Rule - Q receives, channel C
- if LSq NULL, then record state C NULL, go to R1
- else record state C sequence of messages
received since LSq recorded and marker received.
22Discussion
- The collected global state may not correspond a
real global state. This is due to distributed
nature of the algorithm and propagation delays. - However, the algorithm has the ability to detect
stable properties such as process termination,
computation completion, or deadlock.
23Distributed Coordination
Server implemented mutual exclusion Distributed
mutual exclusion Central server Distributed
manager ring-based