SlideShare a Scribd company logo
1 of 20
Teaching material 
based on Distributed 
Systems: Concepts and 
Design, Edition 3, 
Addison-Wesley 2001. 
Distributed Systems Course 
Time and clocks 
Copyright © George 
Coulouris, Jean Dollimore, 
Tim Kindberg 2001 
email: authors@cdk2.net 
This material is made 
available for private study 
and for direct use by 
individual teachers. 
It may not be included in any 
product or employed in any 
service without the written 
permission of the authors. 
Viewing: These slides 
must be viewed in 
slide show mode. 
10.1 Introduction 
10.2 Clocks, events and process states 
10.3 Synchronizing physical clocks 
10.4 Logical time and logical clocks 
(Omitting sections on global states)
10.1 Introduction 
• We need to measure time accurately: 
• to know the time an event occurred at a computer 
• to do this we need to synchronize its clock with an authoritative 
external clock 
• Algorithms for clock synchronization useful for 
• concurrency control based on timestamp ordering 
• authenticity of requests e.g. in Kerberos 
• There is no global clock in a distributed system 
• this chapter discusses clock accuracy and synchronisation 
• Logical time is an alternative 
• It gives ordering of events - also useful for consistency of replicated 
2 
data 
• 
In the NFS client cache scheme, 
do the client and server clocks need to be synchronized? 
what properties do we require from the clocks?
•Ch 2 (p 50) Computer clocks and timing events 
• Each computer in a DS has its own internal clock 
– used by local processes to obtain the value of the current time 
– processes on different computers can timestamp their events 
– but clocks on different computers may give different times 
– computer clocks drift from perfect time and their drift rates differ from 
one another. 
– clock drift rate: the relative amount that a computer clock differs from 
a perfect clock 
 Even if clocks on all computers in a DS are set to 
the same time, their clocks will eventually vary quite 
significantly unless corrections are applied 
3 
• 
What clock properties are required by the Unix make program 
when it uses local files? 
When files are served by NFS, what properties does the 
Unix make program require from the computer clocks?
The 'happened before' relation is essential to understanding logical clocks 
10.2 Clocks, events and process states 
 A distributed system is defined as a collection P of N 
processes pi, i = 1,2,… N 
 Each process pi has a state si consisting of its variables (which 
it transforms as it executes) 
 Processes communicate only by messages (via a network) 
 Actions of processes: 
– Send, Receive, change own state 
 Event: the occurrence of a single action that a process 
carries out as it executes e.g. Send, Receive, change state 
 Events at a single process pi, can be placed in a total 
ordering denoted by the relation ®i between the events. i.e. 
e ®i e’ if and only if e occurs before e’ at pi 
 A history of process pi: is a series of events ordered by ®i 
4 
history(pi)= hi = <ei 
0, ei 
2, …> • 
1, ei
5 
Clocks 
 We have seen how to order events (happened before) 
 To timestamp events, use the computer’s clock 
 At real time, t, the OS reads the time on the computer’s 
hardware clock Hi(t) 
 It calculates the time on its software clock 
Ci(t)= aHi(t) + b  
– e.g. a 64 bit number giving nanoseconds since some base time 
– in general, the clock is not completely accurate 
– but if Ci behaves well enough, it can be used to timestamp events at pi 
• 
What is clock resolution? How accurate should it be? 
Clock resolution < time interval between successive events that matter
Skew between computer clocks in a distributed system 
Computer clocks are not generally in perfect agreement 
Skew: the difference between the times on two clocks (at any instant) 
Computer clocks are subject to clock drift (they count time at different rates) 
Clock drift rate: the difference per unit of time from some ideal reference 
clock 
Ordinary quartz clocks drift by about 1 sec in 11-12 days. (10-6 secs/sec). 
High precision quartz clocks drift rate is about 10-7 or 10-8 secs/sec 
6 
Network Figure 10.1 
• 
What happens to clocks when their batteries become very low?
Coordinated Universal Time (UTC) 
 International Atomic Time is based on very accurate physical 
clocks (drift rate 10-13) 
 UTC is an international standard for time keeping 
 It is based on atomic time, but occasionally adjusted to 
astronomical time 
 It is broadcast from radio stations on land and satellite (e.g. 
GPS) 
 Computers with receivers can synchronize their clocks with 
these timing signals 
 Signals from land-based stations are accurate to about 0.1- 
10 millisecond 
 Signals from GPS are accurate to about 1 microsecond 
• Why can't we put GPS receivers on all our computers? 
7
10.3 Synchronizing physical clocks 
 External synchronization 
– A computer’s clock Ci is synchronized with an external authoritative time 
source S, so that: 
– |S(t) - Ci(t)| < D for i = 1, 2, … N over an interval, I of real time 
– The clocks Ci are accurate to within the bound D. 
 Internal synchronization 
