Distributed Computing UNIT-3
Distributed Computing UNIT-3
Syllabus
Distributed Mutual
exclusion Algorithms
Ricart-Agrawala 's Algorithm -
:
Introduction - Preliminaries -
Lamport's algorithm
Token-Based Algorithms -
Deadlock Detection in
of Deadlocks -
Distributed Systems : Suzuki-Kasami's Broadcast
Introduction - System Model -
Chandy-Misra-HaasAlgorithm for the
Algorithm
Preliminaries -Models
modelAND andOR Model.
Contents
3.1 Distributed Mutual Exclusion Algorithms :Introduction
3.2 Preliminaries
(3 - 1)
3-2 Distributed Mutex and Deadlock
DistributedComputing
•n a distributed systemn neither shared variables nor a local kernel can be used
has be
in
:
Entry section The code executed in preparation for entering the critical section
• Exit section : The code executed upon leaving the critical section
3.2 Preliminaries
3.2.1 System Model
. Distributed mutual
delays and incomplete knowledge
exclusion algorithms must
of the system
deal
state.
with unpredictable message
System model
The system consists of N sites, SN.
S1,S2,..., We assume that a single process is
• At any instant, a site may have several requests` for critical section. A site queueS
1. Requesting CS
2. Executing CS
3. Neither requesting nor executing requests for CS
.
also maintain
information. different types Of
2. Token based:
Permission passes around from one
site to another. Site
is
allowed enter its critical section if it
to
possesses the token and it continues to
hold the token until the
execution of the critical section is
over.
2. Freedom from starvation : A site should not wait indefinitely while other sites
repeatedly access the CS.
3. Strict fairness :
Requests are served in the (logical) order in which they arrive.
4. Fault tolerance : An algorithm should be able to detect and recover from failures.
2. Synchronization delay : After a site leaves the CS, it is the time required before
the next site enters the CS.
3. Response time :The time interval a request waits for its CS execution to be over
after its request messages have been sent out.
4. System throughput :The rate at which the system executes requests for the CS.
execution time.
Time
Synchronization delay
the system.
• Performance may depend on whether load is low or high. Best case, worst case,
• If the load is high then there is always pending requests for mutual exclusion.
The site
enters the The site
CS request Its request CS exits the
arrive message CS
sent out
CS execution
time Time
Response time
Each process freely and equally competes for the right to use the shared resource;
requests are arbitrated by a central control site or by distributed agreement.
Permission from all processes.
• Let Ri be the request, set of site Si, i.e. the set of sites from which Si needs
permission when it wants to enter CS.
• Each site Si keeps a request queue of requests ordered by logical timestamp
. When Sj
places the
receives
REQUEST
the REQUEST(Ci,
in the
i)
request queue.
it returns a timestamped REPLY to S1 and
sites.
:Si has received a message with a timestamp larger than (Ci, i) from all other
Releasing the CS
and send RELEASE to all sites in the
Remove (Ci,i) from the request queue, a
request set.
When Sj receives RELEASE, it removes the request from the request queue.
Correctness
[L1, L2] hold in both processes
• Assume two processes S1, S2 in CS simultaneously.
timestamps from all others, their
i.e. both have received messages with larger
of site Si 's
its own REQUEST message with timestamp higher than the timestamp
to site Si .
request, then site Sjneed not send a REPLY message
because when site Si receives site Sj 's request with timestamp higher than
• This is
its own. it can conclude that site Sj does not have any smaller timestamp request
for section.
Step 1 : Sites S1 and S2 are making request critical
Logical timestamp=2
(2, 1) Process=1
|2,1
Timestamp = 1 (1,2)/
Process =2
1,2
Request
(2,1)
S1
2,1|/1,2
2,1
(1,2)/
S2
|1,2|1,2|
|2,1
S3
1,2 1,2
2,1 S2 enters
critical
section
TECHNICAL PUBLICATIONS
an
up-thrust for
knowledge
Mutex andDeadlock
3-7 Distributed
Computing
Dstibuted
(2,1)
S1
(1.2)/
S2
1,2||1,2
2,1
Release
S3
1,2| |1,2| S2 leaves
|2,1 critical section
S1enters
critical section
|
(2,1)
S1
2,11,2 |2.1
|2,1
S2(1.2/
1,2||1,2
2,1
S3
1,2 |1,2 2,1|
|2,1
Lamport evaluation
• Deadlock :processes do not wait forever
which is fair
• Fairness : CS requests are granted in order of logical clock,
• Fault tolerance :
Performance
• Itis assumed that all processes keep a logical clock which is updated according to
the clock rules.
Case 3: The receiver also wants to enter the critical section and has sent its request. n
this case, the receiver compares the timestamp
message with the one thatin the received
it has sent out. The
earliest timestamp wins. If the
receiver is the loser, it sends a
(OK)to sender. Ifthe receiver has the earlier timestamp, then it is reply
the winner and does
not reply. Instead, it adds the request to its queue.
When a site
5. Sj receivesthe RELEASE() message from site, it sends a REPLY)
message to the next site waiting in the gueue and deletes that entry from the
queue. l the queue is empty, then the site updates its state to reflect that the site
has not sent out any
REPLY message.
:
Optimization
Once site Si has received a REPLY message from a site Si, the authorization
implicit in this message remains valid Sisends a REPLY message
. Fig. 3.4.1 shows operation of Ricart-Agrawala algorithm.
until to Sj.
(2,1)
S1
Reply
s2 (1.2)/
2,1
S3
S2 enters
critical seotion
(2.1)
S1
(1.2)
S2
|2,1|
S3
S2 leaves
critical section
S1 enters
critical section
S1 (2.1)
(1,2)
S2
2.11
S3
•A site can access the lock (critical section) if it has a token. Every process
maintains a sequence number (requestid).
Logical token representing the access right to the shared resource is passed in a
regulated fashion among the processes; whoever holds the token is allowed to
instead of a timestamp.
Algorithm :
Requesting CS :
1. Site Si increments its sequence number, RNi[i] and sends a REQUEST( ,Sn) to all
Executing CS:
3. Site Si executes CS when it has received the token
Releasing CS:
4. LN[i]<- Rn[il[i]
Performance :
:
2. Synchronizationdelay 0 orT. No message is needed or the synchronizationdelay
is zero if a site holds the idle token at the time of its request.
University Question
AU :Dec.-22, Marks 15
• Processes with a globally unique identifier run on the distributed system. They
make resource requests to a controller. There is one controller per site.
t the resource is local, the process makes a request of the local controller.
following situation :
holds a lock on resource X.
• However, the deadlock will not be discovered at either site unless they exchange
information via some detection scheme.
2. No pre-emption
3. Hold and wait
4. Circularwait
1. Mutual exclusion Only one process may use a resource at a time. Once a process
has been allocated particular resource, it has exclusive
a
use of the resource, No
other process can use a resource while it is allocated to a process.
2. Hold and wait : A process may hold a resource at the same time it requests
another one.
: processes
3.6.1).
explicit action of the process, rather than by the action of an external authority.)
A deadlock is possible only if all four of these conditions simultaneously hold in the
University Question
1. Discuss with suitable example to show that a deadlock cannot occur if any one of the four
conditions is absent.
AU:May-22,Marks 13
graph are processes and resources of a system, and the edges of the graph depict
assignments or pending requests.
R1
R4
P4
Assignment
edge
R2 P3 Request edge
R3
. A system is deadlocked
some resource.
First method :
• Prevent the hold-and-wait condition by requiring the process to acquire all needed
resources before starting execution.
Disadvantages :
l Inefficient use of resources.
2 Reduced concurrency.
Third method :
Use of time-stamps
• Example : Use time-stamps for transactions to a database -Each transaction has
the time-stamp of its creation.
the resource, then the older process (that wants theresource) waits. If an older
process is holding the resource, the younger process (that wants the resource) kill
itself. This forces the resource utilization graph to be directed from older to
kill T2 (die');
Waits
halt T2 (wait):
.die
i
wait
wourd-
TECHNICALPUBLICATIONS - an up-thrust for knowledge
Computing
istnbuted
3- 17 Mutex and Deadlock
Distributed
Wants resource
Holds resource
=7)
A(t
B(t =11)
Preempts
B(t = 11)
A(t =7)
Waits
• Disadvantages
l Every site has to maintain global state of system (extensive overhead in storage
and communication).
but global state
2Different sites may determine (concurrently) that state is safe,
normal operation.
and resolution algorithms:
• Requirements for the deadlock detection
Detection
time
K The algorithm must detect all existing deadlock in finite
(phantom)deadlock.
2 The algorithm should not report non-existent
• In the single resource model, a process can have at most one outstanding request
for only one unit of a resource.
Since the maximum out-degree of a node in a WFG for the single resource model
can be 1, the presence of a cycle in the WFG shall indicate that there is a
deadlock.
Set of deadlocked processes, where each process waits for a resource held by
another process (e.g. data object in a database, I/0 resource on a server).
Uses AND condition.
• AND condition : A process that requires resources for execution carn proceed
when it has acquired all those resources.
The condition for deadlock in a system using the AND condition is the existence
of a cycle.
Since in the single-resource model, a process can have most one outstanding
at
request, the AND model is more general than the single-resource model
• Uses OR condition.
• OR condition :A
process that requires resources for execution can proceed when
it has acquired at least one of those resources.
The condition for deadlock in a system using the
OR condition is the existence of
a knot. A knot (K) consists of a set of nodes
such that for every node a in K, all
nodes in K and only the nodes in K are reachable from
node
a.
• In the OR model, the presence of a knot indicates a deadlock.
of
the resOurce request. For example, in the AND-OR model, a request for multiple
can be of the form x and
resources (y or z).
Question
University
AU: Dec.-22,.Marks 13
It is also considered
. This considered an edge-chasing, probe-based algorithm.
is
and
receive this probe message.
3. The id of the process that should
is also waiting for
checks to see if
message, it it
is a cycle in the
system and thus, deadlock.
knows there
P (P,.P.P3)i
\P,.P3. Pe
P, P2
Site 2
Site 1
Advantages :
a) It is easy to implement.
b) Each probe message is of fixed length.
e) There isno need to construct a graph, nor to pass graph information to other
sites.
to a
computation
diffusion computation
:query(i, j, k) and
initiated by a
process P and are being sent from process P,to process Pk
A blocked process initiates deadlock detection by sending query messages
processes in to all
its dependent set. If an active process receives a query or reply
message, it discards it.
it
query.Otherwise, it
Process Pk maintains a discards the query.
boolean variable waitk (i)
that denotes the
been continuously fact that it nas
blocked since it received
the last engaging
P.. When a query from process
blocked process P, receives
a reply(i, i, k) message,
num, (i) only if waity (i) holds. it decrements
.A processsends a
reply message in response
to an engaging
has received a reply to query only after it
every query message it
had sent out for this
query. The initiator process engagin8
detects a deadlock
when it receives reply messages to
all the query
messages it had sent out.
message toall other site to get their permission to enter critical section. A site send a
REPLY message to other site to give its permission to enter the critical section.
0.6
Which are the three basic approaches for implementing distributed mutual
exclusion ?
distributed mutual
Ans. :There are three basic approaches for implementing exclusion
algorithmsare
algorithms
a
Freedom from deadlocks b. Freedom from starvation
C. Strict fairness d. Fault tolerance
Q.8
What are the performance metric of mutual exclusion algorithm ?
Ans. : Performances metric are message complexity, synchronization delay, response
time and system
throughput.
Q.9 What is response time ?
Ans. : The time interval a request waits for its CS execution to be over after its request
messages have been sent out.
Q.10 Which are the criteria for evaluating performance of algorithms for
exclusion ? mutual
TECHNICAL PUBLICATIONS
- an up-thrust for
knowledge
Distributed Computing 3-23 Distributed Mutex and Deadlock
graph are processes and resources of a system, and the edges of the graph depict
assignmentsor pending requests. A pending request is represented by a request edge
directed from the node of a requesting process to the node of the requested resource.
Ans. : A non-preemptive approach. If a younger process is using the resource, then the
older process waits. If an older process is holding the resource, the younger process
kills itself. This forces the resource utilization graph to be directed from older to
younger processes, making cycles impossible. This algorithm is known as the wait-die
algorithm.
Ans.: There are three strategies for handling deadlocks, viz., deadlock prevention,
deadlockavoidance, and deadlock detection.
The resource manager can grant the request if the resources are available.
Q.17 Define deadlock detection in distributed systems.