SlideShare a Scribd company logo
1 of 68
CS 425 / ECE 428
Distributed Systems
Fall 2020
Indranil Gupta (Indy)
Lecture 12: Time and Ordering
All slides © IG
• (You will get these jokes as you start understanding the topic)
• What’s common between a carrier pigeon and a Lamport timestamp? Both like
to travel with messages.
• Why did the chicken cross the road?
– Because Lamport asked it to carry a timestamp.
– Because it was carrying a Lamport timestamp.
• What did the chicken carry across the road? A Lamport timestamp.
• What’s the difference between a blind date and a second date? The first is
casual, the second is causal. (this joke is really important)
(All jokes © unless otherwise mentioned. Apologies for bad jokes!).
2
Jokes for this Topic
1. Cristian’s algorithm vs. NTP algorithm: which has a better error bound? (and
why?)
2. Why do many distributed systems work correctly without time synchronization?
3. Two events e1 and e2 are such that e1  e2. What does that tell you about their
Lamport timestamps? a) LamportTS(e1) < LamportTS(e2), b) LamportTS (e2)
< LamportTS (e1), c) LamportTS (e1) == LamportTS (e2), d) Can’t tell
4. Two events e1 and e2 are such that LamportTS(e1) < LamportTS(e2). Then
which of the following is FALSE: a) e1 happens before e2, b) e2 happens before
e1, c) e1 and e2 are concurrent, d) Can’t tell
5. Two events e1 and e2 are such that VectorTimestamp(e1) <
VectorTimestamp(e2). Then which of the following is TRUE: a) e1 happens
before e2, b) e2 happens before e1, c) e1 and e2 are concurrent, d) Can’t tell
6. Prove that VT(e1) < VT(e2) iff e1  e2
3
Exercises
P0
P1
P2
P3
Mark Lamport Timestamps
P0
P1
P2
P3
Mark Lamport Timestamps
P0
P1
P2
P3
Mark Lamport Timestamps
Mark Vector Timestamps
P0
P1
P2
P3
P0
P1
P2
P3
Mark Vector Timestamps
P0
P1
P2
P3
Mark Vector Timestamps
• You want to catch a bus at 6.05 pm, but your watch is off by
15 minutes
– What if your watch is Late by 15 minutes?
• You’ll miss the bus!
– What if your watch is Fast by 15 minutes?
• You’ll end up unfairly waiting for a longer time than you
intended
• Time synchronization is required for both
– Correctness
– Fairness
Why Synchronization?
10
Synchronization In The Cloud
• Cloud airline reservation system
• Server A receives a client request to purchase last ticket on flight
ABC 123.
• Server A timestamps purchase using local clock 9h:15m:32.45s,
and logs it. Replies ok to client.
• That was the last seat. Server A sends message to Server B
saying “flight full.”
• B enters “Flight ABC 123 full” + its own local clock value
(which reads 9h:10m:10.11s) into its log.
• Server C queries A’s and B’s logs. Is confused that a client
purchased a ticket at A after the flight became full at B.
• This may lead to further incorrect actions by C
11
• End hosts in Internet-based systems (like clouds)
– Each have their own clocks
– Unlike processors (CPUs) within one server or
workstation which share a system clock
• Processes in Internet-based systems follow an
asynchronous system model
– No bounds on
• Message delays
• Processing delays
– Unlike multi-processor (or parallel) systems which
follow a synchronous system model
Why is it Challenging?
12
• An Asynchronous Distributed System consists of a number of
processes.
• Each process has a state (values of variables).
• Each process takes actions to change its state, which may be
an instruction or a communication action (send, receive).
• An event is the occurrence of an action.
• Each process has a local clock – events within a process can be
assigned timestamps, and thus ordered linearly.
• But – in a distributed system, we also need to know the time
order of events across different processes.
Some Definitions
13
• Each process (running at some end host) has its own clock.
• When comparing two clocks at two processes:
• Clock Skew = Relative Difference in clock values of two processes
• Like distance between two vehicles on a road
• Clock Drift = Relative Difference in clock frequencies (rates) of two processes
• Like difference in speeds of two vehicles on the road
• A non-zero clock skew implies clocks are not synchronized.
• A non-zero clock drift causes skew to increase (eventually).
– If faster vehicle is ahead, it will drift away
– If faster vehicle is behind, it will catch up and then drift away
Clock Skew vs. Clock Drift
14
• Maximum Drift Rate (MDR) of a clock
• Absolute MDR is defined relative to Coordinated Universal
Time (UTC). UTC is the “correct” time at any point of time.
• MDR of a process depends on the environment.
• Max drift rate between two clocks with similar MDR is 2 *
MDR
• Given a maximum acceptable skew M between any pair of
clocks, need to synchronize at least once every: M / (2 * MDR)
time units
– Since time = distance/speed
How often to Synchronize?
15
• Consider a group of processes
• External Synchronization
– Each process C(i)’s clock is within a bound D of a well-known clock S external to the group
– |C(i) – S| < D at all times
– External clock may be connected to UTC (Universal Coordinated Time) or an atomic clock
– E.g., Cristian’s algorithm, NTP
• Internal Synchronization
– Every pair of processes in group have clocks within bound D
– |C(i) – C(j)| < D at all times and for all processes i, j
– E.g., Berkeley algorithm
External vs Internal Synchronization
16
• External Synchronization with D => Internal
Synchronization with 2*D
• Internal Synchronization does not imply External
Synchronization
– In fact, the entire system may drift away from the
external clock S!
External vs Internal Synchronization (2)
17
Next
• Algorithms for Clock Synchronization
18
Cristian’s Algorithm
19
Basics
• External time synchronization
• All processes P synchronize with a time server S
P
S
Time
What’s the time?
Here’s the time t!
Check local clock to find time t
Set clock to t
20
What’s Wrong
• By the time response message is received at P,
time has moved on
• P’s time set to t is inaccurate!
• Inaccuracy a function of message latencies
• Since latencies unbounded in an asynchronous
system, the inaccuracy cannot be bounded
21
P
S
Time
What’s the time?
Here’s the time t!
Check local clock to find time t
Set clock to t
Cristian’s Algorithm
• P measures the round-trip-time RTT of message exchange
22
Cristian’s Algorithm (2)
• P measures the round-trip-time RTT of message exchange
• Suppose we know the minimum P  S latency min1
• And the minimum S  P latency min2
– min1 and min2 depend on Operating system overhead to buffer messages, TCP
time to queue messages, etc.
P
S
Time
What’s the time?
Here’s the time t!
Check local clock to find time t
Set clock to t
RTT
23
Cristian’s Algorithm (3)
• P measures the round-trip-time RTT of message exchange
• Suppose we know the minimum P  S latency min1
• And the minimum S  P latency min2
– min1 and min2 depend on Operating system overhead to buffer messages, TCP
time to queue messages, etc.
• The actual time at P when it receives response is between [t+min2, t+RTT-min1]
P
S
Time
What’s the time?
Here’s the time t!
Check local clock to find time t
Set clock to t
RTT
24
Cristian’s Algorithm (4)
• The actual time at P when it receives response is between [t+min2, t+RTT-
min1]
• P sets its time to halfway through this interval
– To: t + (RTT+min2-min1)/2
• Error is at most (RTT-min2-min1)/2
– Bounded!
P
S
Time
What’s the time?
Here’s the time t!
Check local clock to find time t
Set clock to t
RTT
25
Gotchas
• Allowed to increase clock value but should never
decrease clock value
– May violate ordering of events within the same
process
• Allowed to increase or decrease speed of clock
• If error is too high, take multiple readings and
average them
26
NTP = Network Time Protocol
• NTP Servers organized in a tree
• Each Client = a leaf of tree
• Each node synchronizes with its tree parent
Client
Primary servers
Secondary servers
Tertiary servers
27
NTP Protocol
Child
Parent
Time
Let’s start protocol
Message 1
Message 1 send time ts1
Message 2 send time ts2
Message 1 recv time tr1
Message 2 recv time tr2
Message 2 ts1, tr2
28
What the Child Does
• Child calculates offset between its
clock and parent’s clock
• Uses ts1, tr1, ts2, tr2
• Offset is calculated as
o = (tr1 – tr2 + ts2 – ts1)/2
29
Why o = (tr1 - tr2 + ts2 - ts1)/2?
• Offset o = (tr1 – tr2 + ts2 – ts1)/2
• Let’s calculate the error
• Suppose real offset is oreal
– Child is ahead of parent by oreal
– Parent is ahead of child by -oreal
• Suppose one-way latency of Message 1 is L1
(L2 for Message 2)
• No one knows L1 or L2!
• Then
tr1 = ts1 + L1 + oreal
tr2 = ts2 + L2 – oreal 30
Why o = (tr1 - tr2 + ts2 - ts1)/2? (2)
• Then
tr1 = ts1 + L1 + oreal
tr2 = ts2 + L2 – oreal
• Subtracting second equation from the first
oreal = (tr1 – tr2 + ts2 – ts1)/2 + (L2 – L1)/2
=> oreal = o + (L2 – L1)/2
=> |oreal – o| < |(L2 – L1)/2| < |(L2 + L1)/2|
– Thus, the error is bounded by the round-trip-
time
31
And yet…
• We still have a non-zero error!
• We just can’t seem to get rid of error
– Can’t, as long as message latencies are non-zero
• Can we avoid synchronizing clocks altogether, and still be able to
order events?
32
Lamport Timestamps
33
Ordering Events in a Distributed System
• To order events across processes, trying to sync clocks is one approach
• What if we instead assigned timestamps to events that were not absolute time?
• As long as these timestamps obey causality, that
would work
If an event A causally happens before another
event B, then timestamp(A) < timestamp(B)
Humans use causality all the time
E.g., I enter a house only after I unlock it
E.g., You receive a letter only after I send it
34
Logical (or Lamport) Ordering
• Proposed by Leslie Lamport in the 1970s
• Used in almost all distributed systems since then
• Almost all cloud computing systems use some
form of logical ordering of events
35
Logical (or Lamport) Ordering(2)
• Define a logical relation Happens-Before among pairs of events
• Happens-Before denoted as 
• Three rules
1. On the same process: a  b, if time(a) < time(b) (using the local clock)
2. If p1 sends m to p2: send(m)  receive(m)
3. (Transitivity) If a  b and b  c then a  c
• Creates a partial order among events
– Not all events related to each other via 
36
Example
P2
Time
Instruction or step
P1
P3
Message
A B C D E
E F G
H I J
While P1 and P3 each have an event
labeled E, these are different events as
they occur at different processes.
37
Happens-Before
P2
Time
Instruction or step
P1
P3
Message
• A  B
• B  F
• A  F
A B C D E
E’ F G
H I J
Happens-Before (2)
P2
Time
Instruction or step
P1
P3
Message
• H  G
• F  J
• H  J
• C  J
A B C D E
E’ F G
H I J
In practice: Lamport timestamps
• Goal: Assign logical (Lamport) timestamp to each event
• Timestamps obey causality
• Rules
– Each process uses a local counter (clock) which is an integer
• initial value of counter is zero
– A process increments its counter when a send or an
instruction happens at it. The counter is assigned to the event
as its timestamp.
– A send (message) event carries its timestamp
– For a receive (message) event the counter is updated by
max(local clock, message timestamp) + 1
40
Example
P2
Time
Instruction or step
P1
P3
Message
41
P2
Time
Instruction or step
P1
P3
Message
0
0
0
Initial counters (clocks)
Lamport Timestamps
P2
Time
Instruction or step
P1
P3
Message
Message send
ts = 1
ts = 1
Message carries
ts = 1
0
0
0
Lamport Timestamps
P2
Time
Instruction or step
P1
P3
Message
1
1
Message carries
ts = 1
ts = max(local, msg) + 1
= max(0, 1)+1
= 2
0
0
0
Lamport Timestamps
P2
Time
Instruction or step
P1
P3
Message
1
1
Message carries
ts = 2
2
2
max(2, 2)+1
=3
0
0
0
Lamport Timestamps
P2
Time
Instruction or step
P1
P3
Message
1
1
2
2 3 4
3
max(3, 4)+1
=5
0
0
0
Lamport Timestamps
P2
Time
Instruction or step
P1
P3
Message
1
1
2
2 3 4
3 5 6
7
2
0
0
0
Lamport Timestamps
Obeying Causality
P2
Time
Instruction or step
P1
P3
Message
1
1
2
2 3 4
3 5 6
7
• A  B :: 1 < 2
• B  F :: 2 < 3
• A  F :: 1 < 3
A B C D E
E’ F G
H I J
2
0
0
0
Obeying Causality (2)
P2
Time
Instruction or step
P1
P3
Message
1
1
2
2 3 4
3 5 6
7
A B C D E
E’ F G
H I J
• H  G :: 1 < 4
• F  J :: 3 < 7
• H  J :: 1 < 7
• C  J :: 3 < 7
2
0
0
0
Not always implying Causality
P2
Time
Instruction or step
P1
P3
Message
1
1
2
2 3 4
3 5 6
7
A B C D E
E’ F G
H I J
• ? C  F ? :: 3 = 3
• ? H  C ? :: 1 < 3
• (C, F) and (H, C) are pairs of
concurrent events
2
0
0
0
Concurrent Events
• A pair of concurrent events doesn’t have a causal
path from one event to another (either way, in the
pair)
• Lamport timestamps not guaranteed to be ordered or
unequal for concurrent events
• Ok, since concurrent events are not causality related!
• Remember
E1  E2  timestamp(E1) < timestamp (E2), BUT
timestamp(E1) < timestamp (E2) 
{E1  E2} OR {E1 and E2 concurrent}
51
Next
• Can we have causal or logical timestamps from which we can tell if
two events are concurrent or causally related?
52
Vector Timestamps
• Used in key-value stores like Riak
• Each process uses a vector of integer clocks
• Suppose there are N processes in the group 1…N
• Each vector has N elements
• Process i maintains vector Vi[1…N]
• jth element of vector clock at process i, Vi[j], is i’s
knowledge of latest events at process j
53
Assigning Vector Timestamps
• Incrementing vector clocks
1. On an instruction or send event at process i, it increments only its ith element
of its vector clock
2. Each message carries the send-event’s vector timestamp Vmessage[1…N]
3. On receiving a message at process i:
Vi[i] = Vi[i] + 1
Vi[j] = max(Vmessage[j], Vi[j]) for j ≠ i
54
Example
P2
Time
Instruction or step
P1
P3
Message
A B C D E
E’ F G
H I J
55
Vector Timestamps
P2
Time
P1
P3
(0,0,0)
(0,0,0)
(0,0,0)
Initial counters (clocks)
(0,0,0) (1,0,0)
(0,0,0)
Message(0,0,1)
(0,0,0) (0,0,1)
P2
Time
P1
P3
Vector Timestamps
P2
Time
P1
P3
(0,0,0) (1,0,0)
(0,0,0) (0,1,1)
Message(0,0,1)
(0,0,0) (0,0,1)
Vector Timestamps
P2
Time
P1
P3
(0,0,0) (1,0,0) (2,0,0)
Message(2,0,0)
(0,0,0) (0,1,1) (2,2,1)
(0,0,0) (0,0,1)
Vector Timestamps
P2
Time
P1
P3
(0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1)
(0,0,0) (0,1,1) (2,2,1) (2,3,1)
(0,0,0) (0,0,1) (0,0,2) (5,3,3)
Vector Timestamps
• VT1 = VT2,
iff (if and only if)
VT1[i] = VT2[i], for all i = 1, … , N
• VT1 ≤ VT2,
iff VT1[i] ≤ VT2[i], for all i = 1, … , N
• Two events are causally related iff
VT1 < VT2, i.e.,
iff VT1 ≤ VT2 &
there exists j such that
1 ≤ j ≤ N & VT1[j] < VT2 [j]
Causally-Related …
61
• Two events VT1 and VT2 are concurrent
iff
NOT (VT1 ≤ VT2) AND NOT (VT2 ≤ VT1)
We’ll denote this as VT2 ||| VT1
… or Not Causally-Related
62
P2
Time
P1
P3
(0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1)
(0,0,0) (0,1,1) (2,2,1) (2,3,1)
(0,0,0) (0,0,1) (0,0,2) (5,3,3)
Obeying Causality
• A  B :: (1,0,0) < (2,0,0)
• B  F :: (2,0,0) < (2,2,1)
• A  F :: (1,0,0) < (2,2,1)
A B C D E
E’ F G
H I J
63
P2
Time
P1
P3
(0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1)
(0,0,0) (0,1,1) (2,2,1) (2,3,1)
(0,0,0) (0,0,1) (0,0,2) (5,3,3)
Obeying Causality (2)
A B C D E
E’ F G
H I J
• H  G :: (0,0,1) < (2,3,1)
• F  J :: (2,2,1) < (5,3,3)
• H  J :: (0,0,1) < (5,3,3)
• C  J :: (3,0,0) < (5,3,3)
P2
Time
P1
P3
(0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1)
(0,0,0) (0,1,1) (2,2,1) (2,3,1)
(0,0,0) (0,0,1) (0,0,2) (5,3,3)
Identifying Concurrent Events
A B C D E
E’ F G
H I J
• C & F :: (3,0,0) ||| (2,2,1)
• H & C :: (0,0,1) ||| (3,0,0)
• (C, F) and (H, C) are pairs of concurrent events
Logical Timestamps: Summary
• Lamport timestamps
– Integer clocks assigned to events
– Obeys causality
– Cannot distinguish concurrent events
• Vector timestamps
– Obey causality
– By using more space, can also identify
concurrent events
66
Time and Ordering: Summary
• Clocks are unsynchronized in an asynchronous distributed system
• But need to order events, across processes!
• Time synchronization
– Cristian’s algorithm
– NTP
– Berkeley algorithm
– But error a function of round-trip-time
• Can avoid time sync altogether by instead
assigning logical timestamps to events
67
Announcements
• Midterm
• Regrade requests : submit within 1 week of receiving back
graded HW/exam/MP report
68