– The clocks of a pair of computers are synchronized with one another so that: 
– | Ci(t) - Cj(t)| < D for i = 1, 2, … N over an interval, I of real time 
– The clocks Ci and Cj agree within the bound D. 
 Internally synchronized clocks are not necessarily externally 
synchronized, as they may drift collectively 
 if the set of processes P is synchronized externally within a 
bound D, it is also internally synchronized within bound 2D 
8 
•
Clock correctness 
 A hardware clock, H is said to be correct if its drift rate is 
within a bound r > 0. (e.g. 10-6 secs/ sec) 
 This means that the error in measuring the interval between 
real times t and t’ is bounded: 
– (1 - r )  (t’ - t) ≤ H(t’) - H(t) ≤ (1 + r )  (t’ - t) (where t’>t) 
– Which forbids jumps in time readings of hardware clocks 
 Weaker condition of monotonicity 
– t' > t Þ C(t’) > C(t) 
– e.g. required by Unix make 
– can achieve monotonicity with a hardware clock that runs fast by adjusting the 
values of a  b  Ci(t)= aHi(t) + b  
 a faulty clock is one that does not obey its correctness 
condition 
 crash failure - a clock stops ticking 
 arbitrary failure - any other failure e.g. jumps in time 
9 
• 
Consider the 'Y2K bug' - what sort of clock failure would that be?
Is the Internet In the Internet, aw es ycnacnh roonnlyo ussa ys yTstratnesm? = min + x where x >= 0 
10.3.1 Synchronization in a synchronous system 
 a synchronous distributed system is one in which the 
following bounds are defined (ch. 2 p. 50): 
– the time to execute each step of a process has known lower and 
upper bounds 
– each message transmitted over a channel is received within a known 
bounded time 
– each process has a local clock whose drift rate from real time has a 
known bound 
10 
• 
Internal synchronization in a synchronous system 
– One process p1 sends its local time t to process p2 in a message m, 
– p2 could set its clock to t + Ttrans where Ttrans is the time to transmit m 
– Ttrans is unknown but min ≤ Ttrans ≤ max 
– uncertainty u = max-min. Set clock to t + (max - min)/2 then skew ≤ u/2
Cristian’s method (1989) for an asynchronous system 
 A time server S receives signals from a UTC source 
– Process p requests time in mr and receives t in mt from S 
– p sets its clock to t + Tround/2 
– Accuracy ± (Tround/2 - min) : 
Tround is the round trip time recorded by p 
min is an estimated minimum round trip time 
 because the earliest time S puts t in message mt is min after p sent mr. 
 the latest time was min before mt arrived at p 
 the time by S’s clock when mt arrives is in the range [t+min, t + Tround - min] 
11 
mr 
mt 
p Time server,S 
Figure 10.2 
• 
What is the potential problem in using a single time server?
Berkeley algorithm 
 Cristian’s algorithm - 
– a single time server might fail, so they suggest the use of a group of 
synchronized servers 
– it does not deal with faulty servers 
 Berkeley algorithm (also 1989) 
– An algorithm for internal synchronization of a group of computers 
– A master polls to collect clock values from the others (slaves) 
– The master uses round trip times to estimate the slaves’ clock values 
– It takes an average (eliminating any above some average round trip time or 
with faulty clocks) 
– It sends the required adjustment to the slaves (better than sending the time 
which depends on the round trip time) 
– Measurements 
 15 computers, clock synchronization 20-25 millisecs drift rate < 2x10-5 
 If master fails, can elect a new master to take over (not in bounded time) 
12 
•
Network Time Protocol (NTP) 
 A time service for the Internet - synchronizes clients to UTC 
Reliability Primary from servers redundant are connected paths, scalable, to UTC sources 
authenticates time 
sources 
Secondary servers are synchronized to primary 
servers 
13 
Synchronization subnet - lowest level servers in 
users’ computers 
1 
2 
3 
2 
3 3 
Figure 10.3 
•
NTP - synchronisation of servers 
 The synchronization subnet can reconfigure if failures occur, e.g. 
– a primary that loses its UTC source can become a secondary 
– a secondary that loses its primary can use another primary 
 Modes of synchronization: 
 Multicast 
 A server within a high speed LAN multicasts time to others which set clocks 
assuming some delay (not very accurate) 
 Procedure call 
 A server accepts requests from other computers (like Cristiain’s algorithm). Higher 
accuracy. Useful if no hardware multicast. 
14 
 Symmetric 
 Pairs of servers exchange messages containing time information 
 Used where very high accuracies are needed (e.g. for higher levels) 
•
Messages exchanged between a pair of NTP peers 
15 
Ti 
Ti-2 Ti-1 
Ti- 3 
Server B 
Server A 
Time 
m m' 
Time 
 All modes use UDP 
 Each message bears timestamps of recent events: 
– Local times of Send and Receive of previous message 
– Local times of Send of current message 
 Recipient notes the time of receipt Ti ( we have Ti-3, Ti-2, Ti-1, Ti) 
 In symmetric mode there can be a non-negligible delay between 
