A load balancing method for distributed service state redundancy processing

By constructing hash slots and hash-based request positioning, the problem of state redundancy in distributed services is solved, load balancing and high availability are achieved, and service interruptions caused by node failures are avoided.

CN116566982BActive Publication Date: 2025-11-11ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310358413.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-06
Publication Date
2025-11-11
Estimated Expiration
2043-04-06

AI Technical Summary

Technical Problem

Existing load balancing methods cannot effectively handle state redundancy in distributed services, leading to uneven load distribution and state loss among service nodes in high-concurrency scenarios.

Method used

A load balancing method is adopted, which constructs a hash slot of size p, evenly fills the slot with service nodes, and locates the request by hash value to achieve state redundancy and ensure that other nodes can take over the work when a node fails.

Benefits of technology

It achieves uniform distribution of user requests, improves the balance of service nodes and system availability, reduces service interruption time when nodes fail, and has the ability to handle node changes consistently.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116566982B_ABST
    Figure CN116566982B_ABST
Patent Text Reader

Abstract

This invention discloses a load balancing method for handling state redundancy in distributed services. First, a hash slot of prime number is constructed, with multiple slots. Each slot stores multiple service nodes, and all service nodes are evenly distributed into the hash slot until it is full. When a request arrives, the hash value of the request's source address is moduloed to locate the request in a specific slot. A service node in any slot is randomly selected to process the request. State redundancy is achieved, with all service nodes in a slot storing the state set generated by all requests corresponding to that slot. This invention addresses the problem that traditional load balancing methods struggle to achieve state redundancy across multiple service nodes in distributed services, leading to the loss of existing state when a service node becomes inaccessible due to failure and user requests are transferred to other service nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of distributed services, and more particularly to a load balancing method for handling state redundancy in distributed services. Background Technology

[0002] Internet applications have become an integral part of people's lives. To meet requirements such as high concurrency, high availability, and high stability, monolithic services are increasingly unable to satisfy market demands, and more and more applications are adopting distributed architectures to provide services. In distributed services, multiple service nodes exist, and user requests are evenly distributed to different service nodes for processing through a certain load balancing strategy to improve system performance, scalability, and reliability. Service nodes need to maintain certain state information, including user sessions, tokens, and logs. For high availability, state redundancy is required, replicating state information across multiple nodes. When one node fails, other nodes can take over its work, thereby reducing the time the system is unable to provide service.

[0003] Current load balancing methods include hardware-based and software-based load balancing. Hardware load balancing is typically implemented using dedicated load balancing equipment; however, hardware-based load balancing cannot be aware of the state information stored at the application layer, making it difficult to achieve application-layer state redundancy. Software load balancing typically uses methods such as random, round-robin, and least-connections load balancing. Random load balancing randomly distributes requests among a group of service nodes, round-robin distributes requests among a group of service nodes in turn, and least-connections load balancing selects the service node with the fewest connections each time.

[0004] Random load balancing is affected by the random seed and the quality of random number generation, making it impossible to distribute traffic or requests evenly. Least connections load balancing requires additional maintenance of the connection count for all servers; each service node periodically sends its connection count to the load balancer, resulting in a delay in connection count statistics and causing uneven load distribution among service nodes in high-concurrency scenarios. Random load balancing and the Round Robin method lack consistency; when a node changes, the mapping of requests to that node changes significantly.

[0005] Furthermore, none of the above three methods solve the problem of state redundancy processing among multiple service nodes in a distributed service. When a service node becomes inaccessible due to a failure, user requests will be transferred to a new service node for processing. Since the new node does not store the state of the failed node, the original state will be lost.

[0006] Therefore, to address the above problems, this invention focuses on solving the issues of state redundancy handling and load balancing in distributed services, and designs a load balancing method. This method improves the balance of service nodes and the availability of services by evenly distributing user requests to different service nodes in the cluster and selecting backup service nodes among these nodes. Summary of the Invention

[0007] The purpose of this invention is to address the shortcomings of existing technologies by proposing a load balancing method for handling state redundancy in distributed services.

[0008] The objective of this invention is achieved through the following technical solution: a load balancing method for handling state redundancy in distributed services, comprising the following steps:

[0009] S1. Construct a hash slot of size p, the hash slot has multiple slots, each slot stores multiple service nodes, and all service nodes are evenly filled into the hash slot until the hash slot is full.

[0010] S2. Request Distribution: When a request arrives, the hash value of the request's source address is moduloed to locate the request in slot S. t Slot S will be randomly selected. t Any service node M i Process the request;

[0011] S3, State redundancy, a request will generate state X; slot S t All service nodes on the platform will store the set of states generated by all requests corresponding to that slot.

[0012] Furthermore, the hash slot construction step in S1 includes:

[0013] S1.1. Establish a hash slot {S0, S1, S2, ..., S} of size p, which is a prime number. p-1}, each slot S i They are all collections of service nodes, slot S i initial size |S i | is 0;

[0014] S1.2, The set of service nodes is M = {M0, M1, M2, ..., M} n-1 The state needs to be redundantly distributed across r (r≤n) nodes. For each service node M... i Calculate the integer a based on the hash value of its name and address. i and b i a serves as the seed for generating random sequences. i and b i The calculation method is as follows:

[0015] a i =f(M i .name)mod p,b i =f(M i .address)mod p

[0016] Where M i .name represents service node M i The name, M i .address represents service node M i The address of f(x) is a hash function;

[0017] S1.3, For each service node M i Assign an integer value x i Used for subsequent slot allocation, initially x i =0;

[0018] S1.4. Traverse all service nodes from left to right. For service node M... i :

[0019] S1.4.1 If x i If the value is ≥pr, then skip this service node;

[0020] S1.4.2 Calculate t=(a i +b i x i mod p, and let x i =x i +1;

[0021] S1.4.3 If 0 ≤ |S t |<r,and Then M i Add a slot;

[0022] If S1.4.4 does not satisfy S1.4.3, proceed to step S1.4.1;

[0023] When there exists 0 ≤ k < p, such that slot S k Size | S k If | < r, return S1.4;

[0024] At this time, each slot S of the hash slot... i The hash table contains r distinct nodes. Returning the hash slot terminates the algorithm.

[0025] Furthermore, the method for taking the hash value of the source address of the request is as follows: the request is located in slot S by using t = f(request.address) mod p. tWhere request.address is the source address of the request, and f(x) is a hash function.

[0026] The beneficial effects of this invention are:

[0027] (1) The present invention can distribute user requests evenly to each service node, avoiding the overload of a certain computing resource and affecting the operating efficiency and reliability of the entire system.

[0028] (2) The present invention can redundantly process the status of the service in a balanced manner across multiple nodes. When one node fails, other nodes can take over its work, thereby reducing the time when the system cannot provide services and improving the availability of the system.

[0029] (3) The present invention is consistent. If the number of service nodes changes, the hash slot changes little; correspondingly, the change in the number of service nodes is also small. Therefore, most requests will not be affected by changes in the number of service nodes. Attached Figure Description

[0030] Figure 1 This is a schematic diagram of a hash slot with an initial length of 11.

[0031] Figure 2 A schematic diagram of the hash table after the hash slots have been constructed. Detailed Implementation

[0032] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the single embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0033] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.

[0034] like Figure 1 As shown, suppose we have 5 service nodes M = {M0, M1, M2, M3, M4}, and the name and address of each service node are shown in the table below. The state needs to be redundantly distributed across 3 nodes, and the length of the hash slot is 11.

[0035] Table 1. Name and address of each service node

[0036]

[0037] (1) Initially, a hash slot of size 11 is created {S0, S1, S2, ..., S...}.10}, each slot S i It is a collection of service nodes, slot S i initial size |S i | is 0, such as Figure 1 As shown.

[0038] (2) For each service node M i Calculate the integer a based on the hash value of its name and address. i and b i a serves as the seed for generating random sequences. i and b i The calculation method is as follows:

[0039] a i =SHA256(M i .name)mod 11

[0040] b i =SHA256(M i .address)mod 11

[0041] Where M i .name represents service node M i The name, M i .address represents service node M i The address, SHM256(x), is a hash function. We calculate it for the above 5 service nodes and get the following results:

[0042] Table 2 Seeds for generating random sequences corresponding to service nodes

[0043]

[0044] (3) For each service node M i Assign an integer value x i Used for subsequent slot allocation, initially X i =0

[0045] (4) Traverse all service nodes from left to right. For service node M i :

[0046] 4.1 If x i If ≥pr=33, then skip this service node;

[0047] 4.2 Calculate t = (a i +b i x i mod 11, and let x i =x i +1;

[0048] 4.3 If 0 ≤ |S t | < 3, and Then M i Add a slot;

[0049] 4.4 If 4.3 is not met, proceed to step 4.1.

[0050] (5) When there exists 0≤k<11, such that slot S k Size | S k If | < 3, return to step (4).

[0051] (6) The hash slots are now constructed. At this point, each slot S of the hash slots is... i It contains three distinct nodes, such as Figure 2 As shown.

[0052] (7) During request distribution, assume the cluster receives a request with a source address of request.address = 183.24.53.16:24807. By calculating SHA256(request.address) mod 11, we know the request will be located in slot S2 = {M0, M1, M2}. We randomly select a service node M1 in slot S2 and distribute the request to that service node M1, which will then process the request.

[0053] (8) In order to achieve state redundancy, each of the three nodes {M0, M1, M2} will copy the state X corresponding to the request so that a replacement node can be found when a node fails.

[0054] (9) If node M1 fails, it will be removed from slot S2. When the next request is received, a node will be randomly selected from S2 = {M0, M2} to process the request.

[0055] The above embodiments are used to explain and illustrate the present invention, but not to limit the present invention. Any modifications and changes made to the present invention within the spirit and scope of the claims shall fall within the protection scope of the present invention.

[0056] The above embodiments are used to explain and illustrate the present invention, but not to limit the present invention. Any modifications and changes made to the present invention within the spirit and scope of the claims shall fall within the protection scope of the present invention.

Claims

1. A load balancing method for handling state redundancy in distributed services, characterized in that, The method includes the following steps: S1. Construct a prime number... The hash slot has multiple slots, each slot is used to store multiple service nodes, and all service nodes are evenly filled into the hash slot until the hash slot is full. The hash slot construction steps in S1 include: S1.1, Create a system with a size of prime numbers. Hash slots Each slot They are all collections of service nodes, slots initial size =0; S1.2, the set of service nodes is The state needs to be redundant. On the node, among which For each service node Calculate the integer based on the hash value of its name and address. and As a seed for generating random sequences and The calculation method is as follows: ; in Representative service node The name, Representative service node address, It is a hash function; S1.3 For each service node Assign an integer value Used for subsequent slot allocation work, initially ; S1.

4. Traverse all service nodes from left to right. For each service node... : S1.4.1 If If so, then skip this service node; S1.4.2 Calculation and order ; S1.4.3 If ,and , then Add a slot; If S1.4.4 does not satisfy S1.4.3, proceed to step S1.4.1; When it exists This makes the slot Size When that happens, return to S1.4; At this time, each slot of the hash slot It contains distinct ones The algorithm returns the hash slot for each node, and then terminates. S2. Request Distribution: When a request arrives, the hash value of the request's source address is moduloed to locate the request in the corresponding slot. ; will randomly select slots Any service node Process the request; S3. State redundancy: Requests generate states. slot All service nodes on the platform will store the set of states generated by all requests corresponding to that slot.

2. The load balancing method for handling state redundancy in distributed services according to claim 1, characterized in that, The method for obtaining the hash value of the source address of the request is as follows: through Target the slot ;in, It is the source address of the request. It is a hash function.

Citation Information

Patent Citations

  • Metadata management method and system in big data environment

    CN115665159A

  • Identity-based casting of network addresses

    US8996607B1