More Related Content

Similar to L12.FA20.ppt

fggggggggggggggggggggggggggggggfffffffffffffffffff
fggggggggggggggggggggggggggggggffffffffffffffffffffggggggggggggggggggggggggggggggfffffffffffffffffff
fggggggggggggggggggggggggggggggfffffffffffffffffffadugnanegero
 
Process Scheduling Algorithms for Operating Systems
Process Scheduling Algorithms for Operating SystemsProcess Scheduling Algorithms for Operating Systems
Process Scheduling Algorithms for Operating SystemsKathirvelRajan2
 
3_process_scheduling.ppt----------------
3_process_scheduling.ppt----------------3_process_scheduling.ppt----------------
3_process_scheduling.ppt----------------DivyaBorade3
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Sri Prasanna
 
dataprocess using different technology.ppt
dataprocess using different technology.pptdataprocess using different technology.ppt
dataprocess using different technology.pptssuserf6eb9b
 
Designing TCP-Friendly Window-based Congestion Control
Designing TCP-Friendly Window-based Congestion ControlDesigning TCP-Friendly Window-based Congestion Control
Designing TCP-Friendly Window-based Congestion Controlsoohyunc
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed systemSunita Sahu
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithmssathish sak
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System Harshita Ved
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdfKp Sharma
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin schedulingRaghav S
 

