maekawa
TRANSCRIPT
-
7/28/2019 Maekawa
1/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 primitiveswere 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 thedeadlocked 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),towait 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 dataspace. 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.
-
7/28/2019 Maekawa
2/2
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 formatis as follows. The format is in Java.
byte source; //contains the id of source of the messagebyte 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 nodebyte 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 Waiting time Number of messages0.5 9.8498 3811
1.0 9.8498 3810
2.0 9.8498 3815
5.0 9.8498 3915
Deadlock free version:
T Waiting time Number of messages
0.5 339 4561
1.0 217 4511
2.0 218 41505.0 222 4115
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.