Distributed Mutual Exclusion Algorithms
Course: Distributed Computing Faculty: Dr. Rajendra Prasath
Spring 2019
Distributed Mutual Exclusion Algorithms Course: Distributed - - PowerPoint PPT Presentation
Distributed Mutual Exclusion Algorithms Course: Distributed Computing Faculty: Dr. Rajendra Prasath Spring 2019 About this topic This course covers various concepts in Mutual Exclusion in Distributed Systems. We will also focus on different
Spring 2019
This course covers various concepts in Mutual Exclusion in Distributed Systems. We will also focus on different types of distributed mutual exclusion algorithms in distributed contexts and their analysis
2
Rajendra, IIIT Sri City
è Challenges in Message Passing systems è Distributed Sorting è Space-Time Diagram è Partial Ordering / Causal Ordering è Concurrent Events è Local Clocks and Vector Clocks è Distributed Snapshots è Termination Detection è Topology Abstraction and Overlays è Leader Election Problem in Rings è Message Ordering / Group Communications
Rajendra, IIIT Sri City
3
Rajendra, IIIT Sri City
4
Let us explore mutex algorithms proposed for various interconnection networks
Rajendra, IIIT Sri City
5
è Operating systems: Semaphores è In a single machine, you could use semaphores to implement mutual exclusion è How to implement semaphores?
è Inhibit interrupts è Use clever instructions (e.g. test-and-set)
è On a multiprocessor shared memory machine, only the latter works 6
Rajendra, IIIT Sri City
7
Rajendra, IIIT Sri City
è race condition 8
Rajendra, IIIT Sri City
9
Rajendra, IIIT Sri City
è No Deadlocks – no set of sites should be permanently blocked, waiting for messages from
è No starvation – no site should have to wait indefinitely to enter its critical section, while other sites are executing the CS more than once è Fairness - requests honored in the order they are
agree on the order of events. (Fairness prevents starvation.) è Fault Tolerance – the algorithm is able to survive a failure at one or more sites
10
Rajendra, IIIT Sri City
special message known as a token è Token holder has right to access shared resource è Wait for/ask for (depending on algorithm) token; enter Critical Section (CS) when it is
hold until requested (depending on algorithm) è If a process receives the token and doesn’t need it, just pass it on 11
Rajendra, IIIT Sri City
12
Rajendra, IIIT Sri City
13
Rajendra, IIIT Sri City
Advantages: è Starvation can be avoided by efficient
è Deadlock is also avoidable Disadvantage: Token Loss è Must initiate a cooperative procedure to recreate the token è Must ensure that only one token is created! 14
Rajendra, IIIT Sri City
15
Rajendra, IIIT Sri City
è Guarantees mutual exclusion è No starvation: Only if requests served in order è No deadlock è Fault tolerant? è Single point of failure è Blocking requests mean client processes have difficulty distinguishing crashed coordinator from long wait è Bottlenecks è The solution is simple and ease 16
Rajendra, IIIT Sri City
Why Quorum based algorithm? è Lamports and Ricard-Agrawala’ algorithm requires permission from all processes to enter into the critical section. Modifications: è Is it necessary to obtain permission from all processes before entering into the CS? è How to reduce the message exchanges and increase the performance of MutEx algorithm?
17
Rajendra, IIIT Sri City
è Such a set is said to be a Request Set or Quorum è In fact, we will have a separate Request set for each process Pi 18
Rajendra, IIIT Sri City
19
Rajendra, IIIT Sri City
20
Rajendra, IIIT Sri City
21
Rajendra, IIIT Sri City
22
Rajendra, IIIT Sri City
23
Rajendra, IIIT Sri City
è For all i, j: Ri ∩ Rj ≠ Φ è For all i: i Є Ri è For all i: | Ri | = K, for some K è Any node i is contained in exactly D Request Sets, for some Request set D è K = D = sqrt(N) for Maekawa's algorithm 24
Rajendra, IIIT Sri City
è Pi sends REQUEST message to all process in Ri
è Send a REPLY message if no REPLY message has been sent since the last RELEASE message is received. è Update status to indicate that a REPLY has been sent. è Otherwise, queue up the REQUEST
è Pi enters critical section after receiving REPLY from all nodes in Ri 25
Rajendra, IIIT Sri City
contd)
è Send RELEASE message to all nodes in Ri è On receiving a RELEASE message, send REPLY to next node in queue and delete the node from the queue. è If queue is empty, update status to indicate no REPLY message has been sent 26
Rajendra, IIIT Sri City
è Message Complexity: 3 * sqrt (N) è Synchronization delay
è 2*(max message transmission time)
è Major problem: DEADLOCK possible è Need three more types of messages (FAILED, INQUIRE, YIELD) to handle deadlock.
è Message complexity can be 5* sqrt(N N)
è How to build the request sets?
27
Rajendra, IIIT Sri City
28
Rajendra, IIIT Sri City
è Request movements in an unidirectional ring network 29
Rajendra, IIIT Sri City
P0 P1 P2 P3 PN-1 Previous holder of token next holder of token current holder of token
è Broadcast a request for the token è Process with the token sends it to the requestor if it does not need it è Issues:
è Current versus outdated requests è Determining sites with pending requests è Deciding which site to give the token to
30
Rajendra, IIIT Sri City
The token:
è Queue (FIFO) Q of requesting processes è LN[1.. n] : sequence number of request that j executed most recently
The request message:
è REQUEST( i, k): request message from node i for its kth critical section execution
Other data structures:
è RNi [1.. n] for each node i, where , RNi [ j ] is the largest sequence number received so far by i in a REQUEST message from j
31
Rajendra, IIIT Sri City
è If i does not have token, increment RNi [ i ] and send REQUEST( i, RNi [ i ]) to all nodes è If i has token already, enter critical section if the token is idle (no pending requests), else follow rule to release critical section
è Set RNj [ i ] = max(RNj [ i ], sn) è If j has the token and the token is idle then
è send it to i if RNj [ i ] = LN[ i ] + 1 è If token is not idle, follow rule to release critical section
32
Rajendra, IIIT Sri City
è Enter CS if token is present
è Set LN[ i ] = RNi[ i ] è For every node j which is not in Q (in token), add node j to Q if RNi[ j ] = LN[ j ] + 1 è If Q is non empty after the above, delete first node from Q and send the token to that node 33
Rajendra, IIIT Sri City
è 0 if node holds the token already, è n otherwise
è 0 (node has the token) or è max. message delay (token is elsewhere)
34
Rajendra, IIIT Sri City
è Root’s Holder variable points to itself
35
Rajendra, IIIT Sri City
è To request critical section:
è Send REQUEST to parent on the tree, provided i does not hold the token currently and Qi is
è When a non-root node j receives a request from k
è place request in Qj è send REQUEST to parent if no previous REQUEST sent
36
Rajendra, IIIT Sri City
When the root receives a REQUEST:
è send the token to the requesting node è set Holder variable to point to that node
When a node receives the token:
è delete first entry from the queue è send token to that node è set Holder variable to point to that node è if queue is non non-empty, send a REQUEST message to the parent (node pointed at by Holder variable)
37
Rajendra, IIIT Sri City
contd)
è To execute critical section:
è enter if token is received and own entry is at the top of the queue; delete the entry from the queue
è To release critical section:
è if queue is non non-empty, delete first entry from the queue, send token to that node and make Holder variable point to that node è If queue is still non non-empty, send a REQUEST message to the parent (node pointed at by Holder variable)
38
Rajendra, IIIT Sri City
è O(log n)
è (T log n)/2, where T = max. message delay 39
Rajendra, IIIT Sri City
è Non-Token based algorithm è Quorum based algorithm è Token based algorithm è Suzuki – Kasami’s Algorithm è Raymond’s Tree based algorithm
è Stay tuned ... More to come up … !!
Rajendra, IIIT Sri City
40
rajendra [DOT] prasath [AT] iiits [DOT] in
è http://www.iiits.ac.in/FacPages/index- rajendra.html OR è http://rajendra.2power3.com 41
Rajendra, IIIT Sri City
and above)
and less than 8.5)
work will also be rewarded)
learning by helping the needy students
42
Rajendra, IIIT Sri City
Rajendra, IIIT Sri City
43