0% found this document useful (0 votes)
64 views12 pages

Timing in Distributed Systems

1) When events occur in distributed systems, their ordering can be unclear due to the independence of clocks at different locations and the finite speed of communication. 2) Distributed systems use time to order events, resolve resource contention, ensure correct compilation order, and determine the sequence of financial transactions, but the time does not need to be perfectly accurate as long as all parties agree on the ordering. 3) Lamport's logical clocks assign timestamps to events in a way that preserves causal ordering (if event A caused event B, A must have an earlier timestamp) even when physical clocks disagree, through rules like setting a receive event's timestamp to be greater than the sent message's timestamp.

Uploaded by

Anwar Husami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views12 pages

Timing in Distributed Systems

1) When events occur in distributed systems, their ordering can be unclear due to the independence of clocks at different locations and the finite speed of communication. 2) Distributed systems use time to order events, resolve resource contention, ensure correct compilation order, and determine the sequence of financial transactions, but the time does not need to be perfectly accurate as long as all parties agree on the ordering. 3) Lamport's logical clocks assign timestamps to events in a way that preserves causal ordering (if event A caused event B, A must have an earlier timestamp) even when physical clocks disagree, through rules like setting a receive event's timestamp to be greater than the sent message's timestamp.

Uploaded by

Anwar Husami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Timing in distributed

Systems

Lecture 2
Event ordering in space

star star
event e2
event e1

------------- enormous distances -----------------


velocity v’
velocity v

spaceship
spaceship
observes
observes
e1 before e2
e2 before e1

2
Does accurate time matter?

Important questions:
How accurate does time need to be?
How is time used in a distributed system?
What does “A happened before B” mean in a distributed system?

Sometimes we CAN’T SAY in which order two events occurred.

3
Use of time in distributed systems: examples 1
1. Any source of resource contention e.g. Airline booking

POLICY: if the reservation requests of two transactions may each


be satisfied
separately but there are not enough seats left for both, then
the transaction
with the earlier timestamp wins

Note that no causality is involved, the requests are independent.


We don’t need accurate time but just an ordering convention so
all agree who won.

On a tie (equal timestamps) use an agreed tie-breaker


e.g. IP address / processID
4
Use of time in distributed systems: examples 2
2 Programming environments e.g. UNIX make (compile and link)

Suppose a make involves many components that are edited on distributed


computers.
Suppose a component is edited immediately after a make,
but on a computer with a slow clock
so that the recorded time of the edit is before the recorded time of the make.
On the next make this component is not recompiled.

This can be made unlikely to happen, if we ensure that clocks are initialised
accurately
e.g. not from the operator’s watch, but from a “time server”.

This is an example of correctness depending on correct event ordering:


did the edit take place before or after the last make?

of course – it’s a bad idea to use a timestamp as a version number in a


distributed system. make was designed for a centralised UNIX system.
5
Use of time in distributed systems

When each machine has its own clock, an event


that occurred after another event may
nevertheless be assigned an earlier time.
6
Use of time in distributed systems: examples 3
3. Did a credit/debit transaction take place before or after midnight?
This affects daily calculation of interest.

4. The value of shares at the time of buying/selling.

5. Insider dealing? Did X read Y before buying/selling?

Note that some of the above examples require only a means of agreement,
so that all participants in the algorithm make the same decision.

Others require accurate time, or the order of events in the real world,
when causality is at issue.

7
Local clocks must respect true event orderings
X Y
x1
y1
IPC
send ( m, tx )

x2 receive ( m, tx ) at ty
y2

Note that X’s send caused Y’s receive


Suppose Y’s local clock reads ty on receive ( m, tx )
if ty > tx OK
if ty < = tx reset ty to tx plus one increment
This imposes logical time on the system

BUT system time adjusted in this way will drift ahead of UTC
- could use counters rather than timestamps if all we need is event ordering
- so-called “Lamport Time”
How can we generate timestamps that are reasonably close to UTC and preserve causal
ordering?

8
Logical clocks

9
Lamport’s Logical Clocks (1)
The "happens-before" relation → can be
observed directly in two situations:
• If a and b are events in the same process, and a
occurs before b, then a → b is true.
• If a is the event of a message being sent by one
process, and b is the event of the message being
received by another process, then a → b

10
Lamport’s Logical Clocks (2)
Three processes, each with its own clock. The clocks run at different rates.

11
Lamport’s Logical Clocks (3)

Lamport’s algorithm corrects the clocks.


12

You might also like