Time This powerpoint presentation has been adapted from
Time This powerpoint presentation has been adapted from: 1) www. cse. buffalo. edu/~bina/cse 486/. . . /Time. Global. State s. Apr 20. 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 • ϸ • si – A collection of N processes pi, i = 1, 2, . . N (p executes on a single processor) – 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 = <ei 0, ei 1, ei 2, …> • 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. ü 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 2 D.
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 2 ----3 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). üLC 1 • Li is incremented before each event is issued at process pi : Li : =Li+1 üLC 2: (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 LC 1 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 VC 1: Initially, Vi[j]=0, for i, j = 1, 2…, N VC 2: Just before pi timestamps an event, it sets Vi[i] : = Vi[i] +1 VC 3: pi includes the value t= Vi in every message it sends VC 4: 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… -------
- Slides: 31