Distributed system module 3
Distributed system module 3
Department of
Computer Science & Engineering
www.cambridge.edu.in
Clocks
• The instantaneous difference between the readings of any two
clocks is called their skew.
CiTech, BANGALORE
Coordinated Universal Time
• Computer clocks can be synchronized to external sources of
highly accurate time.
• Coordinated Universal Time – abbreviated as UTC (from the
French equivalent) – is an international standard for
timekeeping.
• UTC signals are synchronized and broadcast regularly from
land based radio stations and satellites covering many parts of
the world.
CiTech, BANGALORE
Synchronizing Physical clocks
In order to know at what time of day events occur at the
processes in our distributed system – for example, for
accountancy purposes – it is necessary to synchronize the
processes’ clocks.
External synchronization: means that all computers in the
system are synchronized with an external source of time (e.g., a
UTC signal). Clocks Ci are synchronized with one another to a
known degree of accuracy.
Internal synchronization: means that all computers in the system
are synchronized with one another, but the time is not
necessarily accurate with respect to UTC.
CiTech, BANGALORE
Synchronization in a synchronous system
• Internal synchronization between two processes in a synchronous
distributed system.
• One process sends the time t on its local clock to the other in a
message m.
• In principle, the receiving process could set its clock to the time t +
Ttrans , where Ttrans is the time taken to transmit m between them.
The two clocks would then agree (since the aim is internal
synchronization, it does not matter whether the sending process’s
clock is accurate).
CiTech, BANGALORE
Cristian’s method for synchronizing clocks
CiTech, BANGALORE
Cristian’s method for synchronizing clocks
Algorithm:
1) The process on the client machine sends the request for fetching clock
time(time at the server) to the Clock Server at time T0 .
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 synchronized client clock time using the formula given below.
Tclient=Tserver+(T1-T0)/2
CiTech, BANGALORE
Cristian’s method for synchronizing clocks
• Cristian’s method suffers from the problem associated with all services
implemented by a single server:
that the single time server might fail and thus render synchronization
temporarily impossible.
• Cristian suggested, for this reason, that time should be provided by a group of
synchronized time servers, each with a receiver for UTC time signals.
• For example, a client could multicast its request to all servers and use only the
first reply obtained.
• Note that a faulty time server that replied with spurious time values, or an
imposter time server that replied with deliberately incorrect times, could wreak
havoc in a computer system.
CiTech, BANGALORE
The Berkeley algorithm
• Describe an algorithm for internal synchronization that they
developed for collections of computers running Berkeley UNIX.
• In it, a coordinator computer is chosen to act as the master.
Unlike in Cristian’s protocol, this computer periodically polls the
other computers whose clocks are to be synchronized, called
slaves.
• The slaves send back their clock values to it. The master
estimates their local clock times by observing the round-trip
times (similarly to Cristian’s technique), and it averages the
values obtained.
CiTech, BANGALORE
The Network Time Protocol
CiTech, BANGALORE
The Network Time Protocol
CiTech, BANGALORE
The Network Time Protocol
CiTech, BANGALORE
Logical Time and Logical clocks
CiTech, BANGALORE
Logical Time and Logical clocks
CiTech, BANGALORE
Logical Time and Logical clocks
CiTech, BANGALORE
Logical Time and Logical clocks
CiTech, BANGALORE
Logical Time and Logical clocks
CiTech, BANGALORE
Logical clocks
• Lamport [1978] invented a simple mechanism by which the
happened before ordering can be captured numerically, called a
logical clock.
• A Lamport logical clock is a monotonically increasing software
counter, whose value need bear no particular relationship to any
physical clock.
• Each process pi keeps its own logical clock, Li , which it uses to
apply so-called Lamport timestamps to events. We denote the
timestamp of event e at pi by Li(e) , and by L(e) at whatever process
it occurred at.
CiTech, BANGALORE
Logical clocks
• To capture the happened-before relation → processes update their
logical clocks and transmit the values of their logical clocks in
messages as follows:
LC1: Li is incremented before each event is issued at process pi :
Li := Li + 1.
LC2: (a) When a process pi sends a message m, it piggybacks on m
the value t = Li.
(b) On receiving (m, t), a process pj ,computes Lj := max( Lj ,t)
and then applies LC1 before timestamping the event
receive(m).
CiTech, BANGALORE
Totally ordered logical clocks
• If e is an event occurring at pi with local timestamp Ti , and e is an
event occurring at pj with local timestamp Tj , we define the global
logical timestamps for these events to be (Ti,i) and (Tj,j) ,
respectively.
• And we define (Ti, i) < (Tj, j) if and only if either Ti < Tj , or Ti = Tj and
i< j. This ordering has no general physical significance (because
process identifiers are arbitrary), but it is sometimes useful.
Lamport used it, for example, to order the entry of processes to a
critical section.
CiTech, BANGALORE
Vector clocks
• Mattern [1989] and Fidge [1991] developed vector clocks to
overcome the shortcoming of Lamport’s clocks: the fact that from
L(e)< L(e’) we cannot conclude that e→ e’.
• A vector clock for a system of N processes is an array of N integers.
• Each process keeps its own vector clock, Vi , which it uses to
timestamp local events.
CiTech, BANGALORE
Vector clocks
• Like Lamport timestamps, processes piggyback vector timestamps
on the messages they send to one another, and there are simple
rules for updating the clocks:
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.
CiTech, BANGALORE
Logical Time and Logical clocks
CiTech, BANGALORE
Vector clocks
CiTech, BANGALORE
Global States
CiTech, BANGALORE
Distributed garbage collection
CiTech, BANGALORE
Distributed deadlock detection
CiTech, BANGALORE
The ‘snapshot’ algorithm of Chandy and
Lamport
The algorithm assumes that:
• Neither channels nor processes fail – communication is reliable so
that every message sent is eventually received intact, exactly once.
• Channels are unidirectional and provide FIFO-ordered message
delivery.
• The graph of processes and channels is strongly connected (there is
a path between any two processes).
• Any process may initiate a global snapshot at any time.
• The processes may continue their execution and send and receive
normal messages while the snapshot takes place.
Example