Similar to L12.FA20.ppt (20)

fggggggggggggggggggggggggggggggfffffffffffffffffff
fggggggggggggggggggggggggggggggffffffffffffffffffffggggggggggggggggggggggggggggggfffffffffffffffffff
fggggggggggggggggggggggggggggggfffffffffffffffffff
 
3_process_scheduling.ppt
3_process_scheduling.ppt3_process_scheduling.ppt
3_process_scheduling.ppt
 
Process Scheduling Algorithms for Operating Systems
Process Scheduling Algorithms for Operating SystemsProcess Scheduling Algorithms for Operating Systems
Process Scheduling Algorithms for Operating Systems
 
3_process_scheduling.ppt----------------
3_process_scheduling.ppt----------------3_process_scheduling.ppt----------------
3_process_scheduling.ppt----------------
 
Clock.pdf
Clock.pdfClock.pdf
Clock.pdf
 
Synch
SynchSynch
Synch
 
3. syncro. in distributed system
3. syncro. in distributed system3. syncro. in distributed system
3. syncro. in distributed system
 
6.Distributed Operating Systems
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating Systems
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)
 
TCP timers.ppt
TCP timers.pptTCP timers.ppt
TCP timers.ppt
 
persist timer.ppt
persist timer.pptpersist timer.ppt
persist timer.ppt
 
dataprocess using different technology.ppt
dataprocess using different technology.pptdataprocess using different technology.ppt
dataprocess using different technology.ppt
 
Designing TCP-Friendly Window-based Congestion Control
Designing TCP-Friendly Window-based Congestion ControlDesigning TCP-Friendly Window-based Congestion Control
Designing TCP-Friendly Window-based Congestion Control
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin scheduling
 
14 queuing
14 queuing14 queuing
14 queuing
 

Recently uploaded

Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Servicedoor45step
 
FULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | DelhiFULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | DelhiMalviyaNagarCallGirl
 
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiMalviyaNagarCallGirl
 
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad EscortsIslamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escortswdefrd
 
Karachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in KarachiKarachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in KarachiAyesha Khan
 
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi NcrSapana Sha
 
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl serviceDelhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl serviceashishs7044
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000Sapana Sha
 
Olivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptxOlivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptxLauraFagan6
 
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineSHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineShivna Prakashan
 
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiFULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiMalviyaNagarCallGirl
 
The First Date by Daniel Johnson (Inspired By True Events)
The First Date by Daniel Johnson (Inspired By True Events)The First Date by Daniel Johnson (Inspired By True Events)
The First Date by Daniel Johnson (Inspired By True Events)thephillipta
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiMalviyaNagarCallGirl
 
