Module5 - Part 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Module 5:

Coordination
Contents
• Time and Global States
• Synchronizing physical clocks
• Logical time and logical clock
• Coordination and Agreement
• Distributed Mutual Exclusion
• Election algorithms
• Consensus and Related
problems.
SCOPE, VIT
Chennai
Time
• Time is an important and interesting issue.
– Time is a quantity often want to measure the
happening of
a certain event accurately. E.g. e-commerce
transaction time at merchant and bank’s
computers
– Algorithms depend upon clock synchronization. E.g.
use of timestamps to serialize transactions to
maintain data consistency. Order of events required.
• Synchronize local clock with an authoritative, external
source of time. Atomic oscillator clock is the most
accurate physical clock. International Atomic Time
and Coordinated Universal Time.

SCOPE, VIT
Chennai
Skew between computer
clocks in a distributed system

Netw ork
• Each node maintain a physical clock. However, they
tend to drift even after an accurate initial setting.
• Skew: the difference between the readings of any
two clocks.
• Clock drift: the crystal-based clock count time at
different rates. Oscillator has different frequency.
• Drift rate is usually used to measure the change in the offset per
unit of time. Ordinary quartz crystal clock, 1second per 11.6 days.

SCOPE, VIT
Chennai
Synchronizing Physical Clocks

• External synchronization:

• Synchronizes each clock in the distributed system with a


Coordinated Universal Time (UTC) source – clocks must be
within drift bound D of UTC.

• Ci is synchronized to a common standard.


• |S(t) –Ci(t)| <D, for i = 1,2,…N and for all real time t, namely
clock Ci are accurate to within the bound D. S is standard time.

SCOPE, VIT
Chennai
Synchronizing Physical Clocks
• Internal synchronization:
• Synchronizes the clocks in the distributed system with one another –
any two physical clocks must be within drift bound D of one another
• May drift from UTC but are synchronized together

• Faulty clock: does not stay within specified drift bound

• Ci is synchronized with one another to a known degree of


accuracy.
– |Ci(t) – Cj(t)| < D for i,j=1,2,…N, and for all real time t, namely,
clocks Ci agree with each other within the bound D.

SCOPE, VIT
Chennai
Simplest Case of Internal
Synchronization
• In a synchronous system, bounds exist for clock
drift rate, transmission delay and time for
computing of each step.
• One process sends the time t on it local clock to
the other in a message m. The receiver should
set its clock to t+Ttrans. It doesn’t matter whether
t is accurate or not
• Synchronous system: Ttrans could range from min to max. The
uncertainty is u=(max-min). If receiver set clock to be t+min or
t+max, the skew is as much as u. If receiver set the clock to be
t+(min+max)/2, the skew is at most u/2.
• Asynchronous system: no upper bound max. only lower bound.

SCOPE, VIT
Chennai
Clock synchronization using a
Time server
mr

mt
p Time server,S

• Cristian’s method: Time server, connected to a device


receiving signals from UTC. Upon request, the server S
supplies the time t according to its clock.
• The algorithm is probabilistic and can achieve synchronization
only if the observed round trip time are short compared with
required accuracy.

SCOPE, VIT
Chennai
Cristian’s algorithm
• P records round trip time Tround between sending and
receiving
• P sets local clock time to t + Tround /2
• Probabilistic method
• All processes (nodes) synchronize with clock server node
• Used for synchronizing nodes on a local intranet
• Variation called Berkeley algorithm
Cristian’s algorithm
• Suffers from the problem associated with
single server that single time server may
fail.
• Cristian suggested to use a group of
synchronized time servers. A client
multicast is request to all servers and use
only the first reply.

SCOPE, VIT
Chennai
Berkeley Algorithm
• Internal synchronization when developed for
collections of computers running Berkeley UNIX.
• A coordinator is chosen to act as the master.
• It periodically polls the other computers whose
clocks are to be synchronized, called slave.
• The slaves send back their clock values to it.
• The master estimate their local clock times by
observing the round-trip time similar to Cristian’s
method.
• It averages the values obtained including its own.

SCOPE, VIT
Chennai
Berkeley Algorithm
• Instead of sending the updated
current time back to other
computers, which further
introduce uncertainty of message
transmission, the master sends
the amount by
which each individual slave’s
clock should adjust.
SCOPE, VIT
Chennai
Berkeley Algorithm
• The master takes a fault-tolerant
average, namely a subset of
clocks is chosen that do not
differ from one another by more
than a specified bound.
• The algorithm eliminates readings
from faulty clocks. Such clocks
could have a adverse effect if an
ordinary average was taken.

SCOPE, VIT
Chennai
The Network Time Protocol
• Cristian’smethod and Berkeley algorithm are
primarily for Intranets.
• The Network Time Protocol(NTP) defines a
time service to distribute time information over
the Internet.
• Clients across the Internet to be synchronized accurately to UTC.
Statistical techniques
• Reliable service that can survive lengthy losses of connectivity.
Redundant servers and redundant paths between
servers.
• Clients resynchronized sufficiently frequently to offset the rates of
drift.
• Protection against interference with time services. Authentication
technique from claimed trusted sources

SCOPE, VIT
Chennai
The Network Time

Protocol
To provide a service enabling clients across the internet to be synchronized accurately to
UTC
– NTP employs statistical techniques for filtering of timing data and it discriminates
between the quality of timing data from different servers.
• To provide a reliable service that can survive lengthy losses of connectivity:
– There are redundant servers and redundant paths between servers; server can
reconfigure in case of failures.
• To enable clients to re-synchronize frequently to offset the rates of drift found in most
computers; this service will scale to large number of clients and servers
• To provide protection against interference with the time service whether accidental or
malicious
• Hierarchical structure for the time servers: primary and secondary at different strata.
• NTP servers synchronize with each other in one of three modes: multicast, procedure-call,
symmetric-mode in the order of accuracy
• All messages use UDP and so deliver unreliable
• Messages between a pair is discusses next
• Each message carries three time stamps: sent time, recd time, time of this message.
An example synchronization subnet in an NTP
implementation
1

2 2

3 3 3

Note: Arrows denote synchronization control, numbers denotestrata.

Hierarchical structure called synchronization subnet


• Primary server: connected directly to a time source.
•Secondary servers are synchronized with primary server.
• Third servers are synchronized with secondary servers.
Such subnet can reconfigure as servers become unreachable or failures
occur.
SCOPE, VIT
Chennai
The Network Time Protocol Server

• NTP servers synchronize in one of three modes:


– 1. Multicast mode: for high-speed LAN. One or
more servers periodically multicasts the time to
servers connected by LAN, which set their times
assuming small delay. Achieve low accuracy.
– 2. Procedure call: similar to Cristian’s algorithm.
One server receives request, replying with its
timestamp. Higher accuracy than multicast or
multicast is not supported.
– 3. Symmetric mode: used by servers that supply time
in LAN and by higher level of synchronization
subnet. Highest accuracy. A pair of servers operating
in symmetric mode exchange messages bearing
timing information.

SCOPE, VIT
Chennai
Messages exchanged
between a pair of NTP peers

Server B Ti-2 Ti-1


Time

m m'

Time
Server A Ti- 3 Ti

SCOPE, VIT
Chennai
LOGICAL CLOCK

• A logical clock is a mechanism for capturing chronological and causal


relationships in a distributed system. Distributed systems may have no
physically synchronous global clock, so a logical clock allows global
ordering on events from different processes in such systems.

• Note- chronological: the relation of a serial to its predecessors and successors


• Casual-Causation indicates that one event is the result of the occurrence of the other event;
i.e. there is a causal relationship between the two events.
LOGICAL CLOCK USE
AND ALGORITHMS

• Logical clocks are useful in computation analysis, distributed algorithm design,


individual event tracking, and exploring computational progress.
• Some noteworthy logical clock algorithms are:
• Lamport’s timestamps, which are monotonically increasing software counters.
• Vector clocks, that allow for partial ordering of events in a distributed system.

Timestamp-a digital record of the time of occurrence of a particular event.


LAMPORT’S CLOCK

• Lamport’s clocks are a simple technique used for determining the order of
events in a distributed system.

• This clock was proposed by Leslie Lamport , a Lamport clock maintains order
of operations by incrementing a counter contained in the events

• By simply adding a counter value to events as they are received and


incrementing this value based on the last seen value,

• Lamport clocks provide a partial ordering of events – specifically “happened-


before” ordering.
LAMPORT’S ALGORITHM RULES:

• A process increments its counter before each event in that process;


• When a process sends a message, it includes its counter value with the message;
• On receiving a message, the counter of the recipient is updated, if necessary, to the greater
of its current counter and the timestamp in the received message. The counter is then

incremented by 1 before the message is considered received.


The algorithm for sending:
• time = time+1;
• time_stamp = time;
• send(message, time_stamp);
The algorithm for reciving:
• (message, time_stamp) = receive();
• time = max(time_stamp,time)+1;
VECTOR CLOCK

• A vector clock is an algorithm for generating a partial ordering of events in a


distributed system and detecting causality violations. Just as in Lamport
timestamps, interprocess messages contain the state of the sending
process'slogical clock.
VECTOR CLOCKALGORITHM

• Initially, all vectors [0,0,…,0]

• For event on process i, increment own ci

• Label message sent with local vector

• When process j receives message with vector [d1, d2, …, dn]:


• Set local each local entry k to max(ck, dk)
• Increment value of cj
IMPORTANT POINTS

• Physical Clocks
• Can keep closely synchronized, but never perfect
• Logical Clocks
• Encode causality relationship

• Lamport’s clocks provide only one-way encoding

• Vector clocks provide exact causality information

• Causality – If a b then event a can affect event b

• Partial Ordering – Causal events are sequenced

• Total Ordering – All events are sequenced

You might also like