loadbalancing-algorithms
Load Balancing Algorithms
Round Robin (RR)
Description: Distributes incoming requests sequentially across the available servers. Each new request goes to the next server in the list.
Advantages:
Simple to implement.
Provides a basic, even distribution if all servers have similar capacity.
Disadvantages:
Doesn’t consider current server load or performance differences.
Weighted Round Robin (WRR)
Description: Similar to Round Robin but assigns a weight to each server. Servers with higher weights receive a proportionally higher number of requests.
Advantages:
Accounts for differences in server capacity.
Disadvantages:
Weights are usually static and may not adapt to dynamic load changes.
Least Connections (LC)
Description: Directs requests to the server with the fewest active connections. This dynamic method adapts to varying loads in real time.
Advantages:
Can better balance load when connection durations vary.
Disadvantages:
Doesn’t always account for the processing power or performance of each server.
Weighted Least Connections (WLC)
Description: A variation of Least Connections that factors in both the current connection count and server weights.
Advantages:
Provides more nuanced load distribution by considering server capacity.
Disadvantages:
Weight configuration remains static unless updated manually.
Source Hashing (SH)
Description: Uses a hash of the client’s IP address to determine which server should handle the request. This maintains session persistence by sending the same client to the same server.
Advantages:
Good for session stickiness.
Disadvantages:
May result in uneven load distribution if client IPs are not uniformly distributed.
Destination Hashing (DH)
Description: Uses a hash of the destination IP (or port) to consistently map requests to a specific server.
Advantages:
Useful when session persistence is needed based on the destination.
Disadvantages:
Similar limitations to source hashing regarding load distribution.
Shortest Expected Delay (SED)
Description: Selects the server with the lowest expected delay by evaluating both current load and server performance.
Advantages:
Aims to minimize response time.
Disadvantages:
More complex to implement, as it requires real-time performance monitoring.
Least Response Time (LRT)
Description: Directs traffic to the server with the lowest average response time, which is determined over a moving time window.
Advantages:
Dynamic and responsive to changes in server performance.
Disadvantages:
Requires additional metrics collection and processing overhead.
Summary Table
Algorithm
Pros
Cons
Round Robin (RR)
Simple, even distribution with similar servers.
Doesn’t consider server load differences.
Weighted RR (WRR)
Adjusts for different server capacities.
Static weights may not reflect real-time load.
Least Connections (LC)
Dynamically adapts to current active connections.
Ignores differences in server performance.
Weighted LC (WLC)
Considers both load and server capacity.
Static weights can limit adaptability.
Source Hashing (SH)
Maintains session persistence.
May lead to imbalanced loads.
Destination Hashing (DH)
Similar benefits as source hashing.
Potential for uneven load distribution.
Shortest Expected Delay (SED)
Minimizes delay by considering performance.
Higher complexity and overhead.
Least Response Time (LRT)
Dynamically routes to fastest server.
Requires continuous monitoring of response times.
Conclusion
Choosing the right load balancing algorithm depends on the specific requirements of your system:
Round Robin or Weighted Round Robin are excellent for simple scenarios where servers are homogenous.
Least Connections and Weighted Least Connections work better in environments with varying connection durations.
Hashing-based methods (Source or Destination) are ideal for maintaining session persistence.
Dynamic methods like Shortest Expected Delay or Least Response Time provide more responsive load distribution at the cost of increased complexity and monitoring overhead.
Both HAProxy and LVS offer support for many of these algorithms, and selecting the optimal one can significantly improve performance and resource utilization in high-availability environments.
For further details, you may refer to the official HAProxy and LVS documentation
Last updated