FULL ENJOY - 9953040155 Call Girls in Uttam Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Uttam Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Uttam Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Uttam Nagar | DelhiMalviyaNagarCallGirl
 
Turn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel JohnsonTurn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel Johnsonthephillipta
 
Zagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdfZagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdfStripovizijacom
 
Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...
Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...
Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...akbard9823
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubaidajasot375
 
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call GirlsKishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 

Recently uploaded (20)

Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
 
FULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | DelhiFULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
 
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
 
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad EscortsIslamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
 
Karachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in KarachiKarachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in Karachi
 
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
 
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl serviceDelhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
 
Olivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptxOlivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptx
 
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
 
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineSHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
 
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiFULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
 
The First Date by Daniel Johnson (Inspired By True Events)
The First Date by Daniel Johnson (Inspired By True Events)The First Date by Daniel Johnson (Inspired By True Events)
The First Date by Daniel Johnson (Inspired By True Events)
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
 
FULL ENJOY - 9953040155 Call Girls in Uttam Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Uttam Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Uttam Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Uttam Nagar | Delhi
 
Turn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel JohnsonTurn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel Johnson
 
Zagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdfZagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdf
 
Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...
Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...
Hazratganj ] (Call Girls) in Lucknow - 450+ Call Girl Cash Payment 🧄 89231135...
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
 
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call GirlsKishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
 

