Download presentation
Presentation is loading. Please wait.
Published byAugustine Allison Modified over 8 years ago
1
Topic 7: Time and Global State Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine
2
7.1 Introduction The management of time is crucial to the operation of a distributed system: ⁻Need to know the time in order to measure at what time events occurred. ⁻Need to timestamp events occurring at different processes accurately to order their execution. Each computer in a distributed system contains its own physical clock. Physical clocks are electronic devices which software components use to manage timing operations in the system.
3
7.1 Introduction Computer clocks, are not in perfect agreement as experienced in normal clocks. The instantaneous difference between the reading of any two clocks is termed their skew. the crystal-based clocks used in computers are, like any other clocks, subject to clock drift, which means that they count time at different rates A clock’s drift rate is the change in the offset (difference in reading) between the clock and a nominal perfect reference clock per unit of time measured by the reference clock. Thus, synchronisation is required to approximately unifying the time at each node in a distributed system. One way to achieve synchronisation is to use external sources: ⁻Example: UTC (Coordinated Universal Time), is an international standard for timekeeping. ⁻UTC signals are synchronised and broadcasted from land-based radio stations and satellites covering many parts of the world. ⁻Computers with receivers attached to them synchronise their clocks with such timing signals.
4
7.1 Introduction
5
7.2 Synchronizing physical clocks In order to determine the time at which events occur at processes in a distributed system, ⁻It is necessary to synchronise the processes’ clocks Ci with an external source of time. ⁻This is termed External Synchronisation. In order to determine the time intervals between the occurrence of events at different processes and the order at which these events are executed, ⁻We need to go back to synchronise the processes’ local clocks. ⁻This does not necessarily require synchronising to an external time source. ⁻This is termed Internal Synchronisation.
6
7.2 Synchronizing physical clocks
7
Clocks that are internally synchronised are not necessarily externally synchronised, since they can all drift from an external source of time even if they agree with one another. However it can be seen from the definitions that if a system is externally synchronised with a bound D, then the same system is internally synchronised with a bound of 2D.
8
7.2.1 Cristian’s Method for Synchronising Clocks Cristian proposed using a time server, connected to a device that receives signals from a UTC source, to synchronise computers externally. On request, the server process S supplies the time according to its clock as shown in the figure on the next slide. Process P requests the time in a message Mr, and receives the time value t in a message Mt. Process P records the total round-trip time T round that was required to send the request and receive the reply. This round-trip time can be measured with a good accuracy if the clock’s drift rate is small (e.g. 10^-6 seconds/second)
9
7.2.1 Cristian’s Method for Synchronising Clocks The value of the round-trip time usually ranges between 1-10 ms. A simple estimate of the time to which P should be set is t + T round / 2. This assumes that the time is split equally between before and after t is placed in Mt.
10
7.2.1 Cristian’s Method for Synchronising Clocks Limitations of Cristian’s Algorithm All time services are implemented by a single server and failure of such server causes synchronisation to be impossible temporarily. To overcome this problem, Cristian suggests that time should be provided by a group of synchronised time servers, each with a receiver for UTC time signals. E.g., the client can multicast a request for time and use only the first reply received. Cristian’s algorithm is more suited to LAN and does not operate with good accuracy in bigger network topologies such as the Internet.
11
7.2.2 The Berkeley Algorithm A coordinator computer is chosen to act as the master. Master periodically polls to slaves whose clocks are to be synchronized. The master estimates their local clock times by observing the round-trip times, and it averages the values obtained. The master takes a fault-tolerant average. the master updates it current time and then sends the back only the amount by which each individual slave’s clock requires adjustment. the amount time maybe positive or negative. Should the master fail, then another can be elected to take over.
12
7.2.2 The Network Time Protocol The Network Time Protocol (NTP) defines an architecture for a time service and a protocol to distribute time information over the Internet. The aim is to enable clients across the Internet to be synchronised accurately to UTC despite the large and variable message delays faced in Internet Communication. To provide a reliable service that can survive lengthy sessions of losing connectivity, NTP uses redundant servers and paths between the servers which are reconfigured to continue to provide the service if one or more servers become unavailable.
13
7.2.3 The Network Time Protocol To enable clients to resynchronise frequently to offset drift rates, i.e. to support large client load, the service is designed to scale to a large number To provide protection against interference, the time service uses authentication techniques to check that timing is originated from trusted servers.
14
7.2.3 The Network Time Protocol
15
In NTP, primary servers are connected directly to a UTC time source. Secondary servers are synchronised with primary sources. Servers are connected in a logical hierarchy called a synchronisation subnet whose levels are called strata. Primary servers occupy stratum 1 which are at the root. Stratum 2 servers are secondary servers that are synchronised directly with primary servers. The lowest-level (leaf) servers execute in users’ machines.
16
7.2.3 The Network Time Protocol NTP servers synchronize in three modes: Multicast mode Procedure-call mode Symmetric mode Estimating delay and offset in NTP protocol: a = Ti-2 - Ti-3 b = Ti –Ti-1 di = a + b oi = (a-b)/2
17
7.2.3 The Network Time Protocol As we go down in the tree hierarchy, clocks tend to be less accurate as errors happens at each level of synchronisation. The synchronisation subnet can be reconfigured as servers become in a failure state. NTP takes into account the total round-trip delays to the root in assessing the quality of time data held by a particular server. The offsets experienced by different clocks are constantly monitored by NTP to assists the quality of timing information used by different machines in the system.
18
7.4 Logical Time and Logical Clocks For many purposes, it is sufficient that all machines agree on the same time and it is not necessary that this time also agree with a real external time. I.e. when the internal consistency of clocks is required, such clocks are termed logical clocks.
19
7.4 Logical Time and Logical Clocks The order of the events: two events occurred in the order they appear in a process. event of sending occurred before event of receiving. happened-before relation, denoted by → HB1: If ∃ process p: x →p y, then x → y. If two events occurred at the same process p, then they occurred in the order noted by the process, e.g. execution of X followed by the execution of y. Then x -> y is true. HB2: For any message m, send(m) → rcv(m) When an event x represents the sending of a message from one process to another and y represents the reception of such message by another process, then x -> y is also true. HB3: If x, y and z are events such that x → y and y → z, then x → z.
20
7.4 Logical Time and Logical Clocks Events occurring at three processes
21
7.4.1 Lamport Algorithm Logical clock - a monotonically increasing software counter. C p : logical clock for process p; C p (a): timestamp of event a at p; C(b): timestamp of event b. LC1: event issued at process p: C p := C p + 1. LC2: a) p sends message m to q with value t = C p b) Cq := max(Cq,t) and applies LC1 to rcv(m). If a → b then C(a) < C(b), but not visa versa! Total order logical clock and vector clock.
22
7.4.1 Lamport Algorithm
23
The following is true in the example shown on the previous slide: a -> b is true, since the two event a and b occur at the same process Pi. For the same reason, c -> d. b-> c since these events represent sending and receiving a message M1. The same apply for d -> f. a ->f is also true. a -> e is false as: They occur at different processes. They are not related by message communication.. A and e are concurrent events and can be expressed as a||e.
24
7.4.2 Vector Clocks Vector clock: A vector clock of N processes is an array of N integers. Each process keeps its own vector clock Vi, which it uses to timestamp a local event. 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. Taking the component-wise maximum of two vector timestamps in this way is known as a merge operation.
25
7.4.2 Vector Clocks
26
7.4.3 Lamport VS.Vector Clocks In Lamport’s clock, C(e)<C(e’) does not imply e → e’; while in Vector timestamp, V(e)<V(e’) implies e → e’. Vector timestamps take up an amount of storage and message payload that is proportional to N, the number of process; while Lamport’s clock does not.
27
7.4.4 Lamport Timestamps Exercise
28
7.4.4 Lamport Timestamps Answer
29
7.4.5 Vector Clocks Exercise
30
7.4.5 Vector Clocks Answer
31
7.4.6 Quiz (10 mints) 2.5 marks The figure bellow shows events occurring for each of two processes, p1 and p2. Arrows between processes denote message transmission. Draw and label the shown events using both Lamport Timestamps and Vector Clocks algorithms
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.