Ds Lab Manual Nmiet Be LP V-Final
Ds Lab Manual Nmiet Be LP V-Final
Ds Lab Manual Nmiet Be LP V-Final
2023-2024
Department of Information Technology Page 1 | 50
VISION
MISSION
The students of the Information Technology course after passing out will:
PROGRAM OUTCOMES
The students in the Information Technology course are expected to know and be able
to:
Author
Signature
Document History
LABORATORY CODE
3 While entering in lab remove your shoes and keep it in shoe stand.
If you are the last class of the day, please POWER DOWN all computers
12 and monitors.
Prerequisite Courses:
Course Objectives:
1. The course aims to provide an understanding of the principles on which the
distributed systems are based, their architecture, algorithms and how they meet the
demands of Distributed applications.
2. The course covers the building blocks for a study related to the design and the
implementation of distributed systems and applications.
Course Outcomes:
On completion of the course, students will be able to
LIST OF ASSIGNMENTS
1. Implement multi-threaded client/server Process communication using RMI.
2. Develop any distributed application using CORBA to demonstrate object
brokering. (Calculator or String operations).
3. Develop a distributed system, to find sum of N elements in an array by
distributing N/n elements to n number of processors MPI or OpenMP.
Demonstrate by displaying the intermediate sums calculated at different
processors.
Department of Information Technology Page 8 | 50
4. Create Implement Berkeley algorithm for clock synchronization.
5. Implement token ring based mutual exclusion algorithm.
6. Implement Bully and Ring algorithm for leader election.
7. Create a simple web service and write any distributed application to consume the
web service.
8. Mini Project (In group): A Distributed Application for Interactive Multiplayer
Games.
Mini Project
A Distributed Application for Interactive Multiplayer Games
Reference Books:
1. Distributed Systems –Concept and Design, George Coulouris, Jean Dollimore, Tim
Kindberg & Gordon Blair, Pearson, 5th Edition, ISBN:978-13-214301-1.
2. Distributed Algorithms, Nancy Ann Lynch, Morgan Kaufmann Publishers,
illustrated, reprint, ISBN: 9781558603486
3. Java Network Programming & Distributed Computing by David Reilly, Michael
Reilly
4. Distributed Systems - An Algorithmic approach by Sukumar Ghosh (good book for
distributed algorithms)
5. Distributed Algorithms: Principles, Algorithms, and Systems by A. D.
Kshemkalyani and M. Singhal (Good for algorithms, but very detailed, has lots of
algorithms; good reference)
6. Design and Analysis of Distributed Algorithms by Nicola Santoro (good, distributed
algorithms book).
- Books / E- Learning References
1. https://home.mit.bme.hu/~meszaros/edu/oprendszerek/segedlet/elosztott/
Distributed-systems-survey.pdf
2. https://home.mit.bme.hu/~meszaros/edu/operendszerek/segedlet/elosztott/
DisSysUbiCompReport.html
1. Attendance
Assessment Poor (1) Good (3) Very Good (4) Excellent (5)
Outcome Satisfactory(2)
Dimensions
1.Attendance with Passive Very little Good Individual Individual and self
Involvement of observer involvement Involvement in Involvement in Involvement in
Student (5M ) performing performing performing experim
experiment experiment
3. Presentation
Assessment Poor (1) Good (3) Very Good (4) Excelle
Satisfactory(2) nt(5)
Outcome
Dimensions
PRE-REQUISITE:
1. Knowledge of Multi-threading.
2. Knowledge of Client Server Programming.
3. Knowledge of RMI.
OBJECTIVE:
1. To Remote Method Invocation works.
2. To RMI allows objects to invoke methods on remote objects.
3. To write Distributed Object Application.
THEORY:
What is thread?
A thread of execution is the smallest sequence of programmed instructions
that can be managed independently by a schedule which is typically a part of
the operating systems. The implementation of threads and processes differs
between operating systems. A process consists of an execution environment
together with one or more threads. A threads is the operating system abstraction
of an activity the term derives from the phrase ‘thread of execution’. An execution
environment is the unit of resource management: a collection of local kernel
managed resources to which its threads have access. An execution environment
primarily consists of:
● an address space;
● thread synchronization and communication resources such as
semaphores and communication interfaces for example sockets);
● higher-level resources such as open files and windows.
Threads can be created and destroyed dynamically is needed. The central
aim of having multiple threads of execution between operations thus enabling
the overlap of computation with input and output and enabling concurrent
processing on multiprocessors. This can be particularly helpful within severs
where concurrent processing of client’s requests can reduce the tendency for
servers to become bottlenecks.
Multithreading in the Server:
RMI automatically will execute each client in a separate thread. There will only
be one instance of your server object no matter how many clients, so you need
to make sure that shared data is synchronized appropriately. In particular, any
The Above diagram demonstrates RMI communication with stub and skeleton
involved.
import java.rmi.*;
public class AddClient {
public static void main(String args[]) {
try {
String addServerURL = "rmi://" + args[0] + "/AddServer";
AddServerIntf addServerIntf =
Department of Information Technology Page 18 | 50
(AddServerIntf)Naming.lookup(addServerURL);
System.out.println("The first number is: " + args[1]);
double d1 = Double.valueOf(args[1]).doubleValue();
System.out.println("The second number is: " + args[2]);
double d2 = Double.valueOf(args[2]).doubleValue();
System.out.println("The sum is: " + addServerIntf.add(d1, d2));
}
catch(Exception e) {
System.out.println("Exception: " + e);
}
}
}
Input:
Add server
AddServerIntf
Output
CONCLUSION:
Remote Method Invocation (RMI) allows to build Java applications that are
distributed among several machines. Remote Method Invocation (RMI)
allows a Java object that executes on one machine to invoke a method of a
Java object that executes on another machine. This is an important feature,
because it allows to build distributed applications.
PRE-REQUISITE:
1. Knowledge of CORBA and its Architecture.
2. Knowledge of the Object Request Broker (ORB) and its role in CORBA.
3. Knowledge of how to create and run Java applications using command
line.
OBJECTIVE:
1. To CORBA can be used as a middleware to allow objects running on
different machines to communicate and interact with each other.
2. To Client can use CORBA to RMI on server objects that perform String
Operations such as concatenation and comparison.
3. To using CORBA allows these operations to be performed across a
distributed system transparently.
THEORY:
What is CORBA?
CORBA (Common Object Request Broker Architecture):-
CORBA (Common Object Request Broker Architecture) is a middleware
technology that enables distributed computing between different platforms and
programming languages. It provides a standard protocol for communication
between objects, and a mechanism for locating and invoking remote objects in a
network. In this lab, we will use Java and CORBA to develop a distributed
application that demonstrates object brokering with string operations.
The Common Object Request Broker Architecture (CORBA) is a first step by the
Object Management Group towards achieving application portability and
interoperability across heterogeneous computing platforms. It is a standard for
the development and deployment of applications in distributed, heterogeneous
environments. CORBA 1.1 was first introduced in 1991. In CORBA 2.0, adopted
in December 1994, true interoperability is defined by specifying how ORBs from
different vendors can interoperate.
The client makes a request using either the Dynamic Invocation Interface (DII)
or an OMG IDL stub. The client can also directly interact with the ORB through
the ORB Interface for some functions. Similarly, the object implementation
receives a request either through the OMG IDL skeleton or through a Dynamic
Skeleton Interface (DSI). The object implementation may call the Object Adaptor
and the ORB Interface for the ORB services.
The ORB locates the target object, transmits parameters and transfers control
to the object implementation through an IDL skeleton or a dynamic skeleton.
Defining the interface of an object in IDL generates an IDL skeleton that is
specific to the interface and the object adaptor. The object implementation
information provided at installation time is stored in the Implementation
Repository, which is available for use during request delivery.
Source code
import ReverseModule.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
class ReverseClient
{
try
{
// initialize the ORB object request broker
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
System.out.println("Enter String=");
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String str= br.readLine();
System.out.println(tempStr);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Step 2: Run the IDL-to-Java compiler idlj, on the IDL file to create stubs
and skeletons. This step assumes that you have included the path to the
java/bin directory in your path.
Step 3: Compile the .java files, including the stubs and skeletons (which are in
the directory newly created directory). This step assumes the java/bin directory
is included in your path.
Step 4: Start orbd. To start orbd from a UNIX command shell, enter :
OUTPUT:
CONCLUSION:
we have successfully demonstrated the concept of object brokering using
CORBA to create a distributed application for performing string operations. We
have implemented a server-side code that registers a string helper object with
the naming service, and a client-side code that accesses the string helper object
to perform operations on a string. The string helper object is a remote object that
resides on the server, and its methods are invoked by the client using the ORB.
By using CORBA, we have achieved the interoperability between different
programming languages and platforms, and have shown how object brokering
can be used to create distributed applications that can communicate seamlessly
across different systems.
PRE-REQUISITE:
1. Knowledge of MPI
2. Knowledge about its role.
3. Knowledge of how to create and run Java applications using command
line.
OBJECTIVE:
1. To Develop a widely used standard for Writing Message Passing Program
2. Design an application program interface.
THEORY:
What is MPI?
MPI (Message Passing Interface):-
Message Passing Interface (MPI) is a subroutine or a library for passing messages
between processes in a distributed memory model. MPI is not a programming
language. MPI is a programming model that is widely used for parallel
programming in a cluster. In the cluster, the head node is known as the master,
and the other nodes are known as the workers. By using MPI, programmers are
able to divide up the task and distribute each task to each worker or to some
specific workers. Thus, each node can work on its own task simultaneously.
Since this is a small module, we will be focusing on only important and common
MPI functions and techniques. For further study, there are a lot of free resources
available on the Internet.
Why MPI?
There are many reasons for using MPI as our parallel programming model:
In order to get the MPI library working, you need to include the header
file #include <mpi.h> or #include “mpi.h” in your C code.
Like other programming languages you have seen, program that includes MPI
library has its structure. The structure is shown in the figure below:
The following functions are the functions that are commonly used in MPI
programs:
MPI_Init(&argc, &argv)
This function has to be called in every MPI program. It is used to initialize the
MPI execution environment.
MPI_Comm_size(comm, &size)
MPI_Comm_rank(comm, &rank)
This function determines the rank of the calling process within the
communicator. Each process is assigned uniquely by integer rank
from 0 to number of processes - 1, and its rank gets stored in the variable rank.
MPI_Get_processor_name(name, &len)
This function returns the unique processor name. Variable name is the array of
char for storing the name, and len is the length of the name.
MPI_Wtime()
MPI_Finalize()
express library.
c. export MPJ_HOME=/path/to/mpj/
d. export PATH=$MPJ_HOME/bin:$PATH
CONCLUSION:
There has been a large amount of interest in parallel programming using Java.
mpj is an MPI binding with Java along with the support for multicore
architecture so that user can develop the code on it's own laptop or desktop.
This is an effort to develop and run parallel programs according to MPI
standard.
PRE-REQUISITE:
1. To perform this lab, you should have a basic understanding of Javan
programming language and socket programming.
2. You should also have access to a computer running a Unix-based
operating system (such as Linux or macOS) that can run Python code.
3. In addition, you should have a basic understanding of distributed systems
and clock synchronization algorithms.
4. It would also be helpful to have some experience working with simulated
distributed systems.
OBJECTIVE:
1. To understand the basic principles behind the Berkeley algorithm for clock
synchronization.
2. To implement the Berkeley algorithm in Python.
3. To test the implementation of the Berkeley algorithm in a simulated
distributed system.
4. To analyze the results of the simulation and evaluate the performance of
the algorithm.
THEORY:
What is Berkeley Algorithm?
In a distributed system, it is important to have all the clocks on different
computers synchronized to the same time. This is because many distributed
applications require a common notion of time in order to function correctly.
The Berkeley algorithm for clock synchronization is a widely used algorithm for
synchronizing the clocks of computers in a distributed system. The basic idea
behind the algorithm is to periodically synchronize the clocks of all the
computers in the system by adjusting the clock of each computer based on the
average of the clocks of all the other computers.
Algorithm:
1) An individual node is chosen as the master node from a pool node in the
network. This node is the main node in the network which acts as a master and
the rest of the nodes act as slaves. The master node is chosen using an election
process/leader election algorithm.
2) Master node periodically pings slaves nodes and fetches clock time at them
using Cristian’s algorithm.
Department of Information Technology Page 32 | 50
The diagram below illustrates how the master sends requests to slave nodes.
The diagram below illustrates how slave nodes send back time given by their
system clock.
Scope of Improvement
Source Code
import java.io.*;
import java.net.*;
import java.util.*;
Create a server socket to listen for incoming time requests from nodes.
Each node periodically sends time requests to the server.
When a node sends a time request to the server, record the time difference
between the node's local time and the time received from the server.
When the server receives a time request from a node, respond with the current
time.
Adjust the node's clock by adding the average time difference to the local time.
Output the adjusted time.
Step 5: Repeat:
Periodically repeat steps 2-4 to maintain synchronization between the node and
the server.
OUTPUT:
PRE-REQUISITE:
1. To A programming language of your choice (Python, Java, C++, etc.)
2. An understanding of socket programming and interprocess
communication
3. A development environment (e.g., an IDE such as PyCharm or Visual
Studio Code)
OBJECTIVE:
1. To Understand the basics of the token ring-based mutual exclusion
algorithm.
2. Gain experience with socket programming and interprocess
communication.
3. Learn how to implement a distributed algorithm in a programming
language of your choice.
4. Practice debugging and troubleshooting skills.
5. Learn how to test a distributed algorithm to verify correctness.
THEORY:
What is Ring Based Mutual exclusion Algorithm?
A token circulates around the ring from process to process.
A process can access the shared resource only when it receives the token.
When a process finishes accessing the shared resource, it passes the token to
the next process in the ring.
If a process wants to access the shared resource but does not have the token, it
sends a request message to the next process in the ring.
The process that receives the request message sets a flag to indicate that it has
received a request and passes the token to the next process in the ring.
When the process that has the token receives the request message flag, it does
not release the token after accessing the shared resource, but instead passes the
token to the process that requested it.
Source Code
import java.io.*;
import java.util.*;
class Tok {
OUTPUT:
CONCLUSION:
In conclusion, this lab provides an opportunity to learn and implement a token
ring-based mutual exclusion algorithm. The algorithm ensures that only one
process can access a shared resource at a time in a distributed system. By
completing this lab, you will gain experience with socket programming,
interprocess communication, and implementing a distributed algorithm in a
programming language of your choice.
Department of Information Technology Page 39 | 50
ASSIGNMENT NO. :06
AIM:
Implement Bully and Ring algorithm for leader election.
PRE-REQUISITE:
OBJECTIVE:
1. To gain a better understanding of distributed systems and leader election
algorithms.
2. To be able to implement and test the Bully and Ring algorithms in a
simulated distributed environment.
3. To compare and contrast the performance and effectiveness of the Bully
and Ring algorithms in leader election scenarios.
4. To identify the strengths and weaknesses of the Bully and Ring algorithms
in terms of scalability, fault tolerance, and resource utilization.
THEORY:
Introduction:
Leader Election is an important problem in distributed systems where a
group of processes or nodes are running independently and want to choose a
leader among themselves.
Source Code
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
Implementation Steps:
PRE-REQUISITE:
1 Knowledge of distributed application
2 Knowledge about its role.
3 Knowledge of how to create and run Java applications using command
line.
OBJECTIVE:
3. To Develop a widely used standard for Web services
4. Design an application program interface.
THEORY:
Web Service:
A web service can be defined as a collection of open protocols and standards for
exchanging information among systems or applications.
Service Requestor is the program that interacts with the web service exposed
by the Service Provider. It makes an invocation to the web service over the
network to the Service Provider and exchanges information.
SOAP web services: