SlideShare a Scribd company logo
1 of 28
Time and synchronization
(“There’s never enough time…”)
Today’s outline
• Global Time
• Time in distributed systems
– A baseball example
• Synchronizing real clocks
– Cristian’s algorithm
– The Berkeley Algorithm
– Network Time Protocol (NTP)
• Logical time
• Lamport logical clocks
• Vector Clocks
Why Global Timing?
• Suppose there were a globally consistent
time standard
• Would be handy
– Who got last seat on airplane?
– Who submitted final auction bid before
deadline?
– Did defense move before snap?
Time Standards
• UT1
– Based on astronomical observations
– “Greenwich Mean Time”
• TAI
– Started Jan 1, 1958
– Each second is 9,192,631,770 cycles of radiation
emitted by Cesium atom
– Has diverged from UT1 due to slowing of earth’s
rotation
• UTC
– TAI + leap seconds to be within 800ms of UT1
– Currently 34
Comparing Time Standards
UT1 − UTC
Distributed time
• Premise
– The notion of time is well-defined (and
measurable) at each single location
– But the relationship between time at different
locations is unclear
• Can minimize discrepancies, but never eliminate
them
• Reality
– Stationary GPS receivers can get global time
with < 1µs error
– Few systems designed to use this
A baseball example
• Four locations: pitcher’s mound, first base, home plate,
and third base
• Ten events:
e1: pitcher throws ball to home
e2: ball arrives at home
e3: batter hits ball to pitcher
e4: batter runs to first base
e5: runner runs to home
e6: ball arrives at pitcher
e7: pitcher throws ball to first base
e8: runner arrives at home
e9: ball arrives at first base
e10: batter arrives at first base
A baseball example
• Pitcher knows e1 happens before e6, which
happens before e7
• Home plate umpire knows e2 is before e3,
which is before e4, which is before e8, …
• Relationship between e8 and e9 is unclear
Ways to synchronize
• Send message from first base to home?
– Or to a central timekeeper
– How long does this message take to arrive?
• Synchronize clocks before the game?
– Clocks drift
• million to one => 1 second in 11 days
• Synchronize continuously during the
game?
– GPS, pulsars, etc
Perfect networks
• Messages always arrive, with propagation
delay exactly d
• Sender sends time T in a message
• Receiver sets clock to T+d
– Synchronization is exact
Synchronous networks
• Messages always arrive, with propagation
delay at most D
• Sender sends time T in a message
• Receiver sets clock to T + D/2
– Synchronization error is at most D/2
Synchronization in the real world
• Real networks are asynchronous
– Propagation delays are arbitrary
• Real networks are unreliable
– Messages don’t always arrive
Cristian’s algorithm
• Request time, get reply
– Measure actual round-trip time d
• Sender’s time was T between t1 and t2
• Receiver sets time to T + d/2
– Synchronization error is at most d/2
• Can retry until we get a relatively small d
The Berkeley algorithm
• Master uses Cristian’s algorithm to get
time from many clients
– Computes average time
– Can discard outliers
• Sends time adjustments back to all clients
The Network Time Protocol (NTP)
• Uses a hierarchy of time servers
– Class 1 servers have highly-accurate clocks
• connected directly to atomic clocks, etc.
– Class 2 servers get time from only Class 1 and
Class 2 servers
– Class 3 servers get time from any server
• Synchronization similar to Cristian’s alg.
– Modified to use multiple one-way messages
instead of immediate round-trip
• Accuracy: Local ~1ms, Global ~10ms
Real synchronization is imperfect
• Clocks never exactly synchronized
• Often inadequate for distributed systems
– might need totally-ordered events
– might need millionth-of-a-second precision
Logical time
• Capture just the “happens before”
relationship between events
– Discard the infinitesimal granularity of time
– Corresponds roughly to causality
• Time at each process is well-defined
– Definition (→i): We say e →i e’ if e happens
before e’ at process i
Global logical time
• Definition (→): We define e → e’ using the
following rules:
– Local ordering: e → e’ if e →i e’ for any
process i
– Messages: send(m) → receive(m) for any
message m
– Transitivity: e → e’’ if e → e’ and e’ → e’’
• We say e “happens before” e’ if e → e’
Concurrency
• → is only a partial-order
– Some events are unrelated
• Definition (concurrency): We say e is
concurrent with e’ (written e║e’) if neither
e → e’ nor e’ → e
The baseball example revisited
• e1 → e2
– by the message rule
• e1 → e10, because
– e1 → e2, by the message rule
– e2 → e4, by local ordering at home plate
– e4 → e10, by the message rule
– Repeated transitivity of the above relations
• e8║e9, because
– No application of the → rules yields either e8 → e9 or
e9 → e8
Lamport logical clocks
• Lamport clock L orders events consistent with
logical “happens before” ordering
– If e → e’, then L(e) < L(e’)
• But not the converse
– L(e) < L(e’) does not imply e → e’
• Similar rules for concurrency
– L(e) = L(e’) implies e║e’ (for distinct e,e’)
– e║e’ does not imply L(e) = L(e’)
• i.e., Lamport clocks arbitrarily order some
concurrent events
Lamport’s algorithm
• Each process i keeps a local clock, Li
• Three rules:
1. At process i, increment Li before each event
2. To send a message m at process i, apply rule 1 and
then include the current local time in the message:
i.e., send(m,Li)
3. To receive a message (m,t) at process j, set Lj =
max(Lj,t) and then apply rule 1 before time-stamping
the receive event
• The global time L(e) of an event e is just its
local time
– For an event e at process i, L(e) = Li(e)
Lamport on the baseball example
• Initializing each local clock to 0, we get
L(e1) = 1 (pitcher throws ball to home)
L(e2) = 2 (ball arrives at home)
L(e3) = 3 (batter hits ball to pitcher)
L(e4) = 4 (batter runs to first base)
L(e5) = 1 (runner runs to home)
L(e6) = 4 (ball arrives at pitcher)
L(e7) = 5 (pitcher throws ball to first base)
L(e8) = 5 (runner arrives at home)
L(e9) = 6 (ball arrives at first base)
L(e10) = 7 (batter arrives at first base)
• For our example, Lamport’s algorithm says that
the run scores!
Total-order Lamport clocks
• Many systems require a total-ordering of
events, not a partial-ordering
• Use Lamport’s algorithm, but break ties
using the process ID
– L(e) = M * Li(e) + i
• M = maximum number of processes
Vector Clocks
• Goal
– Want ordering that matches causality
– V(e) < V(e’) if and only if e → e’
• Method
– Label each event by vector V(e) [c1, c2 …, cn]
• ci = # events in process i that causally precede e
Vector Clock Algorithm
• Initially, all vectors [0,0,…,0]
• For event on process i, increment own ci
• Label message sent with local vector
• When process j receives message with
vector [d1, d2, …, dn]:
– Set local each local entry k to max(ck, dk)
– Increment value of cj
Vector clocks on the baseball example
Event Vector Action
e1 [1,0,0,0] pitcher throws ball to home
e2 [1,0,1,0] ball arrives at home
e3 [1,0,2,0] batter hits ball to pitcher
e4 [1,0,3,0] batter runs to first base)
e5 [0,0,0,1] runner runs to home
e6 [2,0,2,0] ball arrives at pitcher
e7 [3,0,2,0] pitcher throws ball to 1st base
e8 [1,0,4,1] runner arrives at home
e9 [3,1,2,0] ball arrives at first base
e10 [3,2,3,0] batter arrives at first base
• Vector: [p,f,h,t]
Important Points
• Physical Clocks
– Can keep closely synchronized, but never
perfect
• Logical Clocks
– Encode causality relationship
– Lamport clocks provide only one-way
encoding
– Vector clocks provide exact causality
information

