Professional Documents
Culture Documents
P&DC Assignment 3
P&DC Assignment 3
Assignment No. 03
Submitted by:
Malik Muhammad Luqman
{01-134191-046}
Muhammad Walid Khan
{01-134191-085}
Submitted to:
Madam Maryam Khalid Multani
Introduction:.............................................................................................................................................. 4
Pros: ...................................................................................................................................................... 6
Cons: ..................................................................................................................................................... 6
Implementation: ........................................................................................................................................ 6
Command: ................................................................................................................................................. 7
You do not need to implement network delays etc. A simple high‐level implementation will
suffice. It should include implementation of the basic Chord functions (succ(k), Lookup(k),
etc.) and implement joining and leaving of nodes [Hint: using Insert(key), etc.]
Your implementation should take as input (See deliverables) number of nodes as well as the
times at which they will join or leave the peer‐to‐peer network, or it should take the number
of nodes as input and randomize the times of joining and leaving.
Design & Implementation
Introduction:
Hash Table is a data structure which stores data in an associative manner. In a hash table,
data is stored in an array format, where each data value has its own unique index value.
Chord is a protocol and algorithm for a peer-to-peer distributed hash table. A distributed
hash table stores key-value pairs by assigning keys to different computers.
DHT is a similar data structure that runs in a distributed setting.
Choosing Chord
A client-server architecture based DHT was used before chord. In this architecture all the requests
are routed through a single server known as Coordination server.
Pros:
Chord is a peer to peer distributed hash table that uses consistent hashing on peer’s
address.
Peers replace Slaves.
No single point of failure as it is fully distributed.
Cons:
Not all nodes share same responsibility.
Single point of failure.
Implementation:
Implement a simulator for the Chord Peer-to-Peer (P2P) distributed system. Although it is
implemented as an approximation of multiple nodes working in parallel, the actions of the nodes
are executed serially. This is done by quantizing time in discrete units. At each unit of time, each
Node performs one operation in round-robin fashion. Nodes communicate with each other by
sending Remote Procedure Calls (RPCs), either containing return values or instructions to execute
a function. These RPCs are “sent” by having the sender Node append the RPC onto the end of the
receiver Node’s RPC queue.
The Chord Ring keeps track of all Nodes in the Ring by maintaining a list and can add/remove
Nodes as desired. At each time step, the Chord Ring will “step”, so each Node in the list processes
one RPC. The serial order in which the Nodes do this is arbitrarily determined by their order in the
list. Find Successor is implemented recursively. That is, rather than have the original Lookup Node
initiate all Find Successor RPCs, the intermediate Nodes directly forward the query to the next
relevant Node. Once the successor is found, the return message can be sent back directly to the
original Node.
When a Node joins the network, it calls a random Node to find its successor. Once that successor
is found, the Node will send an RPC to the successor to ask for key value pairs that this Node
should store. The successor then sends those pairs in a return RPC.
Tools Used:
Python
Libraries.
Visual code.
Command:
Using following command for compiling the code:
The code will start compiling and output will be displayed in the terminal.
Division of labor:
As the group contains two members and the assignment is divided among both. Each member
participated equally and fulfilled the requirements.
Sample Input and outputs:
End