SlideShare a Scribd company logo
1 of 38
Download to read offline
Lecture 4 and 5: Mutual Execution and Election
Algorithms
Distributed and Cloud Computing
Fall 2021
Slides adopted from the instructional material of the textbook
Distributed Systems: Principles and Paradigms by Andrew S. Tanenbaum, Maarten van Steen.
1
Contents
• Distributed system concepts
• Distributed system design goals
• Architectures
• Coordination in Distributed Systems:
• Logical Clocks
• Lamport’s Logical Clocks
• Vector Clocks
• Mutual Exclusion
• Election Algorithms
2
Coordination:
 Mutual Exclusion
 Election Algorithms
Reading Assignment Mutual Exclusion and Election
Algorithms: Text book 6.3 and 6.4
3
Mutual Exclusion
 A centralized algorithm
 Permission-based
 A distributed algorithm
 Ricart & Agrawala
 A token-ring algorithm
 A decentralized mutual exclusion
4
Overview of Mutual exclusion
Problem
A number of processes in a distributed system want exclusive access to some
resource.
Basic solutions
Permission-based: A process wanting to enter its critical section, or access a
resource, needs permission from other processes.
Token-based: A token is passed between processes. The one who has the
token may proceed in its critical section, or pass it on when not
interested.
5
Requirements
1. Correctness/Safety:
• At most one process holds the lock/enter C.S. at a time
2. Fairness:
• Any process that makes a request must be granted lock
• Implies that system must be deadlock-free
• Assumes that no process will hold onto a lock indefinitely
• Eventual fairness: Waiting process will not be excluded
forever
• Bounded fairness: Waiting process will get lock within
some bounded number of cycles (typically n)
6
Other Requirements
• Low message overhead
• No bottlenecks
• Tolerate out-of-order messages
• Allow processes to join protocol or to drop out
• Tolerate failed processes
• Tolerate dropped messages
7
Mutual Exclusion
A Centralized Algorithm (1)
@ Client  Acquire:
Send (Request, i) to coordinator
Wait for reply
@ Server:
while true:
m = Receive()
If m == (Request, i):
If Available():
Send (Grant) to i
8
Mutual Exclusion
A Centralized Algorithm (2)
@ Server:
while true:
m = Receive()
If m == (Request, i):
If Available():
Send (Grant) to I
else:
Add i to Q
9
Mutual Exclusion
A Centralized Algorithm (3)
@ Server:
while true:
m = Receive()
If m == (Request, i):
If Available():
Send (Grant) to I
else:
Add i to Q
If m == (Release)&&!empty(Q):
Remove ID j from Q
Send (Grant) to j
@ Client  Release:
Send (Release) to coordinator
10
Mutual Exclusion
A Centralized Algorithm (4)
• Correctness:
• Clearly safe
• Fairness depends on queuing policy.
• E.g., if always gave priority to lowest process ID, then
processes 1 & 2 lock out 3
• Performance
• "cycle" is a complete round of the protocol with one process i
entering its critical section and then exiting.
• 3 messages per cycle (1 request, 1 grant, 1 release)
• Lock server creates bottleneck
• Issues
• What happens when coordinator crashes?
• What happens when it reboots?
11
Permission-based, centralized
Coordinator
Queueis
empty
Simply use a coordinator
P0 P1 P2
Request OK
C
No reply
P0 P1
Request
P2
C
2
Release
OK
P0
P1
P2
C
(a) (b) (c)
(a) Process P1 asks the coordinator for permission to access a shared
resource. Permission is granted.
(b) Process P2 then asks permission to access the same resource. The
coordinator does not reply.
(c) When P1 releases the resource, it tells the coordinator, which then replies
to P2.
12
Ricart & Agrawala, Distributed
The same as Lamport except that acknowledgments are not sent
Return a response to a request only when:
The receiving process has no interest in the shared resource; or
The receiving process is waiting for the resource, but has lower priority
(known through comparison of timestamps).
In all other cases, reply is deferred, implying some more local administration.
13
A Distributed Algorithm 3
(Ricart & Agrawala)
• Also relies on Lamport totally ordered clocks.
• When node i wants to enter C.S., it sends time-
stamped request to all other nodes. These other
nodes reply (eventually). When i receives n-1
replies, then can enter C.S.
• Trick: Node j having earlier request doesn't reply
to i until after it has completed its C.S.
14
A Distributed Algorithm
Three different cases:
1.If the receiver is not accessing the resource and does not
want to access it, it sends back an OK message to the
sender.
2.If the receiver already has access to the resource, it simply
does not reply. Instead, it queues the request.
3.If the receiver wants to access the resource as well but has
not yet done so, it compares the timestamp of the incoming
message with the one contained in the message that it has
sent everyone. The lowest one wins.
15
A Distributed Algorithm
• Two processes (0 and 2) want to access a
shared resource at the same moment.
16
A Distributed Algorithm
• Process 0 has the lowest timestamp, so it wins.
17
A Distributed Algorithm (4)
• When process 0 is done, it sends an OK also, so
2 can now go ahead.
18
Example with three processes
0
1 2
8
8
8 12
12
12
0
1 2
OK OK
OK
Accesses
resource
0
1 2
OK
Accesses
resource
(a) (b) (c)
(a) Two processes want to access a shared resource at the same moment.
(b) P0 has the lowest timestamp, so it wins.
(c) When process P0 is done, it sends an OK also, so P2 can now go ahead.
Ricart & Agrawala, Distributed cont..
19
Performance
• Each cycle involves 2(n-1) messages
• n-1 requests by I
• n-1 replies to I
• Issues
• What if node fails?
• How is the performance compared to centralized?
20
Token ring algorithm
Essence
Organize processes in a logical ring, and let a token be passed between them.
The one that holds the token is allowed to enter the critical region (if it wants
to).
An overlay network constructed as a logical ring with a circulating token
0 1 2 3
4
5
6
7
T
oken
21
A Token Ring Algorithm
• Organize the processes involved into a logical ring
• One token at any time  passed from node to
node along ring
22
A Token Ring Algorithm
• Correctness:
• Clearly safe: Only one process can hold token
• Fairness:
• Will pass around ring at most once before getting
access.
• Performance:
• Each cycle requires between 1 - ∞ messages
• Latency of protocol between 0 & n-1
• Issues
• Lost token
23
Decentralized mutual exclusion
Principle
Assume every resource is replicated N times, with each replica having its own
coordinator ⇒ access requires a majority vote from m > N/2 coordinators. A
coordinator always responds immediately to a request.
Assumption
When a coordinator crashes, it will recover quickly, but will have forgotten about
permissions it had granted.
24
Decentralized mutual exclusion
25
Decentralized mutual exclusion
26
Mutual exclusion: comparison
27
Election Algorithms
 The bully algorithm
 The ring algorithm
