0% found this document useful (0 votes)
14 views31 pages

Ds Chapter 5

The document discusses the concepts of synchronization in distributed systems, focusing on clock synchronization, logical clocks, mutual exclusion, and election algorithms. It explains various methods and algorithms for achieving synchronization among distributed nodes, including Cristian's Algorithm, Berkeley Algorithm, and Lamport's Logical Clock. Additionally, it covers mutual exclusion techniques and election algorithms like the Bully Algorithm and Ring Algorithm for coordinating processes in a distributed environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views31 pages

Ds Chapter 5

The document discusses the concepts of synchronization in distributed systems, focusing on clock synchronization, logical clocks, mutual exclusion, and election algorithms. It explains various methods and algorithms for achieving synchronization among distributed nodes, including Cristian's Algorithm, Berkeley Algorithm, and Lamport's Logical Clock. Additionally, it covers mutual exclusion techniques and election algorithms like the Bully Algorithm and Ring Algorithm for coordinating processes in a distributed environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Bahir Dar Institute of Technology

Faculty of Computing Network and Internet Chair

Introduction of Distributed System


Content
 Clock Synchronization
 Logical Clocks
 Mutual Exclusion
 Election algorithms
Chapter- Five
What is synchronization
 Synchronize means two items are adjusted to do the same thing.
 For example: when you synchronize two watches, you adjust
them so they show the same exact time.

 When you synchronize something on a computer, it means data


from one computer is transferred to another computer or device,
and vice versa.
 Then both computers or devices have the same exact data for
whatever program you are running.
Clock synchronization in distributed system

 Clock is an electronic device that counts oscillation in a crystal at


a particular frequency
 Clock synchronization involves aligning the clocks of computers
or nodes, enabling efficient data transfer, smooth
communication, and coordinated task execution
 Clock synchronization in distributed systems aims to establish a
reference for time across nodes.
Clock Synchronization cont….

In centralized systems, time can be unambiguously decided by a


system call
Ex. process A at time t1 gets the time, say tA, and process B at time t2,
where t1 < t2, gets the time, say tB,then tA is always less than tB
Is a mechanism to synchronization the time of all computers in
DS.
Achieving agreement on time in distributed systems is difficult.
Example
Physical Clock

 Device that indicates what time it is.


 Physical clocks are used to adjust the time of nodes.
 Each node in the system can share its local time with other nodes
in the system.
 A distributed system can have many physical clocks, and in
general they will not agree.
Physical Clocks Cont…

 Is it possible to synchronize all clocks in a distributed system?


 No; even if all computers initially start at the same time, they will
get out of synch after some time due to crystals in different
computers running at different frequencies, a phenomenon
called clock skew.
 Time difference between 2 computers is know as drift
 Clock drift over the time is know as Clock skew
Universal Coordinated Time

 all computers are generally synchronized to a standard time


called UTC
 UTC is the primary time standard by which the world regulates
clock and time .
 It is available via radio signal, Telephone line, satellite(GPS)
Clock Synchronization Algorithms

 Consider the following two situations:


one machine has a receiver of UTC time, then how do we
synchronize all other machines to it
no machine has a receiver, each machine keeps track of its own
time, then how to synchronize them
 For such and other situations many algorithms have been
proposed
Cristian’s Algorithm
 It is the simple algorithm for selecting time, It issue remote
procedure call to time server and obtain the time.
 A machine send a request to the time sever in d/2 second
when d is the max differ b/n a clock & UTC.
 The time server send a reply with current UTC where
receives the request.

Figure : Cristian’s Algorithm Working


Berkeley Algorithm
 Aims to synchronize clocks in a distributed system but takes an
average of all participating machines' clocks instead of relying
on just one central server.
 Suppose there are three machines: (a), (b), and (c).
Network Protocol Time(NTP)
Logical Clocks

 Keep track of each other’s events rather than maintaining


accurate(absolute) clock.
 To implementing a protocol on all machines within your
distributed system, so that the machines are able to maintain
consistent ordering of events within some virtual timespan.
 Distributed systems may have no physically synchronous
global clock, so a logical clock allows global ordering on events
from different processes in such systems.
Lamport’s Logical Clock

Lamport defined a relation called happens before


a  b read as “a happens before b”; means all processes agree that
first event a occurs, then event b occurs
this relation can be observed in two situations
if a and b are events in the same process, and a occurs before b,
then a  b is true
if a is the event of a message being sent by one process, and b is
the event of the message being received by another process, then
a  b is also true
Lamport’s Logical Clock………

 Happens before is a transitive relation


 if a  b and b  c, then a  c
 If two events, x and y, happen in different processes that do not
exchange messages, then both x  y and y  x are not true;
 These events are said to be concurrent;
 It means that nothing can be said about the order of these
events
 For every event a, we can assign a time value C(a) on which all
processes agree; if a  b, then C(a) < C(b)
Example

a)three processes, each with its own clock; the clocks run at
different rates
b)Lamport's algorithm corrects the clocks
The positioning of Lamport's logical clocks in distributed systems
Mutual Exclusion
 In a distributed system states that only one process is allowed to
execute the critical section (CS) at any given time.
 In distributed systems, since there is no shared memory, these
methods cannot be used.
 To prevent that such concurrent accesses corrupt the resource, or
make it inconsistent, solutions are needed to grant mutual
exclusive access by processes.
 how are critical regions and mutual exclusion implemented in
distributed systems?
 three algorithms: centralized, distributed, and token ring
A Centralized Algorithm
 A coordinator is appointed and is in charge of granting
permissions
 Three messages are required: request, grant, release.

a)process 1 asks the coordinator for permission to enter a critical


region; permission is granted
b)process 2 then asks permission to enter the same critical region;
the coordinator does not reply (could also send a no message; is
implementation dependent), but queues process 2; process 2 is
blocked
Example
A Distributed Algorithm

 When a process wants to enter a critical region it builds a


message (containing name of the critical region, its process
number, current time) and sends it to everyone including itself.
A Token Ring Algorithm
 Ring positions may be allocated in numerical order of network
addresses or some other means.
 It does not matter what the ordering is.
 All that matters is that each process knows who is next in line
after itself
Election Algorithms
 Many distributed algorithm need one process to act as a
coordinating.
 There are situations where one process must act as a coordinator,
initiator, or perform some special task
 Assume that
 each process has a unique number
 every process knows the process number of every other process,
but not the state of each process (which ones are currently
running and which ones are down)
 election algorithms attempt to locate the process with the highest
process number
 Types of Election Algorithm
 Bully algorithm
The Bully Algorithm
 Each process has a unique numerical ID.
 when a process (say P4) notices that the coordinator is no longer
responding to requests, it initiates an election as follows
 P4 sends an ELECTION message to all processes with higher
numbers (P5, P6, P7)
 if a process gets an ELECTION message from one of its lower-
numbered colleagues, it sends an OK message to the sender and
holds an election
1.if no one responds, P4 wins the election and becomes a
coordinator
2.if one of the higher-ups answers, this new process takes over
Example: Bully algorithm

a)Process 4 holds an election


b)Process 5 and 6 respond, telling 4 to stop
c)Now 5 and 6 each hold an election
d)Process 6 tells 5 to stop
e) Process 6 wins and tells everyone
 the last one will send a message to all processes telling them that
it is a boss
 if a process that was previously down comes back, it holds an
election
Ring Algorithm
 Another election algorithm is based on the use of a ring.
 Process priority is obtained by organizing processes into a
(logical) ring. Process with the highest priority should be
elected as Coordinator
Thank You!!!

You might also like