Slides 05
Slides 05
Physical clocks
Problem
Sometimes we simply need the exact time, not just an ordering.
Note
UTC is broadcast through short-wave radio and satellite. Satellites can give an
accuracy of about ±0.5 ms.
Physical clocks
Coordination Clock synchronization
Clock synchronization
Precision
The goal is to keep the deviation between two clocks on any two machines
within a specified bound, known as the precision π:
Accuracy
In the case of accuracy, we aim to keep the clock bound to a value α:
Synchronization
• Internal synchronization: keep clocks precise
• External synchronization: keep clocks accurate
Clock drift
Clock specifications
• A clock comes specified with its maximum clock drift rate ρ.
• F (t ) denotes oscillator frequency of the hardware clock at time t
• F is the clock’s ideal (constant) frequency ⇒ living up to specifications:
F (t )
∀t : (1 − ρ ) ≤ ≤ (1 + ρ)
F
M
∑k =1 (T p,k −T q,k )
NO: Offset[p, q](t ) = M
YES: Offset[p, q](t ) = αt + β
Note
This introduces a partial ordering of events in a system with concurrently
operating processes.
Logical clocks
Problem
How do we maintain a global view of the system’s behavior that is consistent
with the happened-before relation?
Logical clocks
Problem
How do we maintain a global view of the system’s behavior that is consistent
with the happened-before relation?
Logical clocks
Problem
How do we maintain a global view of the system’s behavior that is consistent
with the happened-before relation?
Problem
How to attach a timestamp to an event when there’s no global clock ⇒
maintain a consistent set of logical clocks, one per process.
Notes
• Property P1 is satisfied by (1); Property P2 by (2) and (3).
• It can still occur that two events happen at the same time. Avoid this by
breaking ties through process IDs.
Result
In absence of proper synchronization:
replica #1 ← $1111, while replica #2 ← $1110.
Note
We are assuming that communication is reliable and FIFO ordered.
Vector clocks
Observation
Lamport’s clocks do not guarantee that if C(a) < C(b) that a causally
preceded b.
Vector clocks
Coordination Logical clocks
Vector clocks
Observation
Lamport’s clocks do not guarantee that if C(a) < C(b) that a causally
preceded b.
Note
We cannot conclude that a causally
precedes b.
Vector clocks
Coordination Logical clocks
Causal dependency
Definition
We say that b may causally depend on a if ts(a) < ts(b), with:
• for all k , ts(a)[k ] ≤ ts(b)[k ] and
• there exists at least one index k′ for which ts(a)[k′] < ts(b)[k′]
Vector clocks
Coordination Logical clocks
Vector clocks
Coordination Logical clocks
(a) (b)
Analysis
Vector clocks
Coordination Logical clocks
Adjustment
Pi increments VCi [i ] only when sending a message, and Pj “adjusts” VCj
when receiving a message (i.e., effectively does not change VCj [j ]).
Vector clocks
Coordination Logical clocks
Adjustment
Pi increments VCi [i ] only when sending a message, and Pj “adjusts” VCj
when receiving a message (i.e., effectively does not change VCj [j ]).
Vector clocks
Coordination Logical clocks
Vector clocks
Coordination Logical clocks
Vector clocks
Coordination Mutual exclusion
Mutual exclusion
Problem
Several processes in a distributed system want exclusive access to some
resource.
Basic solutions
Permission-based: A process wanting to enter its critical region, or access a
resource, needs permission from other processes.
Token-based: A token is passed between processes. The one who has the
token may proceed in its critical region, or pass it on when not
interested.
Overview
Coordination Mutual exclusion
Permission-based, centralized
Simply use a coordinator
A centralized algorithm
Coordination Mutual exclusion
A distributed algorithm
Coordination Mutual exclusion
(a) Two processes want to access a shared resource at the same moment.
(b) P0 has the lowest timestamp, so it wins.
(c) When process P0 is done, it sends an OK also, so P2 can now go ahead.
A distributed algorithm
Coordination Mutual exclusion
A token-ring algorithm
Coordination Mutual exclusion
Assumption
When a coordinator crashes, it will recover quickly, but will have forgotten
about permissions it had granted.
A decentralized algorithm
Coordination Mutual exclusion
A decentralized algorithm