2015 3rd AASRI Conference on Computational Intelligence and Bioinformatics (CIB 2015) ISBN: 978-1-60595-308-3
Simulation Implementation of Centralized Algorithm Mutual
Exclusion in Distributed Systems
Qian Li
Changchun Guanghua University, Changchun, Jilin, China, 130033
ABSTRACT: In this paper, the author analyses and studies the problems of distributed synchronization and mutual exclusion, and improves a token-based algorithm—Goscinski algorithm after evaluating a number of existing distributed mutual exclusion algorithm. In order to prove that the improved algorithm has better per-formance, the author in this paper carries out a detailed analysis and calculation of the performance of the im-proved algorithm, and compares it with Goscinski algorithm and other algorithms.
1 INTRODUCTION
Mutual exclusion aims to solve the control of each concurrent process’s access to critical resources in the single-machine system. With the development of computer technology, mutual exclusion problem ex-tends from the single-machine system to the distrib-uted systems. For example, in Web applications, multiple Web servers in response to different re-quests may need to modify the same file on the same server at the same time, and each Web server must synchronize the mutual exclusion modification of the file to ensure the accuracy and completeness of the file content; another example, in large-scale dis-tributed parallel computing, concurrent processes distributed in different machines inevitably needs constant interaction of intermediate result data, and if there is no mutual exclusion mechanism, the cor-rect modification of the intermediate results cannot be guaranteed, which may leads to fatal error in the entire calculation.
In order to achieve distributed mutual exclusion, people have proposed a lot of distributed mutual ex-clusion algorithms, including license-based algo-rithm and token-based algoalgo-rithm. License-based al-gorithm and token-based alal-gorithm use a completely different way to achieve mutual exclusion, each with distinct characteristics. Although license-based algo-rithm was modified and improved for a lot of times, in general, the average number of messages that need to be changed in license-based algorithm is larger than that in token-based algorithm. Therefore, this paper focuses on the research and improvement of token-based algorithm.
2 TOKEN-BASED ALGORITHM
The concept of token is introduced to the token-based algorithm. A token actually represents a con-trol point and is transmitted in the form of messages among the system processes in accordance with a certain order, and only the process that receives the message has access to the critical section. A token is unique for each critical resource, i.e. the system as-signs only one token for each critical resource. The uniqueness of the token determines that at any time, only one process has access to the critical resource, which ensures mutual exclusion access of each pro-cess to the critical resource.
2.1 TokenRing Algorithm
In TokenRing algorithm, all the processes form a ring structure logically among which the token cir-culates. Each process in the ring has the only precur-sor process and the only succesprecur-sor process. When the token moves in the ring to a certain process and is received by this process, if this process wishes to enter the critical section, it will keep the token and enters the critical section. Once it exits the critical section, it will transfer the token to the successor process; if the process that receives the token does not wish to enter the critical section, it will directly transfer the token to its successor process. Since there is only one token in the logic ring, TokenRing algorithm achieves mutual exclusion.
2.2 Ramond Algorithm
2.3 Goscinski Algorithm
Goscinski algorithm is an algorithm that has no re-quirement on the system’s logical structure and sup-port the system with a priority. Its core idea is as fol-lows: 1) in the system there is only one token created by a process at the initialization time of the system; 2) when the process requires access to the critical re-source, it broadcasts the request message to all other processes and at the same time informs them of its priority; 3) each process maintains a request queue P, and the process holding the token puts the request message it receives into the request queue P in de-scending order by priority, and the other processes do nothing when they receive the request message; 4) a request queue Q is maintained in the token, and the process holding the token adds the request in re-quest queue P to the rere-quest queue Q in the token at the initialization time of the system or when it exits the critical section and send the token to the sender of the first request in Q, and finally clears request queue P and eliminates the first request in the re-quest queue Q.
2.4 Comparison of These Three Algorithms
In TokenRing algorithm, the process will not send any request message when it wishes to enter the crit-ical section, but just waits for the arrival of the to-ken; in centralized algorithm, the process will take the initiative t send a request message to the man-agement process when it wishes to enter the critical section, and then waits for the arrival of the token the transfer of which is determined by the manage-ment process; in Goscinksi algorithm, the process will initiatively sends a request message to the hold-er of the token when it wishes to enthold-er the critical zone, and then waits for the arrival of the token and the token movement is determined by the current to-ken holder. In Ramond algorithm, the process initia-tively sends a request message to the parent node in the tree structure when it wishes to enter the critical zone, and then waits for the arrival of the token, and the movement of the token is finally determined by the holder of the token, while the parent node is in-directly involved in the determination of the token’s movement in the process of this algorithm.
Among these three algorithms, the advantage of Foscinski algorithm is the short synchronization de-lay, but because the request message needs to be re-ceived and processed by the token holder who is al-ways changing, in order to ensure that the request message can be sent to the token holder, larger num-ber of messages must be exchanged. Therefore, re-ducing the number of messages in Goscinski algo-rithm can better achieve synchronization.
3 IMPROVED GOSCINSKI ALGORITHM
3.1 Improving Ideas and Improvement Program
When analyzing Goscinski algorithm, the author first understands that it is a multi-request-reception point algorithm in which the request message of each process is received by all processes but is pro-cessed only by the token holder which is always changing, so in order to ensure that the process that wishes to enter the critical section can send the quest message to the token holder, this algorithm re-quires the process to send in the form of broadcast (N-1) messages among which (N-2) messages are not sent to the token holder and become additional messages whose existence reduces the performance of this algorithm. Reducing the number of additional messages can effectively improve the performance of this algorithm.
When re-examine Goscinski algorithm, the au-thor finds that the reason for broadcasting the mes-sage is that the request mesmes-sage can only be pro-cessed by the token holder that is always changing, and this kind of change is not known by the other processes. Therefore, Goscinski algorithm adopts the method of broadcast of request messages to ensure that the request message can be always received by the token holder.
If the token holder can inform other processes of the broadcast message at each change, other pro-cesses will be sure to send the request message to the new token holder instead of sending the request message in the form of broadcast, so the additional messages discussed above do not exist. However, af-ter the above conversions are done, the total number of messages in this algorithm remains the same but not reduced, because each transfer of the token re-quires a broadcast of message, while the number of transfer of the token is the same as that of generation times of request messages. In this case, in order to reduce the total number of messages, the number of broadcast of messages must be reduced, in other words, the broadcast of message does not occur eve-ry time the token holder changes.
Based on the above considerations, the following modifications are made to Goscinski algorithm:
(1) In the system there is an auxiliary process which is fixed. Whenever there is the case of de-layed request, a non-management process is bound to receive the request message and after it receives the request message, it forwards it to the auxiliary process;
(3) In order to ensure that the delayed requests can be added to the request queue Q asap, each time after the management exits the critical section, it will transfer the token to the auxiliary process. After the auxiliary process adds the delayed request mes-sage to the token, it will transfer the token to the sender of the first request message in the token’s re-quest queue Q.
3.2 Performance Analysis of the Improved
Algorithm
After the above modifications of Goscinski algo-rithm, the management process and auxiliary process are introduced, so the improved algorithm is more complex than Goscinski algorithm in how to process request messages, which may cause some loss of the performance. Since the main object of this paper is to improve the performance of Goscinski algorithm in three aspects of the average number of messages, synchronization delay, and the response time, this paper will only focus on the average number of mes-sages, synchronization delay, and the response time and will not consider the influence of the complexity of processing request messages on the performance of the algorithm.
3.3 The Average Number of Messages
Suppose the system has N processes.
In the improved algorithm, each request message may need to be forwarded but at most for once, and in the best case, each request message can be re-ceived by the management process, while in the worst case, only one request message is received by the management process and the other request mes-sages need to be forwarded.
(1) Consider the average number of messages of the algorithm in the best case。
In a cycle, suppose that when the management process exits the critical section, the number of re-quest message it has collected is R, so from sending the request to entering the critical section, these R processes send a total of R request messages, (N-1) notification messages, and (R+1) token messages, so in n cycles, the average number of messages is:
3 M = ∑ ∑ n i i n
i i i
R N R R 1 1 ) 1 + 1 + + ( =2+ ∑ ∑ n i i n i R N 1 1 (1)
According to (1), Mdecreases with the increase
of Ri.
Because 1≤Ri≤N 1, So
2+ ∑ ∑ n i n i N N 1 3 ) 1 ( 1 M ≤ + 2 ≤ ∑ ∑ m i n i N 3 3 1 That is
When 1≤Ri≤N 1,
And
3+ 1 1
1
M
N ≤ ≤2+N
When 1≤Ri≤N 1,
2+ ∑ ∑ n i n i N N 1 3 ) 1 ( 1 M ≤ + 2 ≤ ∑ ∑ m i n i N 3 3 1 And 3+ 1 1 1 M
N ≤ ≤2+N
(2) Consider the average number of messages of the algorithm in the worst case
Suppose the number of request message in any given cycle is R, (R-1) request messages are for-warded, and from R processes sending request mes-sages to entering the critical section, a total number of R request messages, (N-1) notification messages, and (R+1) token messages, as well as (R-1) forward-ed messages are sent, so in n cycles, the average number of messages is:
1) The average number of message integrating both the best case and the worst case: in the best case, the average number of messages is
3+ 1 1 1
M
N ≤ ≤2+N, and in the worst case, the
aver-age number of messaver-age is 4≤M2 ≤2+N.
There-fore, the above cases integrated, the average number
of messages in the algorithm is 3+N 1 M 2+N 1
≤ ≤
. In the case of low request load, namely the request load
is 2,Ri=1, the maximum of M is 2+N, and when
the request load is gradually increased, Mdecreases gradually and approaches 3, and the higher the
re-quest load, the smaller M is.
Compared with Goscinski algorithm, when N>4, and the request load is greater than 2, with or with-out request messages requiring to be forwarded, the average number of messages of the improved algo-rithm is smaller than that of Goscinski algoalgo-rithm, and the gap increases with the increase of the request load.
3.3.1 Synchronization Delay
multi-threaded simulation of distributed mutual exclusion on the computer.
In Token-based algorithm, during the time from one process exiting the critical section to the next process entering the critical section, the number of token transfer determines the length of synchroniza-tion delay time, so in this secsynchroniza-tion, synchronizasynchroniza-tion delay time is measured by the number of token transfer times during the time from one process exit-ing the critical section to the next process enterexit-ing the critical section.
In the improved algorithm, every time a process exits the critical section, the token is directly trans-ferred to the sender of the first request in token queue Q, and when the sender of the first request in token queue Q receives the token, it enters the criti-cal section, so synchronization delay time in the im-proved algorithm is the transfer time of the token, which is the same as Goscinski algorithm.
3.3.2 Response Time
Since the response time is determined by a variety of factors such as the network status, the length of time that processes remain in the critical section, etc., it is difficult to be analyzed and calculated and needs sta-tistical analysis through experiment under specific conditions. In the experiments, data related to the re-sponse time should be collected through the compar-ison of which the response time by the improved al-gorithm is compared with that by Goscinski algorithm.
3.3.3 Comprehensive Comparison
The performance comparison among the improved algorithm, Goscinski algorithm and other algorithms is shown in Table 1. According to the comparison of performance data in Table 1, the performance of im-proved algorithm is better.
Table 1. Performance Comparison Table of the Improved Algorithm and Other Algorithms.
algorithm
the average number of messages
the number of synchronization delay messages
the improved
algorithm (3+ 1
1
−
N )~(2+N) 1
Goscinski
algorithm N 1 TokenRin
algorithm 2
N
0~(N-1)
Ramond
algorithm O(logN) 0~(N-1)
3.4 Simulation Implementation of Improved
Goscniski Algorithm
The improved Goscniski algorithm simulates the multi-thread implementation of distributed mutual
exclusion simulation experiments main interface on which test data are input, as shown in Fig.1, and the results after running are shown in Fig. 2.
Figure 1. Improved Goscnoski algorithm experimental proce-dure figure.
Figure 2. Improved Goscnoski algorithm experimental results figure.
4 CONCLUSION
In this paper, the author conducts in-depth studies and discussion of several distributed mutual exclu-sion algorithms, after analysis and comparison of the advantages and disadvantages of these algorithms, focuses on and improves a token-based algorithm --- Goscniski algorithm. The improved algorithm can not only synchronize access to the critical section of each node in the computer network without re-quirements of logical structure through sending mes-sages and transferring the token to ensure the con-sistency and integrity of critical resources, but also support access to critical resources of each node in priority order. The average number of the improved
algorithm is maintained in the range of 3+ 1
1
−
N ~
2+N, and is better than Goscinski algorithm in most cases. Meanwhile, unlike other algorithms such as Remond algorithm and other ones, the improved al-gorithm has no special restraints and requirements on the network logical structure, and is more flexible and applicable.
[image:4.612.376.508.83.177.2] [image:4.612.377.513.208.300.2]of the performance analysis of the improved algo-rithm, comparative experiments are conducted to prove that the improved algorithm has better per-formance, and the performance deriving from the experiments is consistent with that from the analysis and evaluation.
REFERENCES
[1] Raymound, K., A tree-based algorithm for distributed Mu-tual Exclusion, ACM Transactions on Computer Systems, vol. 7, No. 1, Feb. 1989, pp. 61-77.
[2] Tanenbaum/Translator: Xin Chunsheng, Chen Zongbin “Distributed Systems: Principles and Paradigms (2nd Edi-tion)” TsingHua University Press, pp. 243-256.
[3]Coulouris/Translator: Jin Beihong, Cao Donglei “Distribut-ed Systems Concepts and Design”, Press: China Machine Press, pp.59-71.
[4] Xing Yan, Research on Mutual Exclusion Algorithm in Dis-tributed System Process, Harbin University of Commerce Journal, vol. 19, NO. 1, Feb. 2006.