You are on page 1of 8

Introduction Clock synchronization is a problem from computer science and engineering which deals with the idea that

internal clocks of several computers may differ. Even when initially set accurately, real clocks will differ after some amount of time due to clock drift, caused by clocks counting time at slightly different rates. There are several problems that occur as a repercussion of rate differences and several solutions, some being more appropriate than others in certain contexts. In serial communication, some people use the term "clock synchronization" merely to discuss getting one metronome-like clock signal to pulse at the same frequency as another one frequency synchronization and phase synchronization. Such "clock synchronization" is used in synchronization in telecommunications and automatic baud rate detection. The description of the problem Besides the incorrectness of the time itself, there are problems associated with clock skew that take on more complexity in a distributed system in which several computers will need to realize the same global time. For instance, in Unix systems the make command is used to compile new or modified code without the need to recompile unchanged code. The make command uses the clock of the machine it runs on to determine which source files need to be recompiled. If the sources reside on a separate file server and the two machines have unsynchronized clocks, the make program might not produce the correct results. Solutions In a centralized system the solution is trivial; the centralized server will dictate the system time. Cristian's algorithm and the Berkeley Algorithm are some solutions to the clock synchronization problem in a centralized server environment. In a distributed system the problem takes on more complexity because a global time is not easily known. The most used clock synchronization solution on the Internet is the Network Time Protocol (NTP) which is a layered client-server architecture based on UDP message passing. Lamport timestamps and Vector clocks are concepts of the logical clocks in distributed systems. Cristian's algorithm

Cristian's algorithm relies on the existence of a time server. The time server maintains its clock by using a radio clock or other accurate time source, then all other computers in the system stay synchronized with it. A time client will maintain its clock by making a procedure call to the time server. Variations of this algorithm make more precise time calculations by factoring in network radio propagation time. Berkeley algorithm This algorithm is more suitable for systems where a radio clock is not present, this system has no way of making sure of the actual time other than by maintaining a global average time as the global time. A time server will periodically fetch the time from all the time clients, average the results, and then report back to the clients the adjustment that needs be made to their local clocks to achieve the average. This algorithm highlights the fact that internal clocks may vary not only in the time they contain but also in the clock rate. Often, any client whose clock differs by a value outside of a given tolerance is disregarded when averaging the results. This prevents the overall system time from being drastically skewed due to one erroneous clock. Cristian's algorithm Cristian's Algorithm (introduced by Flaviu Cristian in 1989) is a method for clock synchronisation which can be used in many fields of distributive computer science but is primarily used in low-latency intranets. Cristian observed that this simple algorithm is probabilistic, in that it only achieves synchronisation if the round-trip time (RTT) of the request is short compared to required accuracy. It also suffers in implementations using a single server, making it unsuitable for many distributive applications where redundancy may be crucial. Cristian's Algorithm works between a process P, and a time server S connected to a source of UTC (Coordinated Universal Time). Put simply: 1.P requests the time from S 2.After receiving the request from P, S prepares a response and appends the time T from its own clock. 3.P then sets its time to be T + RTT/2

P needs to record the Round Trip Time (RTT) of the request it made to S so that it can set its clock to T + RTT/2. This method assumes that the RTT is split equally between both request and response, which may not always be the case but is a reasonable assumption on a LAN connection. Further accuracy can be gained by making multiple requests to S and using the response with the shortest RTT. We can estimate the accuracy of the system as follows. Let min be the minimum time to transmit a message one-way. The earliest point at which S could have placed the time T, was min after P sent its request. Therefore, the time at S, when the message is received by P, is in the range (T + min) to (T + RTT - min). The width of this range is (RTT 2*min). This gives an accuracy of (RTT/2 - min). Server Pseudo Code // run forever because its a daemon do forever // receive a query from process k receive(q, k) // reply k with the local current time send(NOW, k) enddo Client PseudoCode // send query to process s (server) send(q, s) // get start time T1 := NOW // wait for process s to reply receive(T, s) // get end time T2 := NOW // set new time D := (T2 T1) / 2 C := T + D(1 + 2r) min*r If minimum message transit time (Tmin) is known then place bounds on accuracy of result

Error bounds



Earliest time message arrives

T0 T min




Latest time message leaves

range = T1 -T0 -2Tmin accuracy of result =

P age 2 8

Cristians algorithm: example

Send request at 5:08:15.100 (T 0) Receive response at 5:08:15.900 (T1)
Response contains 5:09:25.300 ( Tserver )

Elapsed time is T 1 -T0

5:08:15.900 - 5:08:15.100 = 800 msec 400 msec ago

Best guess: timestamp was generated Set time to T server+ elapsed time
5:09:25.300 + 400 = 5:09.25.700

P ag e 2 9

Cristians algorithm: e

If best-case message tim

Minimum error is 3 * * min 2 messages for each Synchronization 2n messages for n processes Berkeley Algorithm The Berkeley algorithm is a method of clock synchronisation in distributed computing which assumes no machine has an accurate time source. It was developed by Gusella and Zatti at the University of California, Berkeley in 1989 [1] and like Cristian's algorithm is intended for use within intranets Unlike Cristian's algorithm the server process in Berkeley algorithm, called the master periodically polls other slave process. Generally speaking the algorithm is as follows: 1.A master is chosen via an election process such as Chang and Roberts algorithm. 2.The master polls the slaves who reply with their time in a similar way to Cristian's algorithm. 3.The master observes the round-trip time (RTT) of the messages and estimates the time of each slave and its own. 4.The master then averages the clock times, ignoring any values it receives far outside the values of the others.






Error =

5.Instead of sending the updated current time back to the other process, the master then sends out the amount (positive or negative) that each slave must adjust its clock. This avoids further uncertainty due to RTT at the slave processes. With this method the average cancels out individual clock's tendencies to drift. Gusella and Zatti released results involving 15 computers whose clocks were synchronised to within about 20-25 milliseconds using their protocol. Computer systems normally avoid rewinding their clock when they receive a negative clock alteration from the master. Doing so would break the property of monotonic time, which is a fundamental assumption in certain algorithms in the system itself or in programs such as make. A simple solution to this problem is to halt the clock for the duration specified by the master, but this simplistic solution can also cause problems, although they are less severe. For minor

Berkeley Algorithm



Berkeley Algorithm

Algorithm has provis from clocks whose sk

Pseudocode: M master , Si slave i Tm-master time,Tsi-slave i time get Tm // get masters time Tsum = 0 n=0// number of computers with the time in the corect range

Compute a fault-to

If master fails
Any slave can take

Tsum += Tm // add master time for each si request Tsi // get time for each slave if Tsi is outside of the range of the rest then ignore Tsi else n++ Tsum += Tsi // sum of all times end for; ftAvg = Tsum/n // calculate fault-tolerant average dif = 0 // the value that must be sent to each computer dif = ftAvg -Tm // dif is calculated based on computers time and the fault-tolerant average ( the difference between them ) send dif to M // send the value to adjust the computers clock for each Tsi dif = ftAvg - Tsi send dif to Si end for; Conslusion Clock synchronization is required for internal and external synchronization of clocks for various transaction processes and process controls. A more efficient algorithm will lead to a better convergence.