More Related Content

Similar to 09-time+synch.ppt

Physical and Logical Clocks
Physical and Logical ClocksPhysical and Logical Clocks
Physical and Logical ClocksDilum Bandara
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptMeymunaMohammed1
 
Synchronization Pradeep K Sinha
Synchronization Pradeep K SinhaSynchronization Pradeep K Sinha
Synchronization Pradeep K SinhaJawwad Rafiq
 
Unit iii-Synchronization
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-SynchronizationDhivyaa C.R
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System Harshita Ved
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptsirajmohammed35
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computingSVijaylakshmi
 
How shit works: Time
How shit works: TimeHow shit works: Time
How shit works: TimeTomer Gabel
 
Distributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmpinki soni
 

Similar to 09-time+synch.ppt (20)

Physical and Logical Clocks
Physical and Logical ClocksPhysical and Logical Clocks
Physical and Logical Clocks
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
 
3. syncro. in distributed system
3. syncro. in distributed system3. syncro. in distributed system
3. syncro. in distributed system
 
slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Chap 5
Chap 5Chap 5
Chap 5
 
6.Distributed Operating Systems
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating Systems
 
Synchronization Pradeep K Sinha
Synchronization Pradeep K SinhaSynchronization Pradeep K Sinha
Synchronization Pradeep K Sinha
 