messages 
Figure 10.4 
•
Accuracy of NTP 
 For each pair of messages between two servers, NTP 
estimates an offset o, between the two clocks and a delay di 
(total time for the two messages, which take t and t’) 
Ti-2 = Ti-3 + t + o and Ti = Ti-1 + t’ - o 
 This gives us (by adding the equations) : 
di = t + t’ = Ti-2 - Ti-3 + Ti - Ti-1 
 Also (by subtracting the equations) 
o = oi + (t’ - t )/2 where oi = (Ti-2 - Ti-3 + Ti - Ti-1 )/2 
 Using the fact that t, t’>0 it can be shown that 
oi - di /2 ≤ o ≤ oi + di /2 . 
– Thus oi is an estimate of the offset and di is a measure of the accuracy 
 NTP servers filter pairs <oi, di>, estimating reliability from 
variation, allowing them to select peers 
 Accuracy of 10s of millisecs over Internet paths (1 on LANs) • 
16
Logical time and logical clocks (Lamport 1978) 
 Instead of synchronizing clocks, event ordering can be used 
a®b (at p1) c®d (at p2) b ®c because of m1 also d®f because of m2 
17 
p1 
p2 
p3 
a b 
c d 
m1 
m2 
e f 
Figure10.5 
Physical 
time 
Not all events are related by ® 
consider a and e (different processes and no chain of messages to relate them) 
they are not related by ® ; they are said to be concurrent; write as a || e 
the happened before relation is the relation of causal ordering 
• 
1. If two events occurred at the same process pi (i = 1, 2, … N) then 
they occurred in the order observed by pi, that is ® 
2. when a message, m is sent between two processes, send(m) 
happened before receive(m) 
3. The happened before relation is transitive 
HB1, HB2 and HB3 (page 397) are formal statements of these 3 points
Lamport’s logical clocks 
 A logical clock is a monotonically increasing software counter. It need not 
relate to a physical clock. 
 Each process pi has a logical clock, Li which can be used to apply logical 
timestamps to events 
– LC1: Li is incremented by 1 before each event at process pi 
– LC2: 
– (a) when process pi sends message m, it piggybacks t = Li 
– (b) when pj receives (m,t) it sets Lj := max(Lj, t) and applies LC1 before timestamping the 
event receive (m) 
1 2 
a b 
1 5 
18 
3 4 
c d 
m1 
m2 
e f 
p1 
p2 
p3 
Figure 10.6 
Physical 
time 
each of p1, p2, p3 has its logical clock initialised to zero, 
the clock values are those immediately after the event. 
e.g. 1 for a, 2 for b. 
for m1, 2 is piggybacked and c gets max(0,2)+1 = 3 
e ®e’ implies L(e)<L(e’) 
The converse is not true, 
that is L(e)<L(e') does not 
imply e ®e’ 
• 
Give an example to show 
the converse is not true e.g. L(b) > L(e) but b || e
Can you see a pair of parallel events?. 
Vector clocks 
 Vector clock Vi at process pi is an array of N integers 
 VC1:initially Vi[j] = 0 for i, j = 1, 2, …N 
 VC2:before pi timestamps an event it sets Vi[i] := Vi[i] +1 
 VC3:pi piggybacks t = Vi on every message it sends 
 VC4:when pi receives (m,t) it sets Vi[j] := max(Vi[j] , t[j]) j = 1, 
2, …N ( then before next event adds I to own element using VC2) 
At p1 a(1,0,0) b (2,0,0) piggyback (2,0,0) on m1 
At p2 on receipt of m1 get max ((0,0,0), (2,0,0)) = (2, 0, 0) add 1 to own element = (2,1,0) 
Meaning of =, <=, max etc for vector timestamps - compare elements pairwise 
Note that e ®e’ implies L(e)<L(e’). The converse is also true. 
See Exercise 10.3 for a proof. 
(1,0,0) (2,0,0) 
a b 
Figure 10.7 
(0,0,1) (2,2,2) 
19 
(2,1,0) (2,2,0) 
c d 
m1 
m2 
e f 
p1 
p2 
p3 
Physical 
time 
Vector clocks overcome the shortcoming of Lamport logical clocks 
(L(e) < L(e’) does not imply e happened before e’) 
Vector timestamps are used to timestamp local events 
They are applied in schemes for replication of data e.g. Gossip (p 572), Coda (p585) and causal multicast 
• 
Vi[i]] is the number of events that pi has timestamped 
Viji] ( j≠ i) is the number of events at pj that pi c || e( parallel) becau shea ns ebiteheenr aVf(fce)c <te=d Vb(ye) nor V(e) <= V(c).
Summary on time and clocks in distributed systems 
 accurate timekeeping is important for distributed systems. 
 algorithms (e.g. Cristian’s and NTP) synchronize clocks in 
