Clock Synchronization:
In Computer Science and Engineering, distributed system includes a set of processors which communicate through message transmission without having access to a central clock. But, the processors needs to know come common notion of time which can be either an exact time or simply an integer-valued counter. This technique that is used to coordinate the notion of time is known as clock synchronization.
Clock Synchronization Algorithms-
- Berkeleyâs Algorithm
- Cristianâs Algorithm
Berkeleyâs Algorithm:
Berkeleyâs Algorithm is a clock synchronization technique used in distributed systems. The algorithm assumes that each machine node in the network either doesnât have an accurate time source or doesnât possess an UTC server.
Algorithm
1) An individual node is chosen as the master node from a pool node in the network. This node is the main node in the network which acts as a master and rest of the nodes act as slaves. Master node is chosen using an election process/leader election algorithm.
2) Master node periodically pings slavesâ nodes and fetches clock time at them using Cristianâs algorithm.
Diagram below illustrates how slave nodes send back time given by their system clock.
3) Master node calculates average time difference between all the clock times received and the clock time given by masterâs system clock itself. This average time difference is added to the current time at masterâs system clock and broadcasted over the network.
Cristianâs Algorithm:
Cristianâs Algorithm is a clock synchronization algorithm is used to synchronize time with a time server by client processes. This algorithm works well with low-latency networks where Round Trip Time is short as compared to accuracy while redundancy prone distributed systems/applications do not go hand in hand with this algorithm. Here Round-Trip Time refers to the time duration between start of a Request and end of corresponding Response.
Below is an illustration imitating working of cristianâs algorithm:
Algorithm:
1) The process on the client machine sends the request for fetching clock time(time at server) to the Clock Server at time T_0.
2) The Clock Server listens to the request made by the client process and returns the response in form of clock server time.
3) The client process fetches the response from the Clock Server at timeÂ
T1Â and calculates the synchronised client clock time using the formula given below.
TCLIENT =TSERVER + (T1-T0)/2
where TCLIENT refers to the synchronised clock time
TSERVER refers to the clock time returned by the server,
T0 refers to the time at which request was sent by the client process,
T1 refers to the time at which response was received by the client process