Unit iii-Synchronization
Unit iii-SynchronizationUnit iii-Synchronization
Unit iii-Synchronization
 
Chapter 6 synchronization
Chapter 6 synchronizationChapter 6 synchronization
Chapter 6 synchronization
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
 
Clocks
ClocksClocks
Clocks
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.ppt
 
Ds practical file
Ds practical fileDs practical file
Ds practical file
 
Synchronisation
SynchronisationSynchronisation
Synchronisation
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
How shit works: Time
How shit works: TimeHow shit works: Time
How shit works: Time
 
Distributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithm
 
Isola 12 presentation
Isola 12 presentationIsola 12 presentation
Isola 12 presentation
 

Recently uploaded

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 

09-time+synch.ppt

  • 1. Time and synchronization (“There’s never enough time…”)
  • 2. Today’s outline • Global Time • Time in distributed systems – A baseball example • Synchronizing real clocks – Cristian’s algorithm – The Berkeley Algorithm – Network Time Protocol (NTP) • Logical time • Lamport logical clocks • Vector Clocks
  • 3. Why Global Timing? • Suppose there were a globally consistent time standard • Would be handy – Who got last seat on airplane? – Who submitted final auction bid before deadline? – Did defense move before snap?
  • 4. Time Standards • UT1 – Based on astronomical observations – “Greenwich Mean Time” • TAI – Started Jan 1, 1958 – Each second is 9,192,631,770 cycles of radiation emitted by Cesium atom – Has diverged from UT1 due to slowing of earth’s rotation • UTC – TAI + leap seconds to be within 800ms of UT1 – Currently 34
  • 6. Distributed time • Premise – The notion of time is well-defined (and measurable) at each single location – But the relationship between time at different locations is unclear • Can minimize discrepancies, but never eliminate them • Reality – Stationary GPS receivers can get global time with < 1µs error – Few systems designed to use this
  • 7. A baseball example • Four locations: pitcher’s mound, first base, home plate, and third base • Ten events: e1: pitcher throws ball to home e2: ball arrives at home e3: batter hits ball to pitcher e4: batter runs to first base e5: runner runs to home e6: ball arrives at pitcher e7: pitcher throws ball to first base e8: runner arrives at home e9: ball arrives at first base e10: batter arrives at first base
  • 8. A baseball example • Pitcher knows e1 happens before e6, which happens before e7 • Home plate umpire knows e2 is before e3, which is before e4, which is before e8, … • Relationship between e8 and e9 is unclear
  • 9. Ways to synchronize • Send message from first base to home? – Or to a central timekeeper – How long does this message take to arrive? • Synchronize clocks before the game? – Clocks drift • million to one => 1 second in 11 days • Synchronize continuously during the game? – GPS, pulsars, etc
  • 10. Perfect networks • Messages always arrive, with propagation delay exactly d • Sender sends time T in a message • Receiver sets clock to T+d – Synchronization is exact
  • 11. Synchronous networks • Messages always arrive, with propagation delay at most D • Sender sends time T in a message • Receiver sets clock to T + D/2 – Synchronization error is at most D/2
  • 12. Synchronization in the real world • Real networks are asynchronous – Propagation delays are arbitrary • Real networks are unreliable – Messages don’t always arrive
  • 13. Cristian’s algorithm • Request time, get reply – Measure actual round-trip time d • Sender’s time was T between t1 and t2 • Receiver sets time to T + d/2 – Synchronization error is at most d/2 • Can retry until we get a relatively small d
  • 14. The Berkeley algorithm • Master uses Cristian’s algorithm to get time from many clients – Computes average time – Can discard outliers • Sends time adjustments back to all clients
  • 15. The Network Time Protocol (NTP) • Uses a hierarchy of time servers – Class 1 servers have highly-accurate clocks • connected directly to atomic clocks, etc. – Class 2 servers get time from only Class 1 and Class 2 servers – Class 3 servers get time from any server • Synchronization similar to Cristian’s alg. – Modified to use multiple one-way messages instead of immediate round-trip • Accuracy: Local ~1ms, Global ~10ms
  • 16. Real synchronization is imperfect • Clocks never exactly synchronized • Often inadequate for distributed systems – might need totally-ordered events – might need millionth-of-a-second precision
  • 17. Logical time • Capture just the “happens before” relationship between events – Discard the infinitesimal granularity of time – Corresponds roughly to causality • Time at each process is well-defined – Definition (→i): We say e →i e’ if e happens before e’ at process i
  • 18. Global logical time • Definition (→): We define e → e’ using the following rules: – Local ordering: e → e’ if e →i e’ for any process i – Messages: send(m) → receive(m) for any message m – Transitivity: e → e’’ if e → e’ and e’ → e’’ • We say e “happens before” e’ if e → e’
  • 19. Concurrency • → is only a partial-order – Some events are unrelated • Definition (concurrency): We say e is concurrent with e’ (written e║e’) if neither e → e’ nor e’ → e
  • 20. The baseball example revisited • e1 → e2 – by the message rule • e1 → e10, because – e1 → e2, by the message rule – e2 → e4, by local ordering at home plate – e4 → e10, by the message rule – Repeated transitivity of the above relations • e8║e9, because – No application of the → rules yields either e8 → e9 or e9 → e8
  • 21. Lamport logical clocks • Lamport clock L orders events consistent with logical “happens before” ordering – If e → e’, then L(e) < L(e’) • But not the converse – L(e) < L(e’) does not imply e → e’ • Similar rules for concurrency – L(e) = L(e’) implies e║e’ (for distinct e,e’) – e║e’ does not imply L(e) = L(e’) • i.e., Lamport clocks arbitrarily order some concurrent events
  • 22. Lamport’s algorithm • Each process i keeps a local clock, Li • Three rules: 1. At process i, increment Li before each event 2. To send a message m at process i, apply rule 1 and then include the current local time in the message: i.e., send(m,Li) 3. To receive a message (m,t) at process j, set Lj = max(Lj,t) and then apply rule 1 before time-stamping the receive event • The global time L(e) of an event e is just its local time – For an event e at process i, L(e) = Li(e)
  • 23. Lamport on the baseball example • Initializing each local clock to 0, we get L(e1) = 1 (pitcher throws ball to home) L(e2) = 2 (ball arrives at home) L(e3) = 3 (batter hits ball to pitcher) L(e4) = 4 (batter runs to first base) L(e5) = 1 (runner runs to home) L(e6) = 4 (ball arrives at pitcher) L(e7) = 5 (pitcher throws ball to first base) L(e8) = 5 (runner arrives at home) L(e9) = 6 (ball arrives at first base) L(e10) = 7 (batter arrives at first base) • For our example, Lamport’s algorithm says that the run scores!
  • 24. Total-order Lamport clocks • Many systems require a total-ordering of events, not a partial-ordering • Use Lamport’s algorithm, but break ties using the process ID – L(e) = M * Li(e) + i • M = maximum number of processes
  • 25. Vector Clocks • Goal – Want ordering that matches causality – V(e) < V(e’) if and only if e → e’ • Method – Label each event by vector V(e) [c1, c2 …, cn] • ci = # events in process i that causally precede e
  • 26. Vector Clock Algorithm • Initially, all vectors [0,0,…,0] • For event on process i, increment own ci • Label message sent with local vector • When process j receives message with vector [d1, d2, …, dn]: – Set local each local entry k to max(ck, dk) – Increment value of cj
  • 27. Vector clocks on the baseball example Event Vector Action e1 [1,0,0,0] pitcher throws ball to home e2 [1,0,1,0] ball arrives at home e3 [1,0,2,0] batter hits ball to pitcher e4 [1,0,3,0] batter runs to first base) e5 [0,0,0,1] runner runs to home e6 [2,0,2,0] ball arrives at pitcher e7 [3,0,2,0] pitcher throws ball to 1st base e8 [1,0,4,1] runner arrives at home e9 [3,1,2,0] ball arrives at first base e10 [3,2,3,0] batter arrives at first base • Vector: [p,f,h,t]
  • 28. Important Points • Physical Clocks – Can keep closely synchronized, but never perfect • Logical Clocks – Encode causality relationship – Lamport clocks provide only one-way encoding – Vector clocks provide exact causality information