Time This powerpoint presentation has been adapted from: 1) www.cse.buffalo.edu/~bina/cse486/.../TimeGlobalState sApr20.ppt Contents Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks Contents Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks Time Introduction Why time is important in distributed systems? A quantity that needs to be measured accurately • to know at what time of day a particular event occurred at a particular computer • is important for auditing purposes • to maintain the consistency of distributed data Contents Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks Time Clocks, events and process states How to timestamp events in terms of their execution? Consider the following notations •ϸ – A collection of N processes pi, i = 1,2, .. N (p executes on a single processor) • si – The state of pi (each p has a state, the state changed when it is executed) • Actions of pi – Operations that transform pi’s state (p executes with a series of actions. – Send or receive message between pi Time Clocks, events and process states e • Event: occurrence of a single action Relation between the events(i) • The series of events for a single process p • e.g., e i e` : e occurs before e` at pi history(pi ) = hi = <ei0, ei1, ei2, …> • The series of event e in process pi Time Clocks, events and process states How to timestamp the events (e)? Clock in computer: • Each computer has its own physical clock • Is a device that counts oscillations occurring in a crystal at a definite frequency • The OS reads the node’s hardware time: Hi(t) » The counts of oscillation since an original point • Then, scale it and add offset to produce software clock, Ci(t) = Hi(t)+ » To timestamp of an event Time Clocks, events and process states Computer clocks tend not to be in a perfect agreement. Netw ork Clock drift • Clocks count time at different rates Clock skew • The instantaneous (direct) difference between the readings of any two clocks Why? Oscillators are subject to physical variations • Frequency, temperature Time Clocks, events and process states How to synchronize computer clocks? Use external source that provide highly accurate time Use atomic oscillator Used by International Atomic Time Time Clocks, events and process states What is the international standard for time keeping? Coordinated Universal Time (UTC) • Based on atomic time • Time is coordinated with astronomical time • UTC signal is broadcasted from land-based radio station to satellites covering many parts of the world Contents Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks Time Synchronizing physical clocks How to know at what time of the day an event occurs? Two types of synchronization: • External • Internal Notations: • Ci : pi’s clock • I : an interval of real time Time Synchronizing physical clocks External synchronization For a synchronization bound D > 0, and for a source S of UTC time, |S(t)-Ci(t)| < D, for i = 1, 2, … N and for all real times t in I Clocks Ci are accurate to within the bound D Internal synchronization For a synchronization bound D > 0, |Ci(t)-Cj(t)| < D for i, j =1,2, … N, and for all real times t in I Clocks Ci agree within the bound D Clocks that are internally synchronized are not necessarily externally synchronized If the system ϸ is externally synchronized with a bound D, then the same system is internally synchronized with a bound of 2D. Time Synchronizing physical clocks Synchronization in a synchronous system there will be a minimum time of transmission where no other processes executed at the same time and no other network traffic existed. Maximum time of transmission in synchronous mode is always set (i.e., time out is applied) Protocol • Sender: send M(t) • Receiver: set time to t + Ttrans Bounds are known in synchronous system • min < Ttrans < max (constant) Optimum transmission time, • Ttrans = (min+max) / 2 • Receiver’s clock = t + (min+max) / 2 t t + min t +Ttrans t+max Time Synchronizing physical clocks The common practice in distributed system is asynchronous; The factors lead to message delay are not bounded (no upper bound max) The Internet is asynchronous Ttrans = min + x, where x ≥ 0, the value of x is not known Methods for synchronizing clock in asynchronous distributed systems: • Cristian’s method • The Berkeley algorithms • The Network Time Protocol Time Synchronizing physical clocks Cristian’s method of synchronizing clocks Use time server Protocol • mr – process p requests the time from server • mt – process receives the time (t is inserted in the message) • Tround - process p records the round-trip (send requestget reply) • Estimated time: t + Tround/2 mr p mt Time server,S Time Synchronizing physical clocks Cristian’s method of synchronizing clocks Accuracy analysis • If the minimum delay of a message transmission is min, then accuracy: (Tround/2 – min) t + min t t +Tround-min t +Tround/2 t +Tround Time and Global State Synchronizing physical clocks The Berkeley algorithms Internal synchronization using a coordinator computer (master). Other computers that their clocks need to be synchronized is known as slaves 1. 2. 3. 4. 5. The master polls the slaves’ clocks The master estimates the slaves’ clocks by roundtrip time The master averages the slaves’ clock values The master sends back to the slaves the amount that the slaves’ clocks should adjust Slave adjust its clock Time Synchronizing physical clocks The Network Time Protocol (NTP) An architecture for a time service and a protocol to distribute time information over the Internet Aims: • External synchronization – Enable clients across the Internet to be synchronized accurately to UTC • Reliability – Can survive lengthy losses of connectivity » Redundant server & redundant path between servers • Scalability – Enable clients to resynchronize sufficiently frequently to offset the rates of drift found in most computers • Security – Protect against interference with the time service Time Synchronizing physical clocks NTP service is provided by servers located across the Internet Primary servers are connected directly to a time source, e.g. radio clock receiving UTC Secondary servers are synchronized to primary servers Time Synchronizing physical clocks Network Time Protocol Architecture 1 2 3 2 3 3 Note: Arrows denote synchronization control, numbers denote strata. Source: Wikipedia Time Synchronizing physical clocks 3 modes of NTP synchronization: Multicast mode • Intended for use on a high speed LAN • One or more servers multicast the time to other servers in the LAN • Low accuracy but sufficient Procedure-call mode • Similar to Christian’s • Higher accuracy than multicast Symmetric mode • Use by the servers that supply time information in LANs • The highest accuracy Contents Introduction Clocks, events and process states Synchronizing physical clocks Logical time & logical clocks Time Logical time and logical clocks Events in a single process is ordered uniquely by times shown in the local clock Clock is unable to be synchronized perfectly. Hence physical time is not accurate to determine the occurrence of events Time Logical time and logical clocks Happened-before relation It is also sometimes known as the relation of causal ordering or potential causal ordering. Time Logical time and logical clocks Logical clocks- a simple mechanism to capture HB order numerically. Known as Lamport timestamps algorithm (it is a software counter). LC1 • Li is incremented before each event is issued at process pi : Li :=Li+1 LC2: (a) When a process pi sends a message m, it adjoin the value t = Li on m (b) On receiving (m,t), a process Pj computes Lj := max(Lj, t) and then applies LC1 before timestamping the event receive(m) Time Logical time and logical clocks Totally ordered logical clocks algorithm Assumption Ti : local timestamp of e that is an event occurring at pi Tj : local timestamp of e` that is an event occurring at pj The timestamps of two events e and e` are (Ti, i), (Tj, j) When (Ti, i) < (Tj, j), if and only if Ti < Tj , or Ti = Tj and i < j Time Logical time and logical clocks Vector Clocks algorithm Each process pi keeps a vector clock Vi VC1: Initially, Vi[j]=0, for i, j = 1,2…, N VC2: Just before pi timestamps an event, it sets Vi[i] := Vi[i] +1 VC3: pi includes the value t= Vi in every message it sends VC4: When pi receives a timestamp t in a message, it sets Vi[j] :=max(Vi[j], t[j]), for j=1,2…,N End of the Chapter…
© Copyright 2026 Paperzz