Distribuerede systemer 5 marts 2001 Presentation based on
Distribuerede systemer – 5. marts 2001 Presentation based on slides by Coulouris et al Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 1
Slides for Chapter 10: Time (and Global State) From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001 2
Time - purpose z We want to know when something happened, e. g. , for the purpose of: y. E-commerce. ymake utility. z Algorithms may depend upon clock synchronization, e. g. : y. Maintain consistency of distributed data. y. Eliminating the processing of duplicate updates. z No global notion of time. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 3
Time – system model z N processes: y. Each executes on a single processor. y. No shared memory. y. Only communication means is exchange of messages. z pi has state si. z An event is the occurrence of a single action, i. e. , either: y An internal state-transforming action by pi, or y A communication action. z e (->i) e’ iff e occurs before e’ in pi. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 4
Time - clocks z Each computer contains its own physical clock. z The software clock Ci can be used to timestamp any event at pi. z Clock skew: The instantaneous difference between the readings of any two clocks. z Clock drift: Clocks count time at different rates and so diverge. z Clock drift rate: The difference in reading between a given clock and a nominal perfect reference clock per time unit measured by the reference clock. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 5
Time - skew between computer clocks in a distributed system Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 6
Time – Coordinated Universal Time (UTC) z An international standard for timekeeping. z Based on atomic time. z Synchronizes with astronomical time using leap seconds. z UTC signals are synchronized and broadcast regularly from land-based radio stations and satellites. z Computers with receivers attached can synchronize their clocks with these timing signals. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 7
Synchronizing physical clocks - basics z External synchronization: For each i, synchronize Ci with an authoritative, external source of time. z Internal synchronization: For each i, j, synchronize Ci and Cj with each other. z Other issues: Correctness, monotonicity, faulty clocks, crash failures, arbitrary failures. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 8
Synchronizing physical clocks – in a synchronous system z In a synchronous system, bounds are known for: y. The drift rates of clocks. y. The maximum message transmission delay. y. The time to execute each step of a process. z One process sends the time t on its local clock to the other in a message m. The receiving process could set its time to: t + T(trans). z T(trans) is subject to variation and unknown – but within limits; T(trans) in [min, max]. z Better for receiver to set its time to: t + (max+min)/2. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 9
Synchronizing physical clocks – clock synchronization using a time server (Cristian’s method) External synchronization mr mt p Time server, S p records total round-trip time T(round); p sets its time to t+T(round)/2; If minimal transmission time is known, accuracy can be calculated. Problem: single-point-of-failure. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 10
Synchronizing physical clocks – the Berkeley algorithm z Internal synchronization. z A coordinator computer is chosen to act as master. z Master periodically polls the other computers (the slaves). z Slaves send back their clock values to master. z Master calculates an average (taking the roundtrip times into account). z Master sends the amount by which each individual slave’s clock requires adjustment. z The algorithm eliminates readings from faulty clocks. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 11
Synchronizing physical clocks – the Network Time Protocol (NTP) z Chief design aims and features: y To provide a service enabling clients across the Internet to be synchronized accurately to UTC. y To provide a reliable service that can survive lengthy losses of connectivity. y To enable clients to resynchronize sufficiently frequently to offset the rates of drift found in most computers. y To provide protection against interference with the timeservice, whether malicious or accidental. z Architecture: y A network of servers located across the Internet. y Primary servers connected directly to time source. y Secondary servers synchronized with primary servers. y Servers connected in logical hierarchy, synchronization subnet. y Three modes of sync. : Multicast, procedure-call, symmetric. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 12
Synchronizing physical clocks – An example synchronization subnet in an NTP implementation 1 2 3 3 Note: Arrows denote synchronization control, numbers denote strata. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 13
Synchronizing physical clocks – Messages exchanged between a pair of NTP peers Server B Ti-2 m Ti-1 Time m' Time Server A Ti- 3 Ti Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 14
Logical time and logical clocks - basics z Since we cannot synchronize clocks perfectly across a distributed system, we cannot in general use physical time to find out the order of any arbitrary pair of events occurring within it. z Events can be ordered by the happened-before relation: y. If two events occurred at the same process pi, then they occurred in the order in which pi observes them (->i). y. Whenever a message is sent between processes, the event of sending the message occurred before the event of receiving the message. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 15
Logical time and logical clocks example events occurring at three processes Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 16
Logical time and logical clocks – Lamport logical clocks and timestamps z A Lamport logical clock is a monotonically increasing software counter. z Each process pi keeps its own logical clock Li which is used to apply Lamport timestamps to events. z To capture the happened-before relation ->, processes update their logical clocks and transmit the values of their logical clocks in messages as follows: y Before each event at pi: Li : = Li+1 y When pi sends a message m, it piggybacks t=Li. y When pj receives (m, t): Lj : = max(Lj, t)+1. z e -> e’ => L(e) < L(e’). Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 17
Logical time and logical clocks – Lamport timestamps for example events Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 18
Logical time and logical clocks – Vector timestamps for example events Vi[i]: The number of events that pi has timestamped; Vi[j]: The number of events that have occurred at pj that pi has potentially been affected by, j <> i. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 19
Summary z Time in general. z Synchronization of physical clocks: y. In a synchronous system. y. Cristian’s method. y. The Berkeley algorithm. y. The Network Time Protocol (NTP). z Logical time and logical clocks: y. The happened-before relation. y. Lamport’s logical clocks and Lamport’s timestamps. y. Vector timestamps. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 20
- Slides: 20