SlideShare a Scribd company logo
1 of 35
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

More Related Content

What's hot

Message and Stream Oriented Communication
Message and Stream Oriented CommunicationMessage and Stream Oriented Communication
Message and Stream Oriented CommunicationDilum Bandara
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency ControlDilum Bandara
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithmBushra M
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architectureYisal Khan
 
System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed systemishapadhy
 
Communications is distributed systems
Communications is distributed systemsCommunications is distributed systems
Communications is distributed systemsSHATHAN
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems Haitham Ahmed
 
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
 
Election algorithms
Election algorithmsElection algorithms
Election algorithmsAnkush Kumar
 
Introduction to Distributed System
Introduction to Distributed SystemIntroduction to Distributed System
Introduction to Distributed SystemSunita Sahu
 
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
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software conceptsPrajakta Rane
 
Scheduling Definition, objectives and types
Scheduling Definition, objectives and types Scheduling Definition, objectives and types
Scheduling Definition, objectives and types Maitree Patel
 
Structure of shared memory space
Structure of shared memory spaceStructure of shared memory space
Structure of shared memory spaceCoder Tech
 
Issues in routing protocol
Issues in routing protocolIssues in routing protocol
Issues in routing protocolPradeep Kumar TS
 

What's hot (20)

Message and Stream Oriented Communication
Message and Stream Oriented CommunicationMessage and Stream Oriented Communication
Message and Stream Oriented Communication
 
Message passing in Distributed Computing Systems
Message passing in Distributed Computing SystemsMessage passing in Distributed Computing Systems
Message passing in Distributed Computing Systems
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
 
System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed system
 
Communications is distributed systems
Communications is distributed systemsCommunications is distributed systems
Communications is distributed systems
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems
 
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
 
Election algorithms
Election algorithmsElection algorithms
Election algorithms
 
Introduction to Distributed System
Introduction to Distributed SystemIntroduction to Distributed System
Introduction to Distributed System
 
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
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
 
Process Management-Process Migration
Process Management-Process MigrationProcess Management-Process Migration
Process Management-Process Migration
 
Scheduling Definition, objectives and types
Scheduling Definition, objectives and types Scheduling Definition, objectives and types
Scheduling Definition, objectives and types
 
Structure of shared memory space
Structure of shared memory spaceStructure of shared memory space
Structure of shared memory space
 
Course outline of parallel and distributed computing
Course outline of parallel and distributed computingCourse outline of parallel and distributed computing
Course outline of parallel and distributed computing
 
Issues in routing protocol
Issues in routing protocolIssues in routing protocol
Issues in routing protocol
 

Similar to Physical and Logical Clocks

Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Sri Prasanna
 
A Deterministic Model Of Time For Distributed Systems
A Deterministic Model Of Time For Distributed SystemsA Deterministic Model Of Time For Distributed Systems
A Deterministic Model Of Time For Distributed SystemsJim Webb
 
Unit iii-Synchronization
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-SynchronizationDhivyaa C.R
 
Concepts of Real time Systems (RTS)
Concepts of Real time Systems (RTS)Concepts of Real time Systems (RTS)
Concepts of Real time Systems (RTS)EngKarrarSMuttair
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptsirajmohammed35
 
Survey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling AlgorithmsSurvey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling AlgorithmsIOSR Journals
 
Distributed computing time
Distributed computing timeDistributed computing time
Distributed computing timeDeepak John
 
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...
Coupling-Based Internal Clock Synchronization for Large Scale Dynamic Distrib...Angelo Corsaro
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptMeymunaMohammed1
 

Similar to Physical and Logical Clocks (20)

Clock.pdf
Clock.pdfClock.pdf
Clock.pdf
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Time in distributed systmes
Time in distributed systmesTime in distributed systmes
Time in distributed systmes
 
Synch
SynchSynch
Synch
 
Chap 5
Chap 5Chap 5
Chap 5
 
Clocks
ClocksClocks
Clocks
 
Ds ppt imp.
Ds ppt imp.Ds ppt imp.
Ds ppt imp.
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)
 
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
 
A Deterministic Model Of Time For Distributed Systems
A Deterministic Model Of Time For Distributed SystemsA Deterministic Model Of Time For Distributed Systems
A Deterministic Model Of Time For Distributed Systems
 
Unit iii-Synchronization
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-Synchronization
 
Concepts of Real time Systems (RTS)
Concepts of Real time Systems (RTS)Concepts of Real time Systems (RTS)
Concepts of Real time Systems (RTS)
 
Distributed Computing
Distributed ComputingDistributed Computing
Distributed Computing
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.ppt
 
Survey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling AlgorithmsSurvey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling Algorithms
 
Distributed computing time
Distributed computing timeDistributed computing time
Distributed computing time
 
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...
Coupling-Based Internal Clock Synchronization for Large Scale Dynamic Distrib...
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
 
Hu3513551364
Hu3513551364Hu3513551364
Hu3513551364
 

More from Dilum Bandara

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine LearningDilum Bandara
 
Time Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeTime Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeDilum Bandara
 
Introduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCAIntroduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCADilum Bandara
 
Introduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsIntroduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsDilum Bandara
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresDilum Bandara
 
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixHard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixDilum Bandara
 
Introduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopIntroduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopDilum Bandara
 
Embarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsEmbarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsDilum Bandara
 
Introduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersIntroduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersDilum Bandara
 
Introduction to Thread Level Parallelism
Introduction to Thread Level ParallelismIntroduction to Thread Level Parallelism
Introduction to Thread Level ParallelismDilum Bandara
 
CPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesCPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesDilum Bandara
 
Data-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsData-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsDilum Bandara
 
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesInstruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesDilum Bandara
 
Instruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesInstruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesDilum Bandara
 
CPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionCPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionDilum Bandara
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
High Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPHigh Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPDilum Bandara
 
Introduction to Content Delivery Networks
Introduction to Content Delivery NetworksIntroduction to Content Delivery Networks
Introduction to Content Delivery NetworksDilum Bandara
 
Peer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingPeer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingDilum Bandara
 

More from Dilum Bandara (20)

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Time Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeTime Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in Practice
 
Introduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCAIntroduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCA
 
Introduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsIntroduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive Analytics
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data Structures
 
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixHard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
 
Introduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopIntroduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with Hadoop
 
Embarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsEmbarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel Problems
 
Introduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersIntroduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale Computers
 
Introduction to Thread Level Parallelism
Introduction to Thread Level ParallelismIntroduction to Thread Level Parallelism
Introduction to Thread Level Parallelism
 
CPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesCPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching Techniques
 
Data-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsData-Level Parallelism in Microprocessors
Data-Level Parallelism in Microprocessors
 
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesInstruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware Techniques
 
Instruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesInstruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler Techniques
 
CPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionCPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An Introduction
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
High Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPHigh Performance Networking with Advanced TCP
High Performance Networking with Advanced TCP
 
Introduction to Content Delivery Networks
Introduction to Content Delivery NetworksIntroduction to Content Delivery Networks
Introduction to Content Delivery Networks
 
Peer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingPeer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and Streaming
 
Mobile Services
Mobile ServicesMobile Services
Mobile Services
 

Recently uploaded

Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 

Recently uploaded (20)

Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 

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