Physical and Logical Clocks

Dilum Bandara
Dilum BandaraResearch Scientist at Data61, CSIRO
Physical & Logical Clocks
CS4262 Distributed Systems
Dilum Bandara
Dilum.Bandara@uom.lk
Slides adapted from U Uthaiyashankar (WSO2) and Rajkumar Buyya’s (IU)
Outline
 Introduction to synchronization
 Time & clocks
 Synchronizing physical clocks
 Logical time & logical clocks
 Synchronizing logical clocks
 Lamport’s time stamp
 Vector clocks – Not covered
2
Interaction Model
 Computation occurs within processes
 Processes interact by passing messages,
resulting in
 Communication (information flow)
 Coordination (synchronization & ordering of activities)
 2 significant factors affecting interacting
processes in a distributed system
 Communication performance is often a limiting
characteristic
 Impossible to maintain a single global notion of time
3
Interaction Model (Cont.)
 Processes running on different nodes can
associate timestamps with their events
 This timestamp doesn’t make sense globally
 Clock drift
 Differing drift rates
 Complexity & cost of time synchronization
 GPS not accessible inside a building
4
2 Variants of Interaction Model
 Hard to set limits on time taken for
 Process execution
 Message delivery
 Clock drift
 2 simple models
 Synchronous model – based on a strong assumption
of time
 Asynchronous model – makes no assumption about
time
5
Synchronous DS Model
 Defined by following bounds
 Time taken to execute a step of a process has known
lower & 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
6
Asynchronous DS Model
 Defined by assuming no bounds on
 Process execution speeds
 Message transmission delays
 Clock drift rates
 Models Internet very closely
 Any solution that is valid for an asynchronous
DS is also valid for a synchronous DS
 There are many design problems that can’t be solved
for an asynchronous DS, but can be solved when
some aspects of time are used
7
Event Ordering
 Whether an event occurred before, after, or
concurrently with another event at another
process?
 Execution of a system can be described in terms of
events & their ordering
 No need of accurate clocks
 Example
 Consider a mailing list with users X, Y, Z, & A
 User X sends a message with subject “meeting”
 Users Y & Z reply by sending messages with the
subject “Re: meeting”
8
Example – Real-Time Ordering of
Events
9Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
Example – Inbox of User A
 Due to independent delivery of messages, messages
may be delivered in different order
 If messages m1, m2, m3 carry their time t1, t2, t3, then they
can be displayed accordingly to their time ordering
10
Time in Distributed Systems
 Scenario
 Running UNIX make program which recompiles only source files
whose corresponding object files carry an earlier time stamp
 Differences in time on editing machine & compiler machine & can
result in a file output.o to have a timestamp greater than recently
modified output.c program
 Result
 Modified source program, output.c will not be recompiled
 Programmer???
11
Time & Clocks
 Atomic Time
 Derived from atomic oscillators
 Very accurate
 Astronomical Time
 Based on Earth’s rotation about its axis & around sun
 Period of Earth’s rotation about its axis is gradually
getting longer
 Coordinated Universal Time (UTC)
 Broadcast from land-based radio stations & GPS
12
Clock Drift
 Different rates of counting time
 Physical variations of underlying oscillators
 Variance caused by temperature
 Extremely small differences that accumulate
over a large no of oscillations  Observable
difference in counters
 Drift rate
 Difference in reading between a clock & a nominal
“perfect clock” per unit of time
 10-6 seconds/sec for quartz crystals
 10-7 to 10-8 seconds/sec for high precision quartz
crystals 13
Clock Skew
 When a system has n computers, their n crystals
will oscillate at different rates
 This causes software clocks to gradually get out-
of synch & give different values
 This instantaneous difference in time values is
called clock skew
14
Clock Synchronization
 External synchronization
 If 1 machine has a WWW or GPS receiver, use it to
synchronize others
 Internal synchronization
 If no machines have receivers, each machine keeps
track of its own time
 Then keep all the machines together as well as
possible
 Many clock synchronization algorithms have
been proposed to achieve these goals
 Christian’s Algorithm, Berkeley Algorithm, Averaging
Algorithms, Network Time Protocol, etc. 15
Synchronization in Asynchronous
Systems
 There is no upper bound on message
transmission delays
 e.g., there is no maximum transmission delay for
Internet
 Ttransmit = min + x, where x > 0
 Ttransmit – time taken to transmit m
 Min – minimum time to transmit
 x may not be known in a particular case, but it is
possible to measure a distribution of values for a
particular installation
16
Network Time Protocol (NTP)
 Christian’s & Berkeley algorithms for intranets
 NTP designed for Internet
 Large & variable message delays are handled through
statistical techniques for filtering timing data
 Discriminates between quality of timing data from different
servers
 Redundant servers & redundant paths between servers
 Scalable – handles a large no of clients & servers
 Authentication to ensure trusted time sources
 Synchronization accuracy
 ~10s of milliseconds over Internet paths
 ~1 millisecond on LANs
17
NTP (Cont.)
 Hierarchical network of servers
 Primary servers connected directly to a UTC time source
 Secondary servers synchronized with primary servers
 Servers connected in a logical hierarchy called a synchronization
subnet whose levels are called strata
 Lowest level (leaf) servers execute in users’ workstation
18
Logical Time & Logical Clocks
 Single process
 Events are ordered uniquely by local clock time
 Lamport (1978) pointed out that,
 “since we can’t synchronize clocks perfectly across a
distributed system, we can’t use physical time to find
out order of any arbitrary pair of events within a
distributed system”
 In general, we can use a scheme that is similar
to physical causality, to order some events that
occur in different processes
19
Physical Causality Based Ordering
 If events occur on same process P, then they
occur in the order in which P observes them
 If a & b are events within a single process Pi, and a
occurs before b, then a i b is true
 Whenever a message is sent between
processes, event of sending occurs before event
of receiving
 a = event of a message m being sent by process Pi
 b = event of message m being received
 then, a i b is true
20
Lamport’s Notion of Event Ordering
 Lamport generalized 2 (intuitive) physical-
causality-based event ordering points to obtain
happened-before partial ordering
 A.k.a relation of causal ordering or potential causal
ordering
 Define “happened-before relation” (denoted by
) as follows
 e i e/ for process Pi ⇒ e  e/
 For any message m, send(m)  receive(m)
 e  e/ and e/  e// ⇒ e  e//
21
Happened-Before Relation
22
Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
Happened-Before Relation
23
 Events a & e that are not ordered by  are concurrent
 Denoted by a || e
Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
Logical Clocks
 Invented by Leslie Lamport to capture
happened-before ordering numerically
 Lamport Logical Clock
 Monotonically increasing software counter
 Value need not have a relationship to any physical
clock
 Each process Pi keeps its own logical clock Li,
which it uses to apply Lamport timestamps to
events
 Li(e) = timestamp of event e at Pi
 L(e) = timestamp of event e at process it occurred
24
Lamport Timestamps
 Processes update their logical clocks & transmit
their logical clock values in messages as follows
 LC1
 Li = Li + 1, before each event is recorded at Pi
 LC2
 When Pi sends a message m, logical clock value t = Li, is piggy-
backed with message
 On receiving (m, t), a process Pj computes
 Lj = max (Lj, t)
 Then computes Lj = Lj + 1 before logically timestamping event
receive(m)
 Thus, e  e/ ⇒ L(e) < L(e/)
 However, L(e) < L(e/) ⇏ e  e/
25
Lamport Timestamps – Example
 Each process has its logical clock initialized to 0
 L(b) > L(e) but b || e
26
Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
Lamport Timestamps – Example
 3 processes, each with its own clock
 Clocks run at different rates
 Lamport’s algorithm corrects clocks 27
Totally Ordered Logical Clocks
 Some pairs of distinct events generated by different
processes have identical Lamport timestamps
 A total order, where all pairs of distinct events are ordered,
can be created by noting IDs of processes
 Suppose,
 (Ti, i) = global logical timestamp for event e at process Pi with local
logical timestamp Ti
 Similarly (Tj, j)
 Then (Ti, i) < (Tj, j) ⇔ Ti < Tj or (Ti = Tj and i < j )
 No general physical significance since process IDs are
arbitrary
 e.g., 2 events in P1 & P2, both with timestamp 40 can be
globally timestamped as 40.1 & 40.2 28
Application of Lamport’s Timestamps
 Consider a database that has been replicated
across several sites
 e.g., a bank account database may be replicated in