spite of their drift and the variability of message delays. 
 for ordering of an arbitrary pair of events at different 
computers, clock synchronization is not always practical. 
 the happened-before relation is a partial order on events that 
reflects a flow of information between them. 
 Lamport clocks are counters that are updated according to 
the happened-before relationship between events. 
 vector clocks are an improvement on Lamport clocks, 
– we can tell whether two events are ordered by happened-before or are 
concurrent by comparing their vector timestamps 
20 
•

More Related Content

What's hot

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionSHIKHA GAUTAM
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Sri Prasanna
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed systemSunita Sahu
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System Harshita Ved
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computingSVijaylakshmi
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance SHIKHA GAUTAM
 
Global state recording in Distributed Systems
Global state recording in Distributed SystemsGlobal state recording in Distributed Systems
Global state recording in Distributed SystemsArsnet
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communicationAbDul ThaYyal
 
resource management
  resource management  resource management
resource managementAshish Kumar
 
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...Sehrish Asif
 
Physical and Logical Clocks
Physical and Logical ClocksPhysical and Logical Clocks
Physical and Logical ClocksDilum Bandara
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systemssumitjain2013
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemDHIVYADEVAKI
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocolsMayank Jain
 

What's hot (20)

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)
 
Unit 1
Unit 1Unit 1
Unit 1
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
6.Distributed Operating Systems
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating Systems
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
 
Global state recording in Distributed Systems
Global state recording in Distributed SystemsGlobal state recording in Distributed Systems
Global state recording in Distributed Systems
 
message passing
 message passing message passing
message passing
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communication
 
resource management
  resource management  resource management
resource management
 
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
 
Physical and Logical Clocks
Physical and Logical ClocksPhysical and Logical Clocks
Physical and Logical Clocks
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed System
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocols
 

Similar to Chapter 10

Unit iii-Synchronization
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-SynchronizationDhivyaa C.R
 
Lesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLagamaPasala
 
Clock Synchronization in Distributed Systems
Clock Synchronization in Distributed SystemsClock Synchronization in Distributed Systems
Clock Synchronization in Distributed SystemsIRJET Journal
 
Real-Time Systems Intro.pptx
Real-Time Systems Intro.pptxReal-Time Systems Intro.pptx
Real-Time Systems Intro.pptx20EUEE018DEEPAKM
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptMeymunaMohammed1
 
Getting date and time from ntp server with esp8266 node mcu
Getting date and time from ntp server with esp8266 node mcuGetting date and time from ntp server with esp8266 node mcu
Getting date and time from ntp server with esp8266 node mcuElaf A.Saeed
 
Resource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time SystemsResource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time Systemsjeronimored
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptsirajmohammed35
 

Similar to Chapter 10 (20)

Unit iii-Synchronization
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-Synchronization
 
Clock.pdf
Clock.pdfClock.pdf
Clock.pdf
 
Synch
SynchSynch
Synch
 
Lesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptx
 
3. syncro. in distributed system
3. syncro. in distributed system3. syncro. in distributed system
3. syncro. in distributed system
 
L12.FA20.ppt
L12.FA20.pptL12.FA20.ppt
L12.FA20.ppt
 
09-time+synch.ppt
09-time+synch.ppt09-time+synch.ppt
09-time+synch.ppt
 
Ds ppt imp.
Ds ppt imp.Ds ppt imp.
Ds ppt imp.
 
slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
 
Shoaib
ShoaibShoaib
Shoaib
 
Clock Synchronization in Distributed Systems
Clock Synchronization in Distributed SystemsClock Synchronization in Distributed Systems
Clock Synchronization in Distributed Systems
 
Shoaib
ShoaibShoaib
Shoaib
 
Real-Time Systems Intro.pptx
Real-Time Systems Intro.pptxReal-Time Systems Intro.pptx
Real-Time Systems Intro.pptx
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
 
Chap 5
Chap 5Chap 5
Chap 5
 
Getting date and time from ntp server with esp8266 node mcu
Getting date and time from ntp server with esp8266 node mcuGetting date and time from ntp server with esp8266 node mcu
Getting date and time from ntp server with esp8266 node mcu
 
Resource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time SystemsResource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time Systems
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.ppt
 
Synchronisation
SynchronisationSynchronisation
Synchronisation
 
Hu3513551364
Hu3513551364Hu3513551364
Hu3513551364
 

More from AbDul ThaYyal

Chapter 15 distributed mm systems
Chapter 15 distributed mm systemsChapter 15 distributed mm systems
Chapter 15 distributed mm systemsAbDul ThaYyal
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replicationAbDul ThaYyal
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlAbDul ThaYyal
 
Chapter 11d coordination agreement
Chapter 11d coordination agreementChapter 11d coordination agreement
Chapter 11d coordination agreementAbDul ThaYyal
 
Chapter 11c coordination agreement
Chapter 11c coordination agreementChapter 11c coordination agreement
Chapter 11c coordination agreementAbDul ThaYyal
 