L12.FA20.ppt

  • 1. CS 425 / ECE 428 Distributed Systems Fall 2020 Indranil Gupta (Indy) Lecture 12: Time and Ordering All slides © IG
  • 2. • (You will get these jokes as you start understanding the topic) • What’s common between a carrier pigeon and a Lamport timestamp? Both like to travel with messages. • Why did the chicken cross the road? – Because Lamport asked it to carry a timestamp. – Because it was carrying a Lamport timestamp. • What did the chicken carry across the road? A Lamport timestamp. • What’s the difference between a blind date and a second date? The first is casual, the second is causal. (this joke is really important) (All jokes © unless otherwise mentioned. Apologies for bad jokes!). 2 Jokes for this Topic
  • 3. 1. Cristian’s algorithm vs. NTP algorithm: which has a better error bound? (and why?) 2. Why do many distributed systems work correctly without time synchronization? 3. Two events e1 and e2 are such that e1  e2. What does that tell you about their Lamport timestamps? a) LamportTS(e1) < LamportTS(e2), b) LamportTS (e2) < LamportTS (e1), c) LamportTS (e1) == LamportTS (e2), d) Can’t tell 4. Two events e1 and e2 are such that LamportTS(e1) < LamportTS(e2). Then which of the following is FALSE: a) e1 happens before e2, b) e2 happens before e1, c) e1 and e2 are concurrent, d) Can’t tell 5. Two events e1 and e2 are such that VectorTimestamp(e1) < VectorTimestamp(e2). Then which of the following is TRUE: a) e1 happens before e2, b) e2 happens before e1, c) e1 and e2 are concurrent, d) Can’t tell 6. Prove that VT(e1) < VT(e2) iff e1  e2 3 Exercises
  • 10. • You want to catch a bus at 6.05 pm, but your watch is off by 15 minutes – What if your watch is Late by 15 minutes? • You’ll miss the bus! – What if your watch is Fast by 15 minutes? • You’ll end up unfairly waiting for a longer time than you intended • Time synchronization is required for both – Correctness – Fairness Why Synchronization? 10
  • 11. Synchronization In The Cloud • Cloud airline reservation system • Server A receives a client request to purchase last ticket on flight ABC 123. • Server A timestamps purchase using local clock 9h:15m:32.45s, and logs it. Replies ok to client. • That was the last seat. Server A sends message to Server B saying “flight full.” • B enters “Flight ABC 123 full” + its own local clock value (which reads 9h:10m:10.11s) into its log. • Server C queries A’s and B’s logs. Is confused that a client purchased a ticket at A after the flight became full at B. • This may lead to further incorrect actions by C 11
  • 12. • End hosts in Internet-based systems (like clouds) – Each have their own clocks – Unlike processors (CPUs) within one server or workstation which share a system clock • Processes in Internet-based systems follow an asynchronous system model – No bounds on • Message delays • Processing delays – Unlike multi-processor (or parallel) systems which follow a synchronous system model Why is it Challenging? 12
  • 13. • An Asynchronous Distributed System consists of a number of processes. • Each process has a state (values of variables). • Each process takes actions to change its state, which may be an instruction or a communication action (send, receive). • An event is the occurrence of an action. • Each process has a local clock – events within a process can be assigned timestamps, and thus ordered linearly. • But – in a distributed system, we also need to know the time order of events across different processes. Some Definitions 13
  • 14. • Each process (running at some end host) has its own clock. • When comparing two clocks at two processes: • Clock Skew = Relative Difference in clock values of two processes • Like distance between two vehicles on a road • Clock Drift = Relative Difference in clock frequencies (rates) of two processes • Like difference in speeds of two vehicles on the road • A non-zero clock skew implies clocks are not synchronized. • A non-zero clock drift causes skew to increase (eventually). – If faster vehicle is ahead, it will drift away – If faster vehicle is behind, it will catch up and then drift away Clock Skew vs. Clock Drift 14
  • 15. • Maximum Drift Rate (MDR) of a clock • Absolute MDR is defined relative to Coordinated Universal Time (UTC). UTC is the “correct” time at any point of time. • MDR of a process depends on the environment. • Max drift rate between two clocks with similar MDR is 2 * MDR • Given a maximum acceptable skew M between any pair of clocks, need to synchronize at least once every: M / (2 * MDR) time units – Since time = distance/speed How often to Synchronize? 15
  • 16. • Consider a group of processes • External Synchronization – Each process C(i)’s clock is within a bound D of a well-known clock S external to the group – |C(i) – S| < D at all times – External clock may be connected to UTC (Universal Coordinated Time) or an atomic clock – E.g., Cristian’s algorithm, NTP • Internal Synchronization – Every pair of processes in group have clocks within bound D – |C(i) – C(j)| < D at all times and for all processes i, j – E.g., Berkeley algorithm External vs Internal Synchronization 16
  • 17. • External Synchronization with D => Internal Synchronization with 2*D • Internal Synchronization does not imply External Synchronization – In fact, the entire system may drift away from the external clock S! External vs Internal Synchronization (2) 17
  • 18. Next • Algorithms for Clock Synchronization 18
  • 20. Basics • External time synchronization • All processes P synchronize with a time server S P S Time What’s the time? Here’s the time t! Check local clock to find time t Set clock to t 20
  • 21. What’s Wrong • By the time response message is received at P, time has moved on • P’s time set to t is inaccurate! • Inaccuracy a function of message latencies • Since latencies unbounded in an asynchronous system, the inaccuracy cannot be bounded 21
  • 22. P S Time What’s the time? Here’s the time t! Check local clock to find time t Set clock to t Cristian’s Algorithm • P measures the round-trip-time RTT of message exchange 22
  • 23. Cristian’s Algorithm (2) • P measures the round-trip-time RTT of message exchange • Suppose we know the minimum P  S latency min1 • And the minimum S  P latency min2 – min1 and min2 depend on Operating system overhead to buffer messages, TCP time to queue messages, etc. P S Time What’s the time? Here’s the time t! Check local clock to find time t Set clock to t RTT 23
  • 24. Cristian’s Algorithm (3) • P measures the round-trip-time RTT of message exchange • Suppose we know the minimum P  S latency min1 • And the minimum S  P latency min2 – min1 and min2 depend on Operating system overhead to buffer messages, TCP time to queue messages, etc. • The actual time at P when it receives response is between [t+min2, t+RTT-min1] P S Time What’s the time? Here’s the time t! Check local clock to find time t Set clock to t RTT 24
  • 25. Cristian’s Algorithm (4) • The actual time at P when it receives response is between [t+min2, t+RTT- min1] • P sets its time to halfway through this interval – To: t + (RTT+min2-min1)/2 • Error is at most (RTT-min2-min1)/2 – Bounded! P S Time What’s the time? Here’s the time t! Check local clock to find time t Set clock to t RTT 25
  • 26. Gotchas • Allowed to increase clock value but should never decrease clock value – May violate ordering of events within the same process • Allowed to increase or decrease speed of clock • If error is too high, take multiple readings and average them 26
  • 27. NTP = Network Time Protocol • NTP Servers organized in a tree • Each Client = a leaf of tree • Each node synchronizes with its tree parent Client Primary servers Secondary servers Tertiary servers 27
  • 28. NTP Protocol Child Parent Time Let’s start protocol Message 1 Message 1 send time ts1 Message 2 send time ts2 Message 1 recv time tr1 Message 2 recv time tr2 Message 2 ts1, tr2 28
  • 29. What the Child Does • Child calculates offset between its clock and parent’s clock • Uses ts1, tr1, ts2, tr2 • Offset is calculated as o = (tr1 – tr2 + ts2 – ts1)/2 29
  • 30. Why o = (tr1 - tr2 + ts2 - ts1)/2? • Offset o = (tr1 – tr2 + ts2 – ts1)/2 • Let’s calculate the error • Suppose real offset is oreal – Child is ahead of parent by oreal – Parent is ahead of child by -oreal • Suppose one-way latency of Message 1 is L1 (L2 for Message 2) • No one knows L1 or L2! • Then tr1 = ts1 + L1 + oreal tr2 = ts2 + L2 – oreal 30
  • 31. Why o = (tr1 - tr2 + ts2 - ts1)/2? (2) • Then tr1 = ts1 + L1 + oreal tr2 = ts2 + L2 – oreal • Subtracting second equation from the first oreal = (tr1 – tr2 + ts2 – ts1)/2 + (L2 – L1)/2 => oreal = o + (L2 – L1)/2 => |oreal – o| < |(L2 – L1)/2| < |(L2 + L1)/2| – Thus, the error is bounded by the round-trip- time 31
  • 32. And yet… • We still have a non-zero error! • We just can’t seem to get rid of error – Can’t, as long as message latencies are non-zero • Can we avoid synchronizing clocks altogether, and still be able to order events? 32
  • 34. Ordering Events in a Distributed System • To order events across processes, trying to sync clocks is one approach • What if we instead assigned timestamps to events that were not absolute time? • As long as these timestamps obey causality, that would work If an event A causally happens before another event B, then timestamp(A) < timestamp(B) Humans use causality all the time E.g., I enter a house only after I unlock it E.g., You receive a letter only after I send it 34
  • 35. Logical (or Lamport) Ordering • Proposed by Leslie Lamport in the 1970s • Used in almost all distributed systems since then • Almost all cloud computing systems use some form of logical ordering of events 35
  • 36. Logical (or Lamport) Ordering(2) • Define a logical relation Happens-Before among pairs of events • Happens-Before denoted as  • Three rules 1. On the same process: a  b, if time(a) < time(b) (using the local clock) 2. If p1 sends m to p2: send(m)  receive(m) 3. (Transitivity) If a  b and b  c then a  c • Creates a partial order among events – Not all events related to each other via  36
  • 37. Example P2 Time Instruction or step P1 P3 Message A B C D E E F G H I J While P1 and P3 each have an event labeled E, these are different events as they occur at different processes. 37
  • 38. Happens-Before P2 Time Instruction or step P1 P3 Message • A  B • B  F • A  F A B C D E E’ F G H I J
  • 39. Happens-Before (2) P2 Time Instruction or step P1 P3 Message • H  G • F  J • H  J • C  J A B C D E E’ F G H I J
  • 40. In practice: Lamport timestamps • Goal: Assign logical (Lamport) timestamp to each event • Timestamps obey causality • Rules – Each process uses a local counter (clock) which is an integer • initial value of counter is zero – A process increments its counter when a send or an instruction happens at it. The counter is assigned to the event as its timestamp. – A send (message) event carries its timestamp – For a receive (message) event the counter is updated by max(local clock, message timestamp) + 1 40
  • 42. P2 Time Instruction or step P1 P3 Message 0 0 0 Initial counters (clocks) Lamport Timestamps
  • 43. P2 Time Instruction or step P1 P3 Message Message send ts = 1 ts = 1 Message carries ts = 1 0 0 0 Lamport Timestamps
  • 44. P2 Time Instruction or step P1 P3 Message 1 1 Message carries ts = 1 ts = max(local, msg) + 1 = max(0, 1)+1 = 2 0 0 0 Lamport Timestamps
  • 45. P2 Time Instruction or step P1 P3 Message 1 1 Message carries ts = 2 2 2 max(2, 2)+1 =3 0 0 0 Lamport Timestamps
  • 46. P2 Time Instruction or step P1 P3 Message 1 1 2 2 3 4 3 max(3, 4)+1 =5 0 0 0 Lamport Timestamps
  • 47. P2 Time Instruction or step P1 P3 Message 1 1 2 2 3 4 3 5 6 7 2 0 0 0 Lamport Timestamps
  • 48. Obeying Causality P2 Time Instruction or step P1 P3 Message 1 1 2 2 3 4 3 5 6 7 • A  B :: 1 < 2 • B  F :: 2 < 3 • A  F :: 1 < 3 A B C D E E’ F G H I J 2 0 0 0
  • 49. Obeying Causality (2) P2 Time Instruction or step P1 P3 Message 1 1 2 2 3 4 3 5 6 7 A B C D E E’ F G H I J • H  G :: 1 < 4 • F  J :: 3 < 7 • H  J :: 1 < 7 • C  J :: 3 < 7 2 0 0 0
  • 50. Not always implying Causality P2 Time Instruction or step P1 P3 Message 1 1 2 2 3 4 3 5 6 7 A B C D E E’ F G H I J • ? C  F ? :: 3 = 3 • ? H  C ? :: 1 < 3 • (C, F) and (H, C) are pairs of concurrent events 2 0 0 0
  • 51. Concurrent Events • A pair of concurrent events doesn’t have a causal path from one event to another (either way, in the pair) • Lamport timestamps not guaranteed to be ordered or unequal for concurrent events • Ok, since concurrent events are not causality related! • Remember E1  E2  timestamp(E1) < timestamp (E2), BUT timestamp(E1) < timestamp (E2)  {E1  E2} OR {E1 and E2 concurrent} 51
  • 52. Next • Can we have causal or logical timestamps from which we can tell if two events are concurrent or causally related? 52
  • 53. Vector Timestamps • Used in key-value stores like Riak • Each process uses a vector of integer clocks • Suppose there are N processes in the group 1…N • Each vector has N elements • Process i maintains vector Vi[1…N] • jth element of vector clock at process i, Vi[j], is i’s knowledge of latest events at process j 53
  • 54. Assigning Vector Timestamps • Incrementing vector clocks 1. On an instruction or send event at process i, it increments only its ith element of its vector clock 2. Each message carries the send-event’s vector timestamp Vmessage[1…N] 3. On receiving a message at process i: Vi[i] = Vi[i] + 1 Vi[j] = max(Vmessage[j], Vi[j]) for j ≠ i 54
  • 59. P2 Time P1 P3 (0,0,0) (1,0,0) (2,0,0) Message(2,0,0) (0,0,0) (0,1,1) (2,2,1) (0,0,0) (0,0,1) Vector Timestamps
  • 60. P2 Time P1 P3 (0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1) (0,0,0) (0,1,1) (2,2,1) (2,3,1) (0,0,0) (0,0,1) (0,0,2) (5,3,3) Vector Timestamps
  • 61. • VT1 = VT2, iff (if and only if) VT1[i] = VT2[i], for all i = 1, … , N • VT1 ≤ VT2, iff VT1[i] ≤ VT2[i], for all i = 1, … , N • Two events are causally related iff VT1 < VT2, i.e., iff VT1 ≤ VT2 & there exists j such that 1 ≤ j ≤ N & VT1[j] < VT2 [j] Causally-Related … 61
  • 62. • Two events VT1 and VT2 are concurrent iff NOT (VT1 ≤ VT2) AND NOT (VT2 ≤ VT1) We’ll denote this as VT2 ||| VT1 … or Not Causally-Related 62
  • 63. P2 Time P1 P3 (0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1) (0,0,0) (0,1,1) (2,2,1) (2,3,1) (0,0,0) (0,0,1) (0,0,2) (5,3,3) Obeying Causality • A  B :: (1,0,0) < (2,0,0) • B  F :: (2,0,0) < (2,2,1) • A  F :: (1,0,0) < (2,2,1) A B C D E E’ F G H I J 63
  • 64. P2 Time P1 P3 (0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1) (0,0,0) (0,1,1) (2,2,1) (2,3,1) (0,0,0) (0,0,1) (0,0,2) (5,3,3) Obeying Causality (2) A B C D E E’ F G H I J • H  G :: (0,0,1) < (2,3,1) • F  J :: (2,2,1) < (5,3,3) • H  J :: (0,0,1) < (5,3,3) • C  J :: (3,0,0) < (5,3,3)
  • 65. P2 Time P1 P3 (0,0,0) (1,0,0) (2,0,0) (3,0,0) (4,3,1) (5,3,1) (0,0,0) (0,1,1) (2,2,1) (2,3,1) (0,0,0) (0,0,1) (0,0,2) (5,3,3) Identifying Concurrent Events A B C D E E’ F G H I J • C & F :: (3,0,0) ||| (2,2,1) • H & C :: (0,0,1) ||| (3,0,0) • (C, F) and (H, C) are pairs of concurrent events
  • 66. Logical Timestamps: Summary • Lamport timestamps – Integer clocks assigned to events – Obeys causality – Cannot distinguish concurrent events • Vector timestamps – Obey causality – By using more space, can also identify concurrent events 66
  • 67. Time and Ordering: Summary • Clocks are unsynchronized in an asynchronous distributed system • But need to order events, across processes! • Time synchronization – Cristian’s algorithm – NTP – Berkeley algorithm – But error a function of round-trip-time • Can avoid time sync altogether by instead assigning logical timestamps to events 67
  • 68. Announcements • Midterm • Regrade requests : submit within 1 week of receiving back graded HW/exam/MP report 68