Colombo & Kandy
 A query is always forwarded to the nearest copy
(for fast response)
 Update costs are higher since each update must
be carried out at each replica in same order
 Why?
29
Application (Cont.)
 Mr. Perera (lives in Kandy) has Rs. 1,000 in his account
 Mr. Perera wants to deposit Rs. 100 to his account
 At the same time, banking application (in Colombo)
initiates an update to increase account balance with 1%
interest
 Both updates must be carried out at both copies of the
database
 Due to communication delays, we may have following
situation:
 In Kandy DB, Mr. Perera’s deposit is performed before interest
update  (Rs. 1000 + Rs. 100) * 1.01 = Rs. 1,111
 In Colombo DB, interest update is performed before Mr. Perera’s
deposit  (Rs. 1000 * 1.01) + Rs. 100 = Rs. 1,110
30
Application (Cont.)
 Problem
 Both updates were not performed in same order at
each DB
 Solution
 Totally ordered multicast
 Multicast operation where all messages are delivered in the
same order to each receiver 31
Totally Ordered Multicast
 If process Pi sends messages x, y to processes
Pj, Pk ,.. then all processes Pj, Pk … receive
messages in the same order (x, y or y, x)
 This doesn’t imply causal or even FIFO ordering
 Solutions
 Multicast through a central coordinator
 Lamport’s solution
32
Lamport’s Totally Ordered Multicast
 Each multicast has a Lamport time stamp
 All processors store received multicast in a queue
 Order based on time stamp
 Everyone has the same queue
 Assume all messages sent by a sender are received in the
order they were sent & no messages are lost
 A time stamped ACK is sent back
 Timestamp of multicast message < timestamp of ACK
 A process can deliver (act on) the message at the
head of queue only when it has received an ACK
from all other processes
33
Lamport’s Totally Ordered Multicast
34
Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
Summary
 Synchronization is important
 Clock drift & clock skew
 Physical clock synchronization
 Logical time & logical clocks
 Lamport Timestamps
 Vector Clocks
 Totally Ordered Multicast
35
1 of 35

Recommended

Communication primitives by
Communication primitivesCommunication primitives
Communication primitivesStudent
24.5K views18 slides
Logical Clocks (Distributed computing) by
Logical Clocks (Distributed computing)Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Sri Prasanna
26.7K views30 slides
Agreement Protocols, distributed File Systems, Distributed Shared Memory by
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
25.4K views91 slides
Clock synchronization in distributed system by
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed systemSunita Sahu
28.7K views25 slides
distributed shared memory by
 distributed shared memory distributed shared memory
distributed shared memoryAshish Kumar
100.7K views108 slides
Google App Engine by
Google App EngineGoogle App Engine
Google App EngineSoftware Park Thailand
11.2K views67 slides

More Related Content

What's hot

Replication in Distributed Systems by
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed SystemsKavya Barnadhya Hazarika
17.4K views27 slides
Synchronization in distributed systems by
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems SHATHAN
40.4K views114 slides
6.Distributed Operating Systems by
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating SystemsDr Sandeep Kumar Poonia
13.4K views92 slides
Process Management-Process Migration by
Process Management-Process MigrationProcess Management-Process Migration
Process Management-Process MigrationMNM Jain Engineering College
7.5K views44 slides
Unit 1 architecture of distributed systems by
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systemskaran2190
144.8K views22 slides
Quality of Service by
Quality of ServiceQuality of Service
Quality of ServiceAbhishek Wadhwa
37.6K views34 slides

What's hot(20)

Synchronization in distributed systems by SHATHAN
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
SHATHAN40.4K views
Unit 1 architecture of distributed systems by karan2190
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
karan2190144.8K views
Inter Process Communication by Adeel Rasheed
Inter Process CommunicationInter Process Communication
Inter Process Communication
Adeel Rasheed3.8K views
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I... by Sagar Rai
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
Sagar Rai6.9K views
Election algorithms by Ankush Kumar
Election algorithmsElection algorithms
Election algorithms
Ankush Kumar32.1K views
clock synchronization in Distributed System by Harshita Ved
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
Harshita Ved4.7K views
Synchronization in distributed computing by SVijaylakshmi
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
SVijaylakshmi1.3K views
User datagram protocol (udp) by Ramola Dhande
User datagram protocol (udp)User datagram protocol (udp)
User datagram protocol (udp)
Ramola Dhande14.7K views
Data link layer by Mukesh Chinta
Data link layer Data link layer
Data link layer
Mukesh Chinta62.1K views
Distributed system lamport's and vector algorithm by pinki soni
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithm
pinki soni17.6K views
Types of Load distributing algorithm in Distributed System by DHIVYADEVAKI
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed System
DHIVYADEVAKI10.9K views

Similar to Physical and Logical Clocks

Clock.pdf by
Clock.pdfClock.pdf
Clock.pdfMohdAbdulHaque
9 views34 slides
Chapter 10 by
Chapter 10Chapter 10
Chapter 10AbDul ThaYyal
4.1K views20 slides
Time in distributed systmes by
Time in distributed systmesTime in distributed systmes
Time in distributed systmesmohammad amid abbasi
124 views41 slides
Synch by
SynchSynch
SynchMohannad Shishani
846 views25 slides
Chap 5 by
Chap 5Chap 5
Chap 5suks_87
1.5K views8 slides
Clocks by
ClocksClocks
Clocksguesta013ed8
5.6K views26 slides

Similar to Physical and Logical Clocks(20)

Chap 5 by suks_87
Chap 5Chap 5
Chap 5
suks_871.5K views
Clock Synchronization (Distributed computing) by Sri Prasanna
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)
Sri Prasanna22.1K views
A Deterministic Model Of Time For Distributed Systems by Jim Webb
A Deterministic Model Of Time For Distributed SystemsA Deterministic Model Of Time For Distributed Systems
A Deterministic Model Of Time For Distributed Systems
Jim Webb2 views
Unit iii-Synchronization by Dhivyaa C.R
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-Synchronization
Dhivyaa C.R41 views
Survey of Real Time Scheduling Algorithms by IOSR Journals
Survey of Real Time Scheduling AlgorithmsSurvey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling Algorithms
IOSR Journals431 views
Distributed computing time by Deepak John
Distributed computing timeDistributed computing time
Distributed computing time
Deepak John766 views
Coupling-Based Internal Clock Synchronization for Large Scale Dynamic Distrib... by Angelo Corsaro
Coupling-Based Internal Clock Synchronization for Large Scale Dynamic Distrib...Coupling-Based Internal Clock Synchronization for Large Scale Dynamic Distrib...
Coupling-Based Internal Clock Synchronization for Large Scale Dynamic Distrib...
Angelo Corsaro1.6K views
Clock Synchronization in Distributed Systems by IRJET Journal
Clock Synchronization in Distributed SystemsClock Synchronization in Distributed Systems
Clock Synchronization in Distributed Systems
IRJET Journal6 views

More from Dilum Bandara

Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag... by
Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag...Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag...
Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag...Dilum Bandara
230 views19 slides
A Decision Model for Choosing Patterns in Blockchain-based Applications by
A Decision Model for Choosing Patterns in Blockchain-based ApplicationsA Decision Model for Choosing Patterns in Blockchain-based Applications
A Decision Model for Choosing Patterns in Blockchain-based ApplicationsDilum Bandara
210 views16 slides
Smart Contract Testing by
Smart Contract TestingSmart Contract Testing
Smart Contract TestingDilum Bandara
363 views19 slides
Smart Contract Security Testing by
Smart Contract Security TestingSmart Contract Security Testing
Smart Contract Security TestingDilum Bandara
672 views21 slides
What's not a cloud by
What's not a cloudWhat's not a cloud
What's not a cloudDilum Bandara
516 views7 slides
Blockchain - A Catalyst for Solving Age-old Distributed Systems Problems by
Blockchain - A Catalyst for Solving Age-old Distributed Systems ProblemsBlockchain - A Catalyst for Solving Age-old Distributed Systems Problems
Blockchain - A Catalyst for Solving Age-old Distributed Systems ProblemsDilum Bandara
224 views18 slides

