Vous êtes sur la page 1sur 2

Implementation Of Maekawa's algorithm Maekawa's algorithm is used for achieving mutual exclusion in distributed systems.

All the features of the original algorithm were implemented. The algorithm is implemented in Java. Major design decisions: A process/node in the distributed system is treated as a thread. Then node can enter critical section asynchronously. But the times at which a process enters CS is implemented as defined in the problem statement. Processes use sockets to communicate with each other. Stream Sockets are used. Each process listens for messages on an unique address and port. Each process knows the addresses of all other processes in its Quorum. These addresses are hard coded in the program. No Name server was implemented to do this. The concept of CS is implemented in the program. No Synchronization primitives were used to define CS. But the logic in the program guarantees that processes access CS mutually exclusively. System time is used to record the waiting times of the processes. Monitor is a thread which runs concurrently with all other processes.Moniter knows the addresses of all the other processes and polls the processes in the deadlocked version to detect a deadlock, if any. In the case of deadlock, it asks one of the processes to give up and the system comes out of deadlock after that process returns all the tokens. In CS, the number of CS executions are counted and the System exits after the count reaches 200. All the traffic generators are forced to wait for 5 seconds for the first time(only),to wait for all the processes to start up.

Program Structure: A node is implemented as a class(class Node) and 16 instances were created for that class. Addresses are declared as static so that different nodes can share the same data space. In case different nodes are created on different machines, they have different instances but have the same value. A Traffic Generator is implemented as a class(class Traffic Generator) which runs asynchronously with Node ,after created. CS is implemented as a class. This is a logical CS. Message class defines the structure of the message. A moniter is run on a machine and nodes need not know the address of the monitor. But the moniter knows the addresses all the nodes.

Message format: For simplifying implementation, a single format is used for all the messages. Some fields of Message are relevant for some respective messages. The message format is as follows. The format is in Java. byte source; //contains the id of source of the message byte destination; //contains the id of destination of the message byte type; //type of message int clock; //Logical clock value exchanged(lamport) REQUEST=1,REPLY=2,RELEASE=3,GRANT=4,INQUIRE=5,FAILED=6,YEILD=7, MONITOR=8,END=9; //Remaining are valid only for messages generated by Monitor process byte tokens[]; //This array is the list of REPLYs received by a node byte groupmembers[]; //groupmembers of a node. This is redundant but is used to reduce calculations at monitor byte state; //State of the Node. redundant. Results: Deadlock prone version: T 0.5 1.0 2.0 5.0 Deadlock free version: T 0.5 1.0 2.0 5.0 Conclusion: In both Maekawa's algorithms, the number of messages exchanged is far less when compared to Ricart-Agarwala's algorithm.. Ricart agarwala uses 15*2*200=6000 Messages for 200 critical section executions. Waiting time 339 217 218 222 Number of messages 4561 4511 4150 4115 Waiting time 9.8498 9.8498 9.8498 9.8498 Number of messages 3811 3810 3815 3915

Vous aimerez peut-être aussi