0% found this document useful (0 votes)
27 views5 pages

DC Experiment No 8

Uploaded by

vu1s2122012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

DC Experiment No 8

Uploaded by

vu1s2122012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name:Suyash Jadhav

DIV:B Batch:C
ID:vu1f2021100
Distributed Computing

Experiment No. 8

Aim: Program for Load Balancing Algorithm.

Theory:

Load Balancing in Distributed Systems: Round Robin


Load balancing is a crucial aspect of distributed systems, ensuring optimal resource
Introductio
utilization and preventing overload on specific nodes. The Round Robin Load Balancing
Algorithm is a simple and widely used approach that distributes incoming requests evenly
across a set of servers.

Key
The load balancer maintains a list of servers available to handle incoming requests.
Server
Round
The RoundRobin
Robin algorithm systematically selects servers in a circular order for each new
request.

Each server is chosen in turn, and the next request is directed to the next server in the list.

Equal
The Workgoal is to achieve an even distribution of requests among the available servers.
primary

This prevents specific servers from being overloaded while others remain underutilized.

Statelessnes
The algorithm is stateless, meaning it does not consider the current load or historical
performance of servers.

Each server is treated equally, and no server-specific information is stored.

Implementatio
The provided Java program exemplifies the Round Robin Load Balancing Algorithm. The
LoadBalanc class maintains a list of servers and utilizes the round-robin approach to
distribute incoming requests among them.
Name:Suyash Jadhav
DIV:B Batch:C
ID:vu1f2021100
Distributed Computing

Usag

Initializatio
Create an instance of the LoadBalanc class.

Add servers to the load balancer using the addServ method.

Requestincoming requests using the


Simulate requestServ method.
The output displays the selected server for each request.

Advantage
The Round Robin algorithm is simple to implement and understand.
Simplicit
It does not require complex calculations or monitoring.

Equal
Requests are evenly distributed among servers, preventing overloading of specific nodes.

No algorithm
The Server State
is stateless, which simplifies its implementation and reduces management
overhead.

Consideration
The algorithm lacks intelligence to consider server load, capacity, or
Lack of
performance. It may not be suitable for systems with varying server capabilities.

Dynamic
In dynamic environments, where server loads change frequently, more sophisticated load
balancing algorithms may be more appropriate.

CODE:
import java.util.ArrayList;
import java.util.List;
Name:Suyash Jadhav
DIV:B Batch:C
ID:vu1f2021100
Distributed Computing

class LoadBalancer
{
private List<String> servers;
private int currentIndex;

public LoadBalancer() {
servers = new ArrayList<>();
currentIndex = 0;
}

public void addServer(String server)


{

servers.add(server);
}

public String requestServer() {


if (servers.isEmpty()) {
throw new IllegalStateException("No servers available.");
}

String selectedServer = servers.get(currentIndex);


currentIndex = (currentIndex + 1) % servers.size();

return selectedServer;
}
}

public class LoadBalancingExample


{
public static void main(String[] args)
{
LoadBalancer loadBalancer = new LoadBalancer();

// Add servers to the load balancer


loadBalancer.addServer("Server 1");
loadBalancer.addServer("Server 2");
loadBalancer.addServer("Server 3");

// Simulate multiple requests and print the selected server


for (int i = 0; i < 10; i++) {
String selectedServer = loadBalancer.requestServer();
System.out.println("Request " + (i + 1) + ": " + selectedServer);
}
}
}
Name:Suyash Jadhav
DIV:B Batch:C
ID:vu1f2021100
Distributed Computing
Name:Suyash Jadhav
DIV:B Batch:C
ID:vu1f2021100
Distributed Computing

OUTPUT:

Conclusion:
The Round Robin Load Balancing Algorithm provides a basic yet effective means of
distributing workloads in a distributed system. Its simplicity makes it suitable for scenarios
where fine-grained control and sophisticated decision-making are not critical, ensuring a fair
distribution of requests among available servers. However, in more complex environments,
other load balancing algorithms may be preferred to address specific considerations.

You might also like