More from Dilum Bandara(20)

Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag... by Dilum Bandara
Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag...Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag...
Modeling Multi-Layer Access Control Policies of a Hyperledger-Fabric-Based Ag...
Dilum Bandara230 views
A Decision Model for Choosing Patterns in Blockchain-based Applications by Dilum Bandara
A Decision Model for Choosing Patterns in Blockchain-based ApplicationsA Decision Model for Choosing Patterns in Blockchain-based Applications
A Decision Model for Choosing Patterns in Blockchain-based Applications
Dilum Bandara210 views
Smart Contract Security Testing by Dilum Bandara
Smart Contract Security TestingSmart Contract Security Testing
Smart Contract Security Testing
Dilum Bandara672 views
Blockchain - A Catalyst for Solving Age-old Distributed Systems Problems by Dilum Bandara
Blockchain - A Catalyst for Solving Age-old Distributed Systems ProblemsBlockchain - A Catalyst for Solving Age-old Distributed Systems Problems
Blockchain - A Catalyst for Solving Age-old Distributed Systems Problems
Dilum Bandara224 views
Protocols for Fast Delivery of Large Data Volumes by Dilum Bandara
Protocols for Fast Delivery of Large Data VolumesProtocols for Fast Delivery of Large Data Volumes
Protocols for Fast Delivery of Large Data Volumes
Dilum Bandara208 views
Content-Centric Networking (CCN) by Dilum Bandara
Content-Centric Networking (CCN)Content-Centric Networking (CCN)
Content-Centric Networking (CCN)
Dilum Bandara973 views
Internet Architecture and Design Philosophy by Dilum Bandara
Internet Architecture and Design PhilosophyInternet Architecture and Design Philosophy
Internet Architecture and Design Philosophy
Dilum Bandara903 views
Transactions and Concurrency Control by Dilum Bandara
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
Dilum Bandara4.2K views
Content Delivery Networks (CDN) by Dilum Bandara
Content Delivery Networks (CDN)Content Delivery Networks (CDN)
Content Delivery Networks (CDN)
Dilum Bandara3K views
CAP Theorem and Split Brain Syndrome by Dilum Bandara
CAP Theorem and Split Brain SyndromeCAP Theorem and Split Brain Syndrome
CAP Theorem and Split Brain Syndrome
Dilum Bandara1.1K views
Communication in Distributed Systems by Dilum Bandara
Communication in Distributed SystemsCommunication in Distributed Systems
Communication in Distributed Systems
Dilum Bandara919 views
02 - Topologies of Distributed Systems by Dilum Bandara
02 - Topologies of Distributed Systems02 - Topologies of Distributed Systems
02 - Topologies of Distributed Systems
Dilum Bandara3.1K views
01 - Introduction to Distributed Systems by Dilum Bandara
01 - Introduction to Distributed Systems01 - Introduction to Distributed Systems
01 - Introduction to Distributed Systems
Dilum Bandara1.2K views
Use of Technology in Toll Collection & Management by Dilum Bandara
Use of Technology in Toll Collection & ManagementUse of Technology in Toll Collection & Management
Use of Technology in Toll Collection & Management
Dilum Bandara578 views
Big data, Security, or Privacy in IoT: Choice is Yours by Dilum Bandara
Big data, Security, or Privacy in IoT: Choice is YoursBig data, Security, or Privacy in IoT: Choice is Yours
Big data, Security, or Privacy in IoT: Choice is Yours
Dilum Bandara276 views
OWASP Top 10 2017 - New Vulnerabilities by Dilum Bandara
OWASP Top 10 2017 - New VulnerabilitiesOWASP Top 10 2017 - New Vulnerabilities
OWASP Top 10 2017 - New Vulnerabilities
Dilum Bandara243 views

Recently uploaded

MK__Cert.pdf by
MK__Cert.pdfMK__Cert.pdf
MK__Cert.pdfHassan Khan
10 views1 slide
MSA Website Slideshow (16).pdf by
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdfmsaucla
64 views8 slides
fakenews_DBDA_Mar23.pptx by
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptxdeepmitra8
14 views34 slides
_MAKRIADI-FOTEINI_diploma thesis.pptx by
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptxfotinimakriadi
7 views32 slides
An approach of ontology and knowledge base for railway maintenance by
An approach of ontology and knowledge base for railway maintenanceAn approach of ontology and knowledge base for railway maintenance
An approach of ontology and knowledge base for railway maintenanceIJECEIAES
12 views14 slides
Thermal aware task assignment for multicore processors using genetic algorithm by
Thermal aware task assignment for multicore processors using genetic algorithm Thermal aware task assignment for multicore processors using genetic algorithm
Thermal aware task assignment for multicore processors using genetic algorithm IJECEIAES
31 views12 slides

Recently uploaded(20)

MSA Website Slideshow (16).pdf by msaucla
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdf
msaucla64 views
fakenews_DBDA_Mar23.pptx by deepmitra8
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptx
deepmitra814 views
_MAKRIADI-FOTEINI_diploma thesis.pptx by fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi7 views
An approach of ontology and knowledge base for railway maintenance by IJECEIAES
An approach of ontology and knowledge base for railway maintenanceAn approach of ontology and knowledge base for railway maintenance
An approach of ontology and knowledge base for railway maintenance
IJECEIAES12 views
Thermal aware task assignment for multicore processors using genetic algorithm by IJECEIAES
Thermal aware task assignment for multicore processors using genetic algorithm Thermal aware task assignment for multicore processors using genetic algorithm
Thermal aware task assignment for multicore processors using genetic algorithm
IJECEIAES31 views
Machine learning in drug supply chain management during disease outbreaks: a ... by IJECEIAES
Machine learning in drug supply chain management during disease outbreaks: a ...Machine learning in drug supply chain management during disease outbreaks: a ...
Machine learning in drug supply chain management during disease outbreaks: a ...
IJECEIAES12 views
Machine Element II Course outline.pdf by odatadese1
Machine Element II Course outline.pdfMachine Element II Course outline.pdf
Machine Element II Course outline.pdf
odatadese18 views
Design of machine elements-UNIT 3.pptx by gopinathcreddy
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptx
gopinathcreddy32 views
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
SUMIT SQL PROJECT SUPERSTORE 1.pptx by Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 12 views
Control Systems Feedback.pdf by LGGaming5
Control Systems Feedback.pdfControl Systems Feedback.pdf
Control Systems Feedback.pdf
LGGaming55 views
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa... by ijseajournal
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...
ijseajournal5 views
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ... by AltinKaradagli
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
AltinKaradagli9 views

Physical and Logical Clocks

  • 1. Physical & Logical Clocks CS4262 Distributed Systems Dilum Bandara Dilum.Bandara@uom.lk Slides adapted from U Uthaiyashankar (WSO2) and Rajkumar Buyya’s (IU)
  • 2. Outline  Introduction to synchronization  Time & clocks  Synchronizing physical clocks  Logical time & logical clocks  Synchronizing logical clocks  Lamport’s time stamp  Vector clocks – Not covered 2
  • 3. Interaction Model  Computation occurs within processes  Processes interact by passing messages, resulting in  Communication (information flow)  Coordination (synchronization & ordering of activities)  2 significant factors affecting interacting processes in a distributed system  Communication performance is often a limiting characteristic  Impossible to maintain a single global notion of time 3
  • 4. Interaction Model (Cont.)  Processes running on different nodes can associate timestamps with their events  This timestamp doesn’t make sense globally  Clock drift  Differing drift rates  Complexity & cost of time synchronization  GPS not accessible inside a building 4
  • 5. 2 Variants of Interaction Model  Hard to set limits on time taken for  Process execution  Message delivery  Clock drift  2 simple models  Synchronous model – based on a strong assumption of time  Asynchronous model – makes no assumption about time 5
  • 6. Synchronous DS Model  Defined by following bounds  Time taken to execute a step of a process has known lower & 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 6
  • 7. Asynchronous DS Model  Defined by assuming no bounds on  Process execution speeds  Message transmission delays  Clock drift rates  Models Internet very closely  Any solution that is valid for an asynchronous DS is also valid for a synchronous DS  There are many design problems that can’t be solved for an asynchronous DS, but can be solved when some aspects of time are used 7
  • 8. Event Ordering  Whether an event occurred before, after, or concurrently with another event at another process?  Execution of a system can be described in terms of events & their ordering  No need of accurate clocks  Example  Consider a mailing list with users X, Y, Z, & A  User X sends a message with subject “meeting”  Users Y & Z reply by sending messages with the subject “Re: meeting” 8
  • 9. Example – Real-Time Ordering of Events 9Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
  • 10. Example – Inbox of User A  Due to independent delivery of messages, messages may be delivered in different order  If messages m1, m2, m3 carry their time t1, t2, t3, then they can be displayed accordingly to their time ordering 10
  • 11. Time in Distributed Systems  Scenario  Running UNIX make program which recompiles only source files whose corresponding object files carry an earlier time stamp  Differences in time on editing machine & compiler machine & can result in a file output.o to have a timestamp greater than recently modified output.c program  Result  Modified source program, output.c will not be recompiled  Programmer??? 11
  • 12. Time & Clocks  Atomic Time  Derived from atomic oscillators  Very accurate  Astronomical Time  Based on Earth’s rotation about its axis & around sun  Period of Earth’s rotation about its axis is gradually getting longer  Coordinated Universal Time (UTC)  Broadcast from land-based radio stations & GPS 12
  • 13. Clock Drift  Different rates of counting time  Physical variations of underlying oscillators  Variance caused by temperature  Extremely small differences that accumulate over a large no of oscillations  Observable difference in counters  Drift rate  Difference in reading between a clock & a nominal “perfect clock” per unit of time  10-6 seconds/sec for quartz crystals  10-7 to 10-8 seconds/sec for high precision quartz crystals 13
  • 14. Clock Skew  When a system has n computers, their n crystals will oscillate at different rates  This causes software clocks to gradually get out- of synch & give different values  This instantaneous difference in time values is called clock skew 14
  • 15. Clock Synchronization  External synchronization  If 1 machine has a WWW or GPS receiver, use it to synchronize others  Internal synchronization  If no machines have receivers, each machine keeps track of its own time  Then keep all the machines together as well as possible  Many clock synchronization algorithms have been proposed to achieve these goals  Christian’s Algorithm, Berkeley Algorithm, Averaging Algorithms, Network Time Protocol, etc. 15
  • 16. Synchronization in Asynchronous Systems  There is no upper bound on message transmission delays  e.g., there is no maximum transmission delay for Internet  Ttransmit = min + x, where x > 0  Ttransmit – time taken to transmit m  Min – minimum time to transmit  x may not be known in a particular case, but it is possible to measure a distribution of values for a particular installation 16
  • 17. Network Time Protocol (NTP)  Christian’s & Berkeley algorithms for intranets  NTP designed for Internet  Large & variable message delays are handled through statistical techniques for filtering timing data  Discriminates between quality of timing data from different servers  Redundant servers & redundant paths between servers  Scalable – handles a large no of clients & servers  Authentication to ensure trusted time sources  Synchronization accuracy  ~10s of milliseconds over Internet paths  ~1 millisecond on LANs 17
  • 18. NTP (Cont.)  Hierarchical network of servers  Primary servers connected directly to a UTC time source  Secondary servers synchronized with primary servers  Servers connected in a logical hierarchy called a synchronization subnet whose levels are called strata  Lowest level (leaf) servers execute in users’ workstation 18
  • 19. Logical Time & Logical Clocks  Single process  Events are ordered uniquely by local clock time  Lamport (1978) pointed out that,  “since we can’t synchronize clocks perfectly across a distributed system, we can’t use physical time to find out order of any arbitrary pair of events within a distributed system”  In general, we can use a scheme that is similar to physical causality, to order some events that occur in different processes 19
  • 20. Physical Causality Based Ordering  If events occur on same process P, then they occur in the order in which P observes them  If a & b are events within a single process Pi, and a occurs before b, then a i b is true  Whenever a message is sent between processes, event of sending occurs before event of receiving  a = event of a message m being sent by process Pi  b = event of message m being received  then, a i b is true 20
  • 21. Lamport’s Notion of Event Ordering  Lamport generalized 2 (intuitive) physical- causality-based event ordering points to obtain happened-before partial ordering  A.k.a relation of causal ordering or potential causal ordering  Define “happened-before relation” (denoted by ) as follows  e i e/ for process Pi ⇒ e  e/  For any message m, send(m)  receive(m)  e  e/ and e/  e// ⇒ e  e// 21
  • 22. Happened-Before Relation 22 Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
  • 23. Happened-Before Relation 23  Events a & e that are not ordered by  are concurrent  Denoted by a || e Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
  • 24. Logical Clocks  Invented by Leslie Lamport to capture happened-before ordering numerically  Lamport Logical Clock  Monotonically increasing software counter  Value need not have a relationship to any physical clock  Each process Pi keeps its own logical clock Li, which it uses to apply Lamport timestamps to events  Li(e) = timestamp of event e at Pi  L(e) = timestamp of event e at process it occurred 24
  • 25. Lamport Timestamps  Processes update their logical clocks & transmit their logical clock values in messages as follows  LC1  Li = Li + 1, before each event is recorded at Pi  LC2  When Pi sends a message m, logical clock value t = Li, is piggy- backed with message  On receiving (m, t), a process Pj computes  Lj = max (Lj, t)  Then computes Lj = Lj + 1 before logically timestamping event receive(m)  Thus, e  e/ ⇒ L(e) < L(e/)  However, L(e) < L(e/) ⇏ e  e/ 25
  • 26. Lamport Timestamps – Example  Each process has its logical clock initialized to 0  L(b) > L(e) but b || e 26 Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
  • 27. Lamport Timestamps – Example  3 processes, each with its own clock  Clocks run at different rates  Lamport’s algorithm corrects clocks 27
  • 28. Totally Ordered Logical Clocks  Some pairs of distinct events generated by different processes have identical Lamport timestamps  A total order, where all pairs of distinct events are ordered, can be created by noting IDs of processes  Suppose,  (Ti, i) = global logical timestamp for event e at process Pi with local logical timestamp Ti  Similarly (Tj, j)  Then (Ti, i) < (Tj, j) ⇔ Ti < Tj or (Ti = Tj and i < j )  No general physical significance since process IDs are arbitrary  e.g., 2 events in P1 & P2, both with timestamp 40 can be globally timestamped as 40.1 & 40.2 28
  • 29. Application of Lamport’s Timestamps  Consider a database that has been replicated across several sites  e.g., a bank account database may be replicated in Colombo & Kandy  A query is always forwarded to the nearest copy (for fast response)  Update costs are higher since each update must be carried out at each replica in same order  Why? 29
  • 30. Application (Cont.)  Mr. Perera (lives in Kandy) has Rs. 1,000 in his account  Mr. Perera wants to deposit Rs. 100 to his account  At the same time, banking application (in Colombo) initiates an update to increase account balance with 1% interest  Both updates must be carried out at both copies of the database  Due to communication delays, we may have following situation:  In Kandy DB, Mr. Perera’s deposit is performed before interest update  (Rs. 1000 + Rs. 100) * 1.01 = Rs. 1,111  In Colombo DB, interest update is performed before Mr. Perera’s deposit  (Rs. 1000 * 1.01) + Rs. 100 = Rs. 1,110 30
  • 31. Application (Cont.)  Problem  Both updates were not performed in same order at each DB  Solution  Totally ordered multicast  Multicast operation where all messages are delivered in the same order to each receiver 31
  • 32. Totally Ordered Multicast  If process Pi sends messages x, y to processes Pj, Pk ,.. then all processes Pj, Pk … receive messages in the same order (x, y or y, x)  This doesn’t imply causal or even FIFO ordering  Solutions  Multicast through a central coordinator  Lamport’s solution 32
  • 33. Lamport’s Totally Ordered Multicast  Each multicast has a Lamport time stamp  All processors store received multicast in a queue  Order based on time stamp  Everyone has the same queue  Assume all messages sent by a sender are received in the order they were sent & no messages are lost  A time stamped ACK is sent back  Timestamp of multicast message < timestamp of ACK  A process can deliver (act on) the message at the head of queue only when it has received an ACK from all other processes 33
  • 34. Lamport’s Totally Ordered Multicast 34 Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
  • 35. Summary  Synchronization is important  Clock drift & clock skew  Physical clock synchronization  Logical time & logical clocks  Lamport Timestamps  Vector Clocks  Totally Ordered Multicast 35

Editor's Notes

  1. Maven in today’s context – for
  2. Christian’s algorithm and the Berkeley algorithm intended for intranets • Network Time Protocol (NTP) designed for the Internet
  3. physical causality - relationship between causes and effects
  4. Causality – Relationship between cause and effect
  5. Because Lamport Clocks induce a total ordering over all records, they actually imply more dependencies than truly exist.
  6. Rather than Mr. Perera getting more or less Rs. 1, key issue is 2 databases are not consistent