Chapter 8 distributed file systems
Chapter 8 distributed file systemsChapter 8 distributed file systems
Chapter 8 distributed file systemsAbDul ThaYyal
 
Chapter 3 networking and internetworking
Chapter 3 networking and internetworkingChapter 3 networking and internetworking
Chapter 3 networking and internetworkingAbDul ThaYyal
 
Chapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systemsChapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systemsAbDul ThaYyal
 
Chapter 2 system models
Chapter 2 system modelsChapter 2 system models
Chapter 2 system modelsAbDul ThaYyal
 
4.file service architecture
4.file service architecture4.file service architecture
4.file service architectureAbDul ThaYyal
 
4.file service architecture (1)
4.file service architecture (1)4.file service architecture (1)
4.file service architecture (1)AbDul ThaYyal
 

More from AbDul ThaYyal (20)

Chapter 17 corba
Chapter 17 corbaChapter 17 corba
Chapter 17 corba
 
Chapter 15 distributed mm systems
Chapter 15 distributed mm systemsChapter 15 distributed mm systems
Chapter 15 distributed mm systems
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replication
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
 
Chapter 11d coordination agreement
Chapter 11d coordination agreementChapter 11d coordination agreement
Chapter 11d coordination agreement
 
Chapter 11c coordination agreement
Chapter 11c coordination agreementChapter 11c coordination agreement
Chapter 11c coordination agreement
 
Chapter 11b
Chapter 11bChapter 11b
Chapter 11b
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 9 names
Chapter 9 namesChapter 9 names
Chapter 9 names
 
Chapter 8 distributed file systems
Chapter 8 distributed file systemsChapter 8 distributed file systems
Chapter 8 distributed file systems
 
Chapter 7 security
Chapter 7 securityChapter 7 security
Chapter 7 security
 
Chapter 6 os
Chapter 6 osChapter 6 os
Chapter 6 os
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Chapter 3 networking and internetworking
Chapter 3 networking and internetworkingChapter 3 networking and internetworking
Chapter 3 networking and internetworking
 
Chapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systemsChapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systems
 
Chapter 2 system models
Chapter 2 system modelsChapter 2 system models
Chapter 2 system models
 
4.file service architecture
4.file service architecture4.file service architecture
4.file service architecture
 
4.file service architecture (1)
4.file service architecture (1)4.file service architecture (1)
4.file service architecture (1)
 
4. system models
4. system models4. system models
4. system models
 

Chapter 10

  • 1. Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley 2001. Distributed Systems Course Time and clocks Copyright © George Coulouris, Jean Dollimore, Tim Kindberg 2001 email: authors@cdk2.net This material is made available for private study and for direct use by individual teachers. It may not be included in any product or employed in any service without the written permission of the authors. Viewing: These slides must be viewed in slide show mode. 10.1 Introduction 10.2 Clocks, events and process states 10.3 Synchronizing physical clocks 10.4 Logical time and logical clocks (Omitting sections on global states)
  • 2. 10.1 Introduction • We need to measure time accurately: • to know the time an event occurred at a computer • to do this we need to synchronize its clock with an authoritative external clock • Algorithms for clock synchronization useful for • concurrency control based on timestamp ordering • authenticity of requests e.g. in Kerberos • There is no global clock in a distributed system • this chapter discusses clock accuracy and synchronisation • Logical time is an alternative • It gives ordering of events - also useful for consistency of replicated 2 data • In the NFS client cache scheme, do the client and server clocks need to be synchronized? what properties do we require from the clocks?
  • 3. •Ch 2 (p 50) Computer clocks and timing events • Each computer in a DS has its own internal clock – used by local processes to obtain the value of the current time – processes on different computers can timestamp their events – but clocks on different computers may give different times – computer clocks drift from perfect time and their drift rates differ from one another. – clock drift rate: the relative amount that a computer clock differs from a perfect clock  Even if clocks on all computers in a DS are set to the same time, their clocks will eventually vary quite significantly unless corrections are applied 3 • What clock properties are required by the Unix make program when it uses local files? When files are served by NFS, what properties does the Unix make program require from the computer clocks?
  • 4. The 'happened before' relation is essential to understanding logical clocks 10.2 Clocks, events and process states  A distributed system is defined as a collection P of N processes pi, i = 1,2,… N  Each process pi has a state si consisting of its variables (which it transforms as it executes)  Processes communicate only by messages (via a network)  Actions of processes: – Send, Receive, change own state  Event: the occurrence of a single action that a process carries out as it executes e.g. Send, Receive, change state  Events at a single process pi, can be placed in a total ordering denoted by the relation ®i between the events. i.e. e ®i e’ if and only if e occurs before e’ at pi  A history of process pi: is a series of events ordered by ®i 4 history(pi)= hi = <ei 0, ei 2, …> • 1, ei
  • 5. 5 Clocks  We have seen how to order events (happened before)  To timestamp events, use the computer’s clock  At real time, t, the OS reads the time on the computer’s hardware clock Hi(t)  It calculates the time on its software clock Ci(t)= aHi(t) + b – e.g. a 64 bit number giving nanoseconds since some base time – in general, the clock is not completely accurate – but if Ci behaves well enough, it can be used to timestamp events at pi • What is clock resolution? How accurate should it be? Clock resolution < time interval between successive events that matter
  • 6. Skew between computer clocks in a distributed system Computer clocks are not generally in perfect agreement Skew: the difference between the times on two clocks (at any instant) Computer clocks are subject to clock drift (they count time at different rates) Clock drift rate: the difference per unit of time from some ideal reference clock Ordinary quartz clocks drift by about 1 sec in 11-12 days. (10-6 secs/sec). High precision quartz clocks drift rate is about 10-7 or 10-8 secs/sec 6 Network Figure 10.1 • What happens to clocks when their batteries become very low?
  • 7. Coordinated Universal Time (UTC)  International Atomic Time is based on very accurate physical clocks (drift rate 10-13)  UTC is an international standard for time keeping  It is based on atomic time, but occasionally adjusted to astronomical time  It is broadcast from radio stations on land and satellite (e.g. GPS)  Computers with receivers can synchronize their clocks with these timing signals  Signals from land-based stations are accurate to about 0.1- 10 millisecond  Signals from GPS are accurate to about 1 microsecond • Why can't we put GPS receivers on all our computers? 7
  • 8. 10.3 Synchronizing physical clocks  External synchronization – A computer’s clock Ci is synchronized with an external authoritative time source S, so that: – |S(t) - Ci(t)| < D for i = 1, 2, … N over an interval, I of real time – The clocks Ci are accurate to within the bound D.  Internal synchronization – The clocks of a pair of computers are synchronized with one another so that: – | Ci(t) - Cj(t)| < D for i = 1, 2, … N over an interval, I of real time – The clocks Ci and Cj agree within the bound D.  Internally synchronized clocks are not necessarily externally synchronized, as they may drift collectively  if the set of processes P is synchronized externally within a bound D, it is also internally synchronized within bound 2D 8 •
  • 9. Clock correctness  A hardware clock, H is said to be correct if its drift rate is within a bound r > 0. (e.g. 10-6 secs/ sec)  This means that the error in measuring the interval between real times t and t’ is bounded: – (1 - r ) (t’ - t) ≤ H(t’) - H(t) ≤ (1 + r ) (t’ - t) (where t’>t) – Which forbids jumps in time readings of hardware clocks  Weaker condition of monotonicity – t' > t Þ C(t’) > C(t) – e.g. required by Unix make – can achieve monotonicity with a hardware clock that runs fast by adjusting the values of a  b  Ci(t)= aHi(t) + b  a faulty clock is one that does not obey its correctness condition  crash failure - a clock stops ticking  arbitrary failure - any other failure e.g. jumps in time 9 • Consider the 'Y2K bug' - what sort of clock failure would that be?
  • 10. Is the Internet In the Internet, aw es ycnacnh roonnlyo ussa ys yTstratnesm? = min + x where x >= 0 10.3.1 Synchronization in a synchronous system  a synchronous distributed system is one in which the following bounds are defined (ch. 2 p. 50): – the time to execute each step of a process has known lower and upper bounds – each message transmitted over a channel is received within a known bounded time – each process has a local clock whose drift rate from real time has a known bound 10 • Internal synchronization in a synchronous system – One process p1 sends its local time t to process p2 in a message m, – p2 could set its clock to t + Ttrans where Ttrans is the time to transmit m – Ttrans is unknown but min ≤ Ttrans ≤ max – uncertainty u = max-min. Set clock to t + (max - min)/2 then skew ≤ u/2
  • 11. Cristian’s method (1989) for an asynchronous system  A time server S receives signals from a UTC source – Process p requests time in mr and receives t in mt from S – p sets its clock to t + Tround/2 – Accuracy ± (Tround/2 - min) : Tround is the round trip time recorded by p min is an estimated minimum round trip time  because the earliest time S puts t in message mt is min after p sent mr.  the latest time was min before mt arrived at p  the time by S’s clock when mt arrives is in the range [t+min, t + Tround - min] 11 mr mt p Time server,S Figure 10.2 • What is the potential problem in using a single time server?
  • 12. Berkeley algorithm  Cristian’s algorithm - – a single time server might fail, so they suggest the use of a group of synchronized servers – it does not deal with faulty servers  Berkeley algorithm (also 1989) – An algorithm for internal synchronization of a group of computers – A master polls to collect clock values from the others (slaves) – The master uses round trip times to estimate the slaves’ clock values – It takes an average (eliminating any above some average round trip time or with faulty clocks) – It sends the required adjustment to the slaves (better than sending the time which depends on the round trip time) – Measurements  15 computers, clock synchronization 20-25 millisecs drift rate < 2x10-5  If master fails, can elect a new master to take over (not in bounded time) 12 •
  • 13. Network Time Protocol (NTP)  A time service for the Internet - synchronizes clients to UTC Reliability Primary from servers redundant are connected paths, scalable, to UTC sources authenticates time sources Secondary servers are synchronized to primary servers 13 Synchronization subnet - lowest level servers in users’ computers 1 2 3 2 3 3 Figure 10.3 •
  • 14. NTP - synchronisation of servers  The synchronization subnet can reconfigure if failures occur, e.g. – a primary that loses its UTC source can become a secondary – a secondary that loses its primary can use another primary  Modes of synchronization:  Multicast  A server within a high speed LAN multicasts time to others which set clocks assuming some delay (not very accurate)  Procedure call  A server accepts requests from other computers (like Cristiain’s algorithm). Higher accuracy. Useful if no hardware multicast. 14  Symmetric  Pairs of servers exchange messages containing time information  Used where very high accuracies are needed (e.g. for higher levels) •
  • 15. Messages exchanged between a pair of NTP peers 15 Ti Ti-2 Ti-1 Ti- 3 Server B Server A Time m m' Time  All modes use UDP  Each message bears timestamps of recent events: – Local times of Send and Receive of previous message – Local times of Send of current message  Recipient notes the time of receipt Ti ( we have Ti-3, Ti-2, Ti-1, Ti)  In symmetric mode there can be a non-negligible delay between messages Figure 10.4 •
  • 16. Accuracy of NTP  For each pair of messages between two servers, NTP estimates an offset o, between the two clocks and a delay di (total time for the two messages, which take t and t’) Ti-2 = Ti-3 + t + o and Ti = Ti-1 + t’ - o  This gives us (by adding the equations) : di = t + t’ = Ti-2 - Ti-3 + Ti - Ti-1  Also (by subtracting the equations) o = oi + (t’ - t )/2 where oi = (Ti-2 - Ti-3 + Ti - Ti-1 )/2  Using the fact that t, t’>0 it can be shown that oi - di /2 ≤ o ≤ oi + di /2 . – Thus oi is an estimate of the offset and di is a measure of the accuracy  NTP servers filter pairs <oi, di>, estimating reliability from variation, allowing them to select peers  Accuracy of 10s of millisecs over Internet paths (1 on LANs) • 16
  • 17. Logical time and logical clocks (Lamport 1978)  Instead of synchronizing clocks, event ordering can be used a®b (at p1) c®d (at p2) b ®c because of m1 also d®f because of m2 17 p1 p2 p3 a b c d m1 m2 e f Figure10.5 Physical time Not all events are related by ® consider a and e (different processes and no chain of messages to relate them) they are not related by ® ; they are said to be concurrent; write as a || e the happened before relation is the relation of causal ordering • 1. If two events occurred at the same process pi (i = 1, 2, … N) then they occurred in the order observed by pi, that is ® 2. when a message, m is sent between two processes, send(m) happened before receive(m) 3. The happened before relation is transitive HB1, HB2 and HB3 (page 397) are formal statements of these 3 points
  • 18. Lamport’s logical clocks  A logical clock is a monotonically increasing software counter. It need not relate to a physical clock.  Each process pi has a logical clock, Li which can be used to apply logical timestamps to events – LC1: Li is incremented by 1 before each event at process pi – LC2: – (a) when process pi sends message m, it piggybacks t = Li – (b) when pj receives (m,t) it sets Lj := max(Lj, t) and applies LC1 before timestamping the event receive (m) 1 2 a b 1 5 18 3 4 c d m1 m2 e f p1 p2 p3 Figure 10.6 Physical time each of p1, p2, p3 has its logical clock initialised to zero, the clock values are those immediately after the event. e.g. 1 for a, 2 for b. for m1, 2 is piggybacked and c gets max(0,2)+1 = 3 e ®e’ implies L(e)<L(e’) The converse is not true, that is L(e)<L(e') does not imply e ®e’ • Give an example to show the converse is not true e.g. L(b) > L(e) but b || e
  • 19. Can you see a pair of parallel events?. Vector clocks  Vector clock Vi at process pi is an array of N integers  VC1:initially Vi[j] = 0 for i, j = 1, 2, …N  VC2:before pi timestamps an event it sets Vi[i] := Vi[i] +1  VC3:pi piggybacks t = Vi on every message it sends  VC4:when pi receives (m,t) it sets Vi[j] := max(Vi[j] , t[j]) j = 1, 2, …N ( then before next event adds I to own element using VC2) At p1 a(1,0,0) b (2,0,0) piggyback (2,0,0) on m1 At p2 on receipt of m1 get max ((0,0,0), (2,0,0)) = (2, 0, 0) add 1 to own element = (2,1,0) Meaning of =, <=, max etc for vector timestamps - compare elements pairwise Note that e ®e’ implies L(e)<L(e’). The converse is also true. See Exercise 10.3 for a proof. (1,0,0) (2,0,0) a b Figure 10.7 (0,0,1) (2,2,2) 19 (2,1,0) (2,2,0) c d m1 m2 e f p1 p2 p3 Physical time Vector clocks overcome the shortcoming of Lamport logical clocks (L(e) < L(e’) does not imply e happened before e’) Vector timestamps are used to timestamp local events They are applied in schemes for replication of data e.g. Gossip (p 572), Coda (p585) and causal multicast • Vi[i]] is the number of events that pi has timestamped Viji] ( j≠ i) is the number of events at pj that pi c || e( parallel) becau shea ns ebiteheenr aVf(fce)c <te=d Vb(ye) nor V(e) <= V(c).
  • 20. Summary on time and clocks in distributed systems  accurate timekeeping is important for distributed systems.  algorithms (e.g. Cristian’s and NTP) synchronize clocks in spite of their drift and the variability of message delays.  for ordering of an arbitrary pair of events at different computers, clock synchronization is not always practical.  the happened-before relation is a partial order on events that reflects a flow of information between them.  Lamport clocks are counters that are updated according to the happened-before relationship between events.  vector clocks are an improvement on Lamport clocks, – we can tell whether two events are ordered by happened-before or are concurrent by comparing their vector timestamps 20 •

Editor's Notes

  1. This took 1 hr 15 minutes to present, but the slides on NTP were omitted. NTP would require another 15 minutes or so.
  2. NFS client caching no need for synchronisation between client and server clocks For validation, check whether client clock has increased by 3 seconds, then compare two timestamps from the same server Need clocks to increase monotonically and at a reasonably accurate rate (if very fast checks will occur too often, if slow, not often enough)
  3. Make requires monotonic clock values (increases in time) When make uses files served by NFS, the client and server clocks need to be synchronised. In general any program that uses local and server files and compres their timestamps would require loose synchronosation between client and server.
  4. Clock resolution - the period between updates of the value of the clock
  5. Low batteries -&amp;gt; large drift rate
  6. GPS does not work inside buildings
  7. I hope they will answer the Y2k problem is an arbitrary failure (it makes 1 Jan 2000 be 1 Jan 1900)
  8. For internal synchronization discuss min is the time to transmit a message when nothing else is going on. max is the upper bound .The internet is an asynchronous system because there is no upper bound on message transmission delays.
  9. The algorithm is probabilistic. Works if round trip times are shortB
  10. animates the points relaibility, primary and secondary servers
  11. Local times of Send and Receive of previous message Local times of Send of current message Recipient notes the time of receipt ( we have Ti-3, Ti-2, Ti-1, Ti) In symmetric mode there can be a non-negligible delay between messages
  12. from the above: o-oi = (t’-t)/2 therefore |o-oi| = |t’-t|/2 now |t’-t| &amp;lt;= |t’+t| = di therefore |o-oi| &amp;lt;=di/2. i.e. o-oi&amp;lt;=dii/2 or o&amp;lt;oi+di/2 also -o+oi&amp;lt;= di/2 i.e. oi-di/2 &amp;lt;= o
  13. Animation explains the following: In Figure 10.5 a -&amp;gt; b (at p1) c-&amp;gt;d at p2 and b-&amp;gt;c because of m1 also d-&amp;gt; f because of m2. Not all events are related by -&amp;gt; (happened before) consider a and e. (different processes and no chain of messages to relate them) Happened before relation - relation of causal ordering HB1, HB2 and HB3 (page 397) are formal statements of the three points on the slide
  14. Discuss LC1 and LC2 for Figure 10.6 (same as 10.5). Initially clocks all set to 0. (a -&amp;gt; 1) b-&amp;gt;2 etc. For m1, 2 is piggybacked and c gets max(1,2) + 1. Same for m2. Note e -&amp;gt; e’ implies L(e) &amp;lt; L(e’). Converse not true. E.g. events b and e. (b || e) concurrent.
  15. Following points animated : Vector clocks overcome the shortcoming of Lamport logical clocks (L(e) &amp;lt; L(e’) does not imply e happened before e’) e.g. events e and c Vector timestamps are used to timestamp local events. Applied in schemes for replication of data e.g. Gossip (p 572), Coda (p585) and causal multicast The rules VC1-VC4 are for updating vector clocks Work through figure 10.7. At p1 a(1,0,0) b (2,0,0) send (2,0,0) on m1 At p2 on receipt of m1 get max((0,0,0), (2,0,0) = (2,0,0) add 1 -&amp;gt; (2,1,0). Meaning of =, &amp;lt;=, max etc for vector timestamps. Note that e-&amp;gt; e’ implies V(e) &amp;lt; V(e’). The converse is also true. But c || e parallel) because neither V(c) &amp;lt;= V(e) nor V(e) &amp;lt;= V(c).