0. The Function of Link Load Balancing (What)#
The role of link load balancing is to distribute the traffic of internal users accessing the external network across multiple links. It's like having several routes to choose from when going home from work; link load balancing can help us select the fastest route home to relax after work, or the route with the best scenery, or even the route with barbecue spots.
From a functional perspective, we can see the scenarios for link load balancing:
For enterprises, using multiple exit links can prevent the impact of a single exit link failure on company operations and can also avoid slow access to resources across ISPs.
1. Why Do We Need Link Load Balancing (Why)#
As mentioned above, the main function of link load balancing is route selection, and routing is also responsible for route selection in the network. Additionally, routing can also apply equivalent static routing and policy routing to multiple exit links. So why do we still need link load balancing?
Equivalent Static Routing and Policy Routing#
To answer this question, we first need to define the concepts of equivalent static routing and policy routing:
Equivalent Static Routing: Manually configured static routes with the same destination, the same priority, and different next hops. During data forwarding, one of the static routes is randomly selected;
Policy Routing: Manually configured routing that can match multi-dimensional information such as four-tuples, roles, ISPs, applications, domain names, etc., and selects routes among multiple next hops based on different routing algorithms.
From the concepts of equivalent static routing and policy routing, we can see that both can perform multi-exit routing, and policy routing has more powerful functions, achieving capabilities closer to link load balancing. However, the drawbacks of both are also evident: the policies are static, while links are dynamic.
Link Load Balancing#
Links have the concept of health status. In a dynamic network environment, links may fail, become congested, or encounter various unexpected situations. The need for link load balancing arises from this, as static routing policies cannot perceive the dynamic changes of links. Therefore, an enhanced policy is needed, under the premise of routing matching, to dynamically select routes based on the status of the links.
Link load balancing is an enhancement of routing functionality, relying on the results of routing matching.
2. What Should Link Load Balancing Achieve (How)#
To achieve link load balancing, we first need to organize its characteristics:
- Maintenance of basic link information: outgoing interface, next hop, ISP, bandwidth, priority, weight, health status, etc.;
- Link status awareness:
- Interface status: enabled, disabled, new IP, deleted IP, type as routing port, switching port...
- Link status: related to the destination, packet loss rate, bandwidth, load...
- Link pool: a collection of links, which is the selection range for load balancing;
- Link load balancing algorithms: random, round-robin, weighted round-robin, priority, load rate, nearest route selection...
- In addition to the above characteristics, considering the situation where multiple connections from the client to the server are NATed to different IPs, which may be considered an attack by the server and blocked, it is necessary to perform link selection based on sessions with the same characteristics (such as four-tuples) within a specific time, known as "session persistence."
Link Status Awareness#
- Monitor interface status
- Use protocols like ping to perceive link status
Excessive awareness of link status is not recommended, as it can consume link bandwidth and server resources. Typically, traffic statistics can be used to calculate link load rate information, combined with interface status monitoring.
Link Load Balancing Algorithms#
Random#
Select one link from the normal links using a hash algorithm; if none are available, randomly select from overloaded links.
Round-Robin#
Select one link in order from the normal links; if none are available, select in order from overloaded links.
Weighted Round-Robin#
Distribute connections to the normal link list based on weight ratios. If none are available, select one from overloaded links using weighted round-robin.
The principle of weighting is essentially to simulate the selection of a link based on weight each time, then decrement the weight of that link, and for the next simulation, select based on the new weights, ultimately generating a route selection list. During actual routing, this selection list is then polled. For example, if there are links a:2, b:4, c:1, the simulated selection list based on weight would be: {b, b, a, b, a, b, c}, and the actual selection would be made by polling this list.
Priority#
Select one link from the normal link list based on priority; if none are available, select one from overloaded links based on priority.
Load Rate#
Calculate the load rate based on the ratio of link traffic to link bandwidth, selecting the link with the minimum load.
Nearest Route Selection#
Query the ISP information database based on the destination IP to find the ISP of the destination and select the link for that ISP. This can be combined with other algorithms for further load balancing of the selection results.
Session Persistence#
Establish a session persistence table based on the four-tuple and routing results, with items in the session persistence table expiring at regular intervals. When a new connection arrives, check the session persistence table; if a match is successful, update the expiration time of the session persistence table; if no match is found, add a new entry to the session persistence table.
Done!
This article is synchronized and updated to xLog by Mix Space. The original link is https://www.vikifish.com/posts/network/linklb