28
Election algorithms
Principle
An algorithm requires that some process acts as a coordinator. The question is
how to select this special process dynamically.
Note
In many systems the coordinator is chosen by hand (e.g. file servers). This
leads to centralized solutions ⇒ single point of failure.
29
Election algorithms
Principle
An algorithm requires that some process acts as a coordinator. The question is
how to select this special process dynamically.
Note
In many systems the coordinator is chosen by hand (e.g. file servers). This
leads to centralized solutions ⇒ single point of failure.
Teasers
1
2
If a coordinator is chosen dynamically, to what extent can we speak about
a centralized or distributed solution?
Is a fully distributed solution, i.e. one without a coordinator, always more
robust than any centralized/coordinated solution?
30
Basic Assumptions: Bullying
All processes have unique id’s
All processes know id’s of all processes in the system (but not if they are
up or down)
Election means identifying the process with the highest id that is up
31
Election by bullying: The Bully Alg.
Principle
Consider N processes {P0 ,...,PN−1} and let id (Pk ) = k . When a process Pk
notices that the coordinator is no longer responding to requests, it initiates an
election:
1
2
3
Pk sends an ELECTION message to all processes with higher identifiers:
Pk+1,Pk+2,...,PN−1.
If no one responds, Pk wins the election and becomes coordinator.
If one of the higher-ups answers, it takes over and Pk ’s job is done.
32
The Bully Algorithm (1)
• The bully election algorithm. (a) Process 4 holds an
election. (b) Processes 5 and 6 respond, telling 4 to
stop. (c) Now 5 and 6 each hold an election.
33
The Bully Algorithm (2)
• The bully election algorithm. (d) Process 6 tells 5
to stop. (e) Process 6 wins and tells everyone.
34
Election by bullying
The bully election algorithm
Election
1
2
4
0
5
6
3
7
OK
1
2
4
0
5
6
3
7
Election
1
2
4
0
5
6
3
7
OK
1
2
4
0
5
6
3
7
Coordinator
1
2
4
0
5
6
3
7
35
Election in a ring: The ring algorithm
Principle
Process priority is obtained by organizing processes into a (logical) ring.
Process with the highest priority should be elected as coordinator.
Any process can start an election by sending an election message to its
successor. If a successor is down, the message is passed on to the next
successor.
If a message is passed on, the sender adds itself to the list. When it gets
back to the initiator, everyone had a chance to make its presence known.
The initiator sends a coordinator message around the ring containing a
list of all living processes. The one with the highest priority is elected as
coordinator.
36
Election in a ring
Election algorithm using a ring
1 2 3 4
5
6
7
0
[3]
[3,4]
[3,4,5]
[3,4,5,6]
[3,4,5,6,0]
[3,4,5,6,0,1] [3,4,5,6,0,1,2]
[6]
[6,0]
[6,0,1] [6,0,1,2] [6,0,1,2,3]
[6,0,1,2,3,4]
[6,0,1,2,3,4,5]
The solid line shows the election messages initiated by P6
The dashed one the messages by P3
37
Summary
 Mutual Exclusion
 A centralized algorithm
 Permission-based
 A distributed algorithm
 Ricart & Agrawala
 A token-ring algorithm
 A decentralized mutual exclusion
 Election Algorithms
 The bully Algorithm
 Ring Algorithm
Reading Assignment Mutual Exclusion and Election Algorithms
Text book 6.3 and 6.4
38

More Related Content

Similar to DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf

Mutual-Exclusion Algorithm.ppt
Mutual-Exclusion Algorithm.pptMutual-Exclusion Algorithm.ppt
Mutual-Exclusion Algorithm.pptShikhaManrai1
 
Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...Govt. P.G. College Dharamshala
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Synchronization in Distributed Systems.pptx
Synchronization in Distributed Systems.pptxSynchronization in Distributed Systems.pptx
Synchronization in Distributed Systems.pptxRichardMathengeSPASP
 
Chapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationChapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationWayne Jones Jnr
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
Leader Election Approach: A Comparison and Survey
Leader Election Approach: A Comparison and SurveyLeader Election Approach: A Comparison and Survey
Leader Election Approach: A Comparison and SurveyEditor Jacotech
 
Leader election approach a comparison and survey
Leader election approach a comparison and surveyLeader election approach a comparison and survey
Leader election approach a comparison and surveyEditor Jacotech
 
Mutual Exclusion in Distributed Memory Systems
Mutual Exclusion in Distributed Memory SystemsMutual Exclusion in Distributed Memory Systems
Mutual Exclusion in Distributed Memory SystemsDilum Bandara
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Sri Prasanna
 
Synchronization
SynchronizationSynchronization
SynchronizationSara shall
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OSC.U
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...Mushfekur Rahman
 
Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess CommunicationDilum Bandara
 
Comparative Study of Mutual Exclusion Algorithms in Distributed Systems
Comparative Study of Mutual Exclusion Algorithms in Distributed SystemsComparative Study of Mutual Exclusion Algorithms in Distributed Systems
Comparative Study of Mutual Exclusion Algorithms in Distributed SystemsIJERA Editor
 

Similar to DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf (20)

Mutual-Exclusion Algorithm.ppt
Mutual-Exclusion Algorithm.pptMutual-Exclusion Algorithm.ppt
Mutual-Exclusion Algorithm.ppt
 
Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Synchronization in Distributed Systems.pptx
Synchronization in Distributed Systems.pptxSynchronization in Distributed Systems.pptx
Synchronization in Distributed Systems.pptx
 
Chapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationChapter 18 - Distributed Coordination
Chapter 18 - Distributed Coordination
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Leader Election Approach: A Comparison and Survey
Leader Election Approach: A Comparison and SurveyLeader Election Approach: A Comparison and Survey
Leader Election Approach: A Comparison and Survey
 
Leader election approach a comparison and survey
Leader election approach a comparison and surveyLeader election approach a comparison and survey
Leader election approach a comparison and survey
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
Mutual Exclusion in Distributed Memory Systems
Mutual Exclusion in Distributed Memory SystemsMutual Exclusion in Distributed Memory Systems
Mutual Exclusion in Distributed Memory Systems
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OS
 
OSCh17
OSCh17OSCh17
OSCh17
 
OS_Ch17
OS_Ch17OS_Ch17
OS_Ch17
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
 
Chapter00000000
Chapter00000000Chapter00000000
Chapter00000000
 
Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess Communication
 
Comparative Study of Mutual Exclusion Algorithms in Distributed Systems
Comparative Study of Mutual Exclusion Algorithms in Distributed SystemsComparative Study of Mutual Exclusion Algorithms in Distributed Systems
Comparative Study of Mutual Exclusion Algorithms in Distributed Systems
 

More from LegesseSamuel

WachemoUniversity_Cryptography_and_Network_Security.pdf
WachemoUniversity_Cryptography_and_Network_Security.pdfWachemoUniversity_Cryptography_and_Network_Security.pdf
WachemoUniversity_Cryptography_and_Network_Security.pdfLegesseSamuel
 
ADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdf
ADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdfADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdf
ADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdfLegesseSamuel
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
Computer Programming.pdf
Computer Programming.pdfComputer Programming.pdf
Computer Programming.pdfLegesseSamuel
 
Lect_4_Requirement Modeling(Use Case_and_Static).pdf
Lect_4_Requirement Modeling(Use Case_and_Static).pdfLect_4_Requirement Modeling(Use Case_and_Static).pdf
Lect_4_Requirement Modeling(Use Case_and_Static).pdfLegesseSamuel
 

More from LegesseSamuel (10)

WachemoUniversity_Cryptography_and_Network_Security.pdf
WachemoUniversity_Cryptography_and_Network_Security.pdfWachemoUniversity_Cryptography_and_Network_Security.pdf
WachemoUniversity_Cryptography_and_Network_Security.pdf
 
ADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdf
ADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdfADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdf
ADVANCED CALCULUS-SCHAUMSOUTLINE SERIES.pdf
 
ch20.ppt
ch20.pptch20.ppt
ch20.ppt
 
ch14.ppt
ch14.pptch14.ppt
ch14.ppt
 
ch11.ppt
ch11.pptch11.ppt
ch11.ppt
 
LinkedQueues.ppt
LinkedQueues.pptLinkedQueues.ppt
LinkedQueues.ppt
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
Lecture-7.ppt
Lecture-7.pptLecture-7.ppt
Lecture-7.ppt
 
Computer Programming.pdf
Computer Programming.pdfComputer Programming.pdf
Computer Programming.pdf
 
Lect_4_Requirement Modeling(Use Case_and_Static).pdf
Lect_4_Requirement Modeling(Use Case_and_Static).pdfLect_4_Requirement Modeling(Use Case_and_Static).pdf
Lect_4_Requirement Modeling(Use Case_and_Static).pdf
 

Recently uploaded

Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)Areesha Ahmad
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...ssifa0344
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfSumit Kumar yadav
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRDelhi Call girls
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)Areesha Ahmad
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfSumit Kumar yadav
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PPRINCE C P
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)PraveenaKalaiselvan1
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisRaman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisDiwakar Mishra
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPirithiRaju
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 

Recently uploaded (20)

Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdf
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisRaman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 

DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf

  • 1. Lecture 4 and 5: Mutual Execution and Election Algorithms Distributed and Cloud Computing Fall 2021 Slides adopted from the instructional material of the textbook Distributed Systems: Principles and Paradigms by Andrew S. Tanenbaum, Maarten van Steen. 1
  • 2. Contents • Distributed system concepts • Distributed system design goals • Architectures • Coordination in Distributed Systems: • Logical Clocks • Lamport’s Logical Clocks • Vector Clocks • Mutual Exclusion • Election Algorithms 2
  • 3. Coordination:  Mutual Exclusion  Election Algorithms Reading Assignment Mutual Exclusion and Election Algorithms: Text book 6.3 and 6.4 3
  • 4. Mutual Exclusion  A centralized algorithm  Permission-based  A distributed algorithm  Ricart & Agrawala  A token-ring algorithm  A decentralized mutual exclusion 4
  • 5. Overview of Mutual exclusion Problem A number of processes in a distributed system want exclusive access to some resource. Basic solutions Permission-based: A process wanting to enter its critical section, or access a resource, needs permission from other processes. Token-based: A token is passed between processes. The one who has the token may proceed in its critical section, or pass it on when not interested. 5
  • 6. Requirements 1. Correctness/Safety: • At most one process holds the lock/enter C.S. at a time 2. Fairness: • Any process that makes a request must be granted lock • Implies that system must be deadlock-free • Assumes that no process will hold onto a lock indefinitely • Eventual fairness: Waiting process will not be excluded forever • Bounded fairness: Waiting process will get lock within some bounded number of cycles (typically n) 6
  • 7. Other Requirements • Low message overhead • No bottlenecks • Tolerate out-of-order messages • Allow processes to join protocol or to drop out • Tolerate failed processes • Tolerate dropped messages 7
  • 8. Mutual Exclusion A Centralized Algorithm (1) @ Client  Acquire: Send (Request, i) to coordinator Wait for reply @ Server: while true: m = Receive() If m == (Request, i): If Available(): Send (Grant) to i 8
  • 9. Mutual Exclusion A Centralized Algorithm (2) @ Server: while true: m = Receive() If m == (Request, i): If Available(): Send (Grant) to I else: Add i to Q 9
  • 10. Mutual Exclusion A Centralized Algorithm (3) @ Server: while true: m = Receive() If m == (Request, i): If Available(): Send (Grant) to I else: Add i to Q If m == (Release)&&!empty(Q): Remove ID j from Q Send (Grant) to j @ Client  Release: Send (Release) to coordinator 10
  • 11. Mutual Exclusion A Centralized Algorithm (4) • Correctness: • Clearly safe • Fairness depends on queuing policy. • E.g., if always gave priority to lowest process ID, then processes 1 & 2 lock out 3 • Performance • "cycle" is a complete round of the protocol with one process i entering its critical section and then exiting. • 3 messages per cycle (1 request, 1 grant, 1 release) • Lock server creates bottleneck • Issues • What happens when coordinator crashes? • What happens when it reboots? 11
  • 12. Permission-based, centralized Coordinator Queueis empty Simply use a coordinator P0 P1 P2 Request OK C No reply P0 P1 Request P2 C 2 Release OK P0 P1 P2 C (a) (b) (c) (a) Process P1 asks the coordinator for permission to access a shared resource. Permission is granted. (b) Process P2 then asks permission to access the same resource. The coordinator does not reply. (c) When P1 releases the resource, it tells the coordinator, which then replies to P2. 12
  • 13. Ricart & Agrawala, Distributed The same as Lamport except that acknowledgments are not sent Return a response to a request only when: The receiving process has no interest in the shared resource; or The receiving process is waiting for the resource, but has lower priority (known through comparison of timestamps). In all other cases, reply is deferred, implying some more local administration. 13
  • 14. A Distributed Algorithm 3 (Ricart & Agrawala) • Also relies on Lamport totally ordered clocks. • When node i wants to enter C.S., it sends time- stamped request to all other nodes. These other nodes reply (eventually). When i receives n-1 replies, then can enter C.S. • Trick: Node j having earlier request doesn't reply to i until after it has completed its C.S. 14
  • 15. A Distributed Algorithm Three different cases: 1.If the receiver is not accessing the resource and does not want to access it, it sends back an OK message to the sender. 2.If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. 3.If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins. 15
  • 16. A Distributed Algorithm • Two processes (0 and 2) want to access a shared resource at the same moment. 16
  • 17. A Distributed Algorithm • Process 0 has the lowest timestamp, so it wins. 17
  • 18. A Distributed Algorithm (4) • When process 0 is done, it sends an OK also, so 2 can now go ahead. 18
  • 19. Example with three processes 0 1 2 8 8 8 12 12 12 0 1 2 OK OK OK Accesses resource 0 1 2 OK Accesses resource (a) (b) (c) (a) Two processes want to access a shared resource at the same moment. (b) P0 has the lowest timestamp, so it wins. (c) When process P0 is done, it sends an OK also, so P2 can now go ahead. Ricart & Agrawala, Distributed cont.. 19
  • 20. Performance • Each cycle involves 2(n-1) messages • n-1 requests by I • n-1 replies to I • Issues • What if node fails? • How is the performance compared to centralized? 20
  • 21. Token ring algorithm Essence Organize processes in a logical ring, and let a token be passed between them. The one that holds the token is allowed to enter the critical region (if it wants to). An overlay network constructed as a logical ring with a circulating token 0 1 2 3 4 5 6 7 T oken 21
  • 22. A Token Ring Algorithm • Organize the processes involved into a logical ring • One token at any time  passed from node to node along ring 22
  • 23. A Token Ring Algorithm • Correctness: • Clearly safe: Only one process can hold token • Fairness: • Will pass around ring at most once before getting access. • Performance: • Each cycle requires between 1 - ∞ messages • Latency of protocol between 0 & n-1 • Issues • Lost token 23
  • 24. Decentralized mutual exclusion Principle Assume every resource is replicated N times, with each replica having its own coordinator ⇒ access requires a majority vote from m > N/2 coordinators. A coordinator always responds immediately to a request. Assumption When a coordinator crashes, it will recover quickly, but will have forgotten about permissions it had granted. 24
  • 28. Election Algorithms  The bully algorithm  The ring algorithm 28
  • 29. Election algorithms Principle An algorithm requires that some process acts as a coordinator. The question is how to select this special process dynamically. Note In many systems the coordinator is chosen by hand (e.g. file servers). This leads to centralized solutions ⇒ single point of failure. 29
  • 30. Election algorithms Principle An algorithm requires that some process acts as a coordinator. The question is how to select this special process dynamically. Note In many systems the coordinator is chosen by hand (e.g. file servers). This leads to centralized solutions ⇒ single point of failure. Teasers 1 2 If a coordinator is chosen dynamically, to what extent can we speak about a centralized or distributed solution? Is a fully distributed solution, i.e. one without a coordinator, always more robust than any centralized/coordinated solution? 30
  • 31. Basic Assumptions: Bullying All processes have unique id’s All processes know id’s of all processes in the system (but not if they are up or down) Election means identifying the process with the highest id that is up 31
  • 32. Election by bullying: The Bully Alg. Principle Consider N processes {P0 ,...,PN−1} and let id (Pk ) = k . When a process Pk notices that the coordinator is no longer responding to requests, it initiates an election: 1 2 3 Pk sends an ELECTION message to all processes with higher identifiers: Pk+1,Pk+2,...,PN−1. If no one responds, Pk wins the election and becomes coordinator. If one of the higher-ups answers, it takes over and Pk ’s job is done. 32
  • 33. The Bully Algorithm (1) • The bully election algorithm. (a) Process 4 holds an election. (b) Processes 5 and 6 respond, telling 4 to stop. (c) Now 5 and 6 each hold an election. 33
  • 34. The Bully Algorithm (2) • The bully election algorithm. (d) Process 6 tells 5 to stop. (e) Process 6 wins and tells everyone. 34
  • 35. Election by bullying The bully election algorithm Election 1 2 4 0 5 6 3 7 OK 1 2 4 0 5 6 3 7 Election 1 2 4 0 5 6 3 7 OK 1 2 4 0 5 6 3 7 Coordinator 1 2 4 0 5 6 3 7 35
  • 36. Election in a ring: The ring algorithm Principle Process priority is obtained by organizing processes into a (logical) ring. Process with the highest priority should be elected as coordinator. Any process can start an election by sending an election message to its successor. If a successor is down, the message is passed on to the next successor. If a message is passed on, the sender adds itself to the list. When it gets back to the initiator, everyone had a chance to make its presence known. The initiator sends a coordinator message around the ring containing a list of all living processes. The one with the highest priority is elected as coordinator. 36
  • 37. Election in a ring Election algorithm using a ring 1 2 3 4 5 6 7 0 [3] [3,4] [3,4,5] [3,4,5,6] [3,4,5,6,0] [3,4,5,6,0,1] [3,4,5,6,0,1,2] [6] [6,0] [6,0,1] [6,0,1,2] [6,0,1,2,3] [6,0,1,2,3,4] [6,0,1,2,3,4,5] The solid line shows the election messages initiated by P6 The dashed one the messages by P3 37
  • 38. Summary  Mutual Exclusion  A centralized algorithm  Permission-based  A distributed algorithm  Ricart & Agrawala  A token-ring algorithm  A decentralized mutual exclusion  Election Algorithms  The bully Algorithm  Ring Algorithm Reading Assignment Mutual Exclusion and Election Algorithms Text book 6.3 and 6.4 38