Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

Experiment No. 8
Aim: Implementation of Load Balancing Algorithm

Theory:
1. Explain Load Balancing?
• Load balancing in distributed systems is the process of distributing workload across
multiple nodes in a network to improve performance, maximize resource utilization,
and ensure reliability. The goal of load balancing is to avoid overloading any single
node in the system while ensuring that all nodes are being utilized efficiently.
• In a distributed system, there may be multiple nodes that can process requests or
execute tasks. Load balancing can be used to distribute incoming requests or tasks
evenly across these nodes, avoiding bottlenecks and maximizing throughput. This
can help to improve the response time of the system, reduce the processing time of
individual requests, and increase the overall throughput of the system.
• Load balancing can be implemented using various algorithms, including round-
robin, random, and least connection. Round-robin load balancing distributes
incoming requests or tasks in a cyclical fashion to each node in turn. Random load
balancing distributes requests or tasks randomly across nodes. Least connection load
balancing distributes requests or tasks to the node with the fewest connections or
active tasks.
• Overall, load balancing is a critical technique for ensuring the performance,
scalability, and reliability of distributed systems. By distributing workload evenly
across nodes, load balancing can help to prevent overloading, reduce response times,
and increase overall throughput.

2. Purpose of Load Balancing?


i. Performance: In a distributed system, there may be multiple nodes that can handle
incoming requests or tasks. Load balancing ensures that the workload is distributed
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

evenly across all nodes, avoiding overloading any single node and ensuring that all
nodes are utilized efficiently. This helps to improve the response time of the system,
reduce the processing time of individual requests, and increase overall throughput.
ii. Scalability: Load balancing helps to ensure that the system can scale effectively as
the workload grows. By distributing the workload across multiple nodes, load
balancing enables the system to handle more requests or tasks without becoming
overloaded or experiencing bottlenecks.
iii. Availability: Load balancing can improve the availability of a distributed system by
ensuring that if one node fails or becomes unavailable, the workload can be
automatically redistributed to other nodes. This helps to prevent downtime and
ensure that the system remains operational even if some nodes are unavailable.
iv. Resource utilization: Load balancing helps to maximize resource utilization by
ensuring that all nodes are being utilized efficiently. By distributing the workload
evenly across all nodes, load balancing helps to ensure that resources, such as CPU
and memory, are being used effectively, and no nodes are being underutilized.
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

3. Types of Load Balancing algorithm in distributed systems?


i. Round Robin: Requests are distributed evenly across all nodes in a cyclic manner.
Each new request is assigned to the next available node in the list, starting from the
first node.
ii. Random: Requests are assigned to a random node in the system. This algorithm is
simple but may not distribute the workload evenly, leading to underutilization of
some nodes.
iii. Least Connection: Requests are assigned to the node with the least number of
connections. This algorithm ensures that nodes with fewer connections receive
more workload, improving resource utilization.
iv. IP Hash: The IP address of the client is used to determine which node should handle
the request. This algorithm ensures that requests from the same client are always
directed to the same node.
v. Weighted Round Robin: Each node is assigned a weight that corresponds to its
processing power. Requests are then distributed to nodes based on their weight, with
more powerful nodes receiving a greater share of the workload.
vi. Least Response Time: Requests are assigned to the node with the lowest response
time. This algorithm ensures that requests are processed quickly, improving the
overall performance of the system.
vii. Hybrid: This approach combines multiple load balancing algorithms to provide
better performance and scalability. For example, a hybrid algorithm may use a
round-robin approach for static content and a least connection algorithm for
dynamic content.

4. Issues of Load Balancing?

• Uneven Workloads: One of the primary concerns in distributed computing is the non-
uniform distribution of tasks among nodes. Certain nodes may be overloaded with tasks
while others remain idle, leading to inefficient resource utilization.
• Dynamic Workloads: Workloads in distributed systems are often dynamic and
unpredictable. The volume of incoming tasks or requests may fluctuate over time,
making it challenging to maintain an optimal balance across nodes.
• Network Latency: Distributing tasks across multiple nodes introduces network
communication overhead. Uneven network latency can impact the performance of load
balancing algorithms, as some nodes may experience delays in task execution due to
network congestion or failures.
• Heterogeneous Environments: Distributed computing environments typically consist of
nodes with varying capabilities and capacities. Load balancing algorithms must consider
these differences to allocate tasks effectively and prevent resource underutilization or
overload.
• Fault Tolerance: Load balancing mechanisms should be resilient to node failures or
network partitions. Strategies such as task replication and dynamic reassignment can help
maintain system reliability in the presence of failures.
• Scalability: As the size of the distributed system grows, the overhead associated with
load balancing becomes more significant. Load balancing algorithms should scale
efficiently to handle large numbers of nodes and tasks without introducing excessive
overhead.
• Algorithm Complexity: Designing effective load balancing algorithms requires a balance
between simplicity and performance. Complex algorithms may provide better load
balancing under certain conditions but can also introduce overhead and computational
complexity.
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

5. Steps of Load Balancing Execution?

• Monitoring: The first step in load balancing execution is to monitor the current state of the
system. This involves collecting data on resource utilization, such as CPU usage, memory usage,
and network traffic, as well as the workload distribution among nodes.
• Threshold Identification: Based on the monitored data, thresholds or criteria are established to
determine when load balancing should be triggered. These thresholds may indicate conditions
such as CPU or memory utilization exceeding a certain threshold, or the number of pending tasks
reaching a predefined limit.
• Decision Making: Once thresholds are identified, load balancing decisions need to be made. This
step involves selecting an appropriate load balancing strategy or algorithm based on the system's
current state and requirements. Common strategies include task migration, task replication, and
dynamic resource allocation.
• Task Migration or Redistribution: In this step, tasks or processes may be migrated from
overloaded nodes to underutilized nodes to achieve better load distribution. Task migration can
involve transferring the entire task state or checkpointing the task's progress and restarting it on
another node.
• Resource Provisioning: In some cases, load balancing may involve provisioning additional
resources to handle increased demand. This could include dynamically adding more compute
nodes or allocating additional storage or network bandwidth as needed.
• Implementation: After load balancing decisions are made, they need to be implemented in the
distributed computing system. This involves coordinating the migration or replication of tasks,
updating system configurations, and ensuring that any necessary adjustments are made to
maintain system stability.
• Validation and Monitoring: Once load balancing is executed, the system needs to be validated to
ensure that the desired load distribution has been achieved. Continuous monitoring is also
necessary to track the effectiveness of the load balancing decisions and make adjustments as
needed.
• Feedback and Adaptation: Load balancing is an iterative process, and feedback mechanisms are
essential for continuously improving system performance. Feedback may come from monitoring
system metrics, user feedback, or automated performance analysis tools, which can inform future
load balancing decisions and adjustments.
• Scalability and Optimization: As the system scales or evolves over time, load balancing
mechanisms may need to be optimized or adapted to accommodate changing requirements and
conditions. This could involve refining algorithms, adjusting thresholds, or deploying more
sophisticated load balancing techniques.
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

Implementation:
def allocate(servers, processes):
each = int(processes/servers)
proc_array = []
for i in range(processes):
proc_array.append(i)
# print(proc_array)
allocations = {}
for i in range(servers):
allocations[int(i)] = []
for i in range(len(allocations)):
for j in range(each):
# allocations[i].append("P"+str(proc_array.pop(0)))
if(len(proc_array) != 0):
try:

for i in range(len(allocations)):
allocations[i].append("P"+str(proc_array.pop(0)+1))
except Exception as e:
pass
return allocations
def print_allocations(allocations):
for i in range(len(allocations)):
print(f"Server {i+1} -> {allocations[i]}")
servers = int(input("Enter the initial amount of servers >>>> "))
processes = int(input("Enter the initial amount of processes >>>> "))
# Allocate
allocations = allocate(servers, processes)
print("Initial Allocation will be as shown below")
print_allocations(allocations)
c = 0
while (c != 5):
print()
print("CASES ")
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

print("1. Add servers 2. Add processes 3. Remove servers 4. Remove


processes 5. Exit")
case = int(input("Enter the case you want to execute >>>> "))
if(case == 1):
# Add New servers
new_servers = int(input( f"Enter the new amount of servers to be
added to old server count of {servers} >>>> "))
servers = servers + new_servers
allocations = allocate(servers, processes)
print("New Allocation will be as shown below")
print_allocations(allocations)
elif(case == 2):
# Add new processes

new_procs = int(input( f"Enter the new amount of processes to beadded


to old process count of {processes} >>>> "))
processes = processes + new_procs
allocations = allocate(servers, processes)
print("New Allocation will be as shown below")
print_allocations(allocations)
elif(case == 3):
# Remove servers
new_servers = int(input(f"Enter the amount of servers to be
removed from old server count of {servers} >>>> "))
servers = servers - new_servers
allocations = allocate(servers, processes)
print("New Allocation will be as shown below")
print_allocations(allocations)
elif(case == 4):
# Remove processes
new_procs = int(input(f"Enter the amount of processes to be
removed from old process count of {processes} >> >> "))
processes = processes - new_procs
allocations = allocate(servers, processes)
print("New Allocation will be as shown below")
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

print_allocations(allocations)
elif(case == 5):
c=5
break

Output:
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2
Name: Greeshma Hedvikar Roll No: 26 BE CMPN A2

You might also like