Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 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 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 Algorithm

Introduction:

Load balancing is a crucial aspect of distributed systems, ensuring optimal resource


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 Concepts:

Server List:

The load balancer maintains a list of servers available to handle incoming requests.

Round Robin Selection:


The Round 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 Work Distribution:

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

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

Statelessness:
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.

Implementation:
The provided Java program exemplifies the Round Robin Load Balancing Algorithm. The
LoadBalancer 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

Usage:

Initialization:

Create an instance of the LoadBalancer class.

Add servers to the load balancer using the addServer method.

Request Processing:

Simulate incoming requests using the requestServer method.

The output displays the selected server for each request.

Advantages:

Simplicity:

The Round Robin algorithm is simple to implement and understand.

It does not require complex calculations or monitoring.

Equal Distribution:

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

No Server State Required:


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

Considerations:

Lack of Intelligence:

The algorithm lacks intelligence to consider server load, capacity, or performance.

It may not be suitable for systems with varying server capabilities.

Dynamic Environments:
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