What are the common load balancing algorithms?
Load balancing reasonably allocates network traffic or a set of tasks to each processing node in a certain algorithm, so that the nodes can be used equally, and the results are returned to users in a timely and reliable manner.
Load balancing is widely used in various hardware and software systems, such as:
Load balance network traffic based on IP address. While the service is being maintained, it is convenient to switch network traffic to a temporary node or a degraded service. Application load balancing based on HTTP header information or request fields reduces the time for users to get a response, and can provide hierarchical services, and also facilitate the addition of new nodes when the service scales out. CDNs direct traffic to servers in adjacent regions based on the traffic's ** for shorter response times and higher availability. The following diagram shows 6 common algorithms.
Round robin client requests are sent sequentially to different service instances. Usually the required service is:StatelessTarget. This algorithm is the simplest, but it also can't handle cases where a node slows down or there is continuity in client operations.
Sticky round robin: This is an improvement on the loop algorithm. If Alice's first request is sent to Service A, subsequent requests are also sent to Service A. This load balancing ensures that all requests from a user are destined for the same service node, which is suitable for client operationsThere is continuitysituation. Sometimes, some of the user's state will be saved on the service node to avoid querying the backend database.
Weighted round robin administrators can specify the weight of each service. A service with a high weight will handle more requests than the other service.
Hashing (IP URL Hash): This algorithm applies a hash function to the IP or URL of an incoming request. Based on the result of the hash function, the request is routed to the relevant service.
Least connections: New requests are sent toMinimal concurrent connectionsnodes.
Least time new requests are sent toFastest response timenodes. This way, a service node slowing down won't block subsequent request processing.