Load balancing method and load balancer

By using hash functions on hash rings in the server cluster to calculate and virtual node allocation, the performance bottleneck problem of load balancing in large-scale server clusters is solved, and more efficient load balancing and performance improvement is achieved.

CN120301892APending Publication Date: 2025-07-11HENAN QINWEI DIGITAL TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510525428.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-24
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

When the server cluster is large, load balancing methods based on algorithms such as polling may cause the addressing system to become a performance bottleneck, unable to effectively realize load balancing, and reducing the performance of the entire server cluster.

Method used

By receiving the connection request from the terminal, the hash value of the identification information is calculated using the preset hash function, and the target virtual node is determined on the pre-established hash ring, and the connection request is allocated to the corresponding server node according to the preset direction. The hash ring contains multiple virtual nodes to evenly distribute the server load.

Benefits of technology

Effectively prevent server overload, realize load balancing, improve server cluster performance, reduce terminal polling and addressing time and save computing power.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120301892A_ABST
    Figure CN120301892A_ABST
Patent Text Reader

Abstract

The invention relates to a load balancing method and a load balancer, and the method comprises the steps: receiving a connection request sent by a terminal, the connection request carrying the identification information of the terminal; calculating a hash value corresponding to the identification information through a preset hash function; obtaining the corresponding position of the Hash value on a pre-established Hash ring, and obtaining a target virtual node closest to the position on the Hash ring according to a preset direction; and distributing the connection request to a server node corresponding to the target virtual node. The Hash ring comprises a plurality of virtual nodes respectively corresponding to each server node, and the plurality of virtual nodes are distributed on the Hash ring in a Hash mode. When one server node goes wrong due to overload, all the connection requests on the server node cannot be distributed to the same server node, so that the problems caused by overload of a large number of servers can be effectively prevented, load balancing can be effectively realized, and the performance of the server cluster can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of load balancing, and in particular, to a load balancing method and a load balancer. Background Art

[0002] With the increasing development of Internet technology, in order to improve the load capacity of the system when providing services to clients, a load balancing method is usually adopted. Load balancing means evenly distributing network requests to different servers for processing to avoid the situation where some servers are under excessive pressure while some servers are relatively idle.

[0003] In the case of the continuous increase in the number of users, related technologies will expand the scale of the server cluster through an addressing mechanism. However, when the scale of the server cluster is large, algorithms such as round-robin may cause the addressing system itself to become a performance bottleneck, making it impossible to effectively achieve load balancing, and further reducing the performance of the entire server cluster. Summary of the Invention

[0004] The present disclosure provides a load balancing method and a load balancer.

[0005] According to a first aspect of the present disclosure, there is provided a load balancing method, the method comprising:

[0006] Receiving a connection request sent by a terminal, the connection request carrying identification information of the terminal;

[0007] Calculating a hash value corresponding to the identification information through a preset hash function;

[0008] Obtaining a position corresponding to the hash value on a pre-established hash ring, and obtaining a target virtual node on the hash ring that is closest to the position in a preset direction; wherein, the hash ring includes a plurality of virtual nodes, the plurality of virtual nodes are distributed on the hash ring through a hash mapping method, each virtual node corresponds to a server node, each server node corresponds to a plurality of virtual nodes, and the number of server nodes includes a plurality;

[0009] Allocating the connection request to the server node corresponding to the target virtual node.

[0010] In an embodiment of the present disclosure, a connection request containing identification information sent by a terminal is received, and a hash value corresponding to the identification information is calculated. By obtaining the position corresponding to the hash value on a pre-established hash ring, and obtaining the target virtual node closest to the position on the hash ring in a preset direction, the connection request is allocated to the server node corresponding to the target virtual node. Since the hash ring contains multiple virtual nodes respectively corresponding to each server node, and these multiple virtual nodes are distributed on the hash ring by means of hashing. When a problem occurs due to overload in one of the server nodes, it will not cause all connection requests on that server node to be allocated to the same server node, but rather be relatively dispersedly allocated to other server nodes, which can effectively prevent problems caused by overload of a large number of servers, can effectively achieve load balancing, and thus can improve the performance of the server cluster.

[0011] Optionally, the obtaining the target virtual node closest to the position on the hash ring in a preset direction includes:

[0012] Obtaining a target hash value interval corresponding to the hash value on the hash ring; wherein, each virtual node on the hash ring corresponds to a hash value, and multiple hash value intervals are formed between the hash values respectively corresponding to the multiple virtual nodes on the hash ring;

[0013] Obtaining the endpoint hash values of the target hash value interval in the preset direction, and using the virtual node corresponding to the endpoint hash values as the target virtual node.

[0014] The embodiment can determine the target interval on the hash ring through the hash calculation of the terminal identification information, and then can determine the server node that needs to process the connection request, which can reduce the time-consuming caused by terminal polling addressing and can save computing power.

[0015] Optionally, the method further includes:

[0016] When a first virtual node is newly added to the hash ring, disconnecting the connection request between the first virtual node and a second virtual node; wherein, the second virtual node is the virtual node adjacent to the first virtual node in the opposite direction of the preset direction on the hash ring;

[0017] Reallocating the disconnected connection request to the service node corresponding to the first virtual node.

[0018] In the embodiment, when a virtual node is newly added, only those connection requests that were originally between the newly added virtual node and the next node in its counterclockwise or clockwise direction will be reallocated, which can minimize the impact on existing connections.

[0019] Optionally, the method further includes:

[0020] Obtain the number of virtual nodes on the hash ring;

[0021] When the number is greater than a first threshold, disconnect the connection relationship between the server nodes corresponding to the respective virtual nodes on the hash ring and each terminal;

[0022] Re-determine the positions of the respective virtual nodes on the hash ring, and re-establish the connection relationship between the server nodes corresponding to the respective virtual nodes on the hash ring and each terminal.

[0023] In the embodiment, when the number of virtual nodes on the hash ring is greater than the first threshold, the connections between the terminals and the server nodes on the entire hash ring will be disconnected, and all the virtual nodes on the hash ring will be re-sorted so that these virtual nodes are evenly distributed on the hash ring to achieve load balancing.

[0024] Optionally, the method further includes:

[0025] When adding a first server node, generate a plurality of virtual nodes corresponding to the first server node;

[0026] Based on the identification information corresponding to the respective virtual nodes of the first server node, map the plurality of virtual nodes of the first server node to the hash ring.

[0027] In the embodiment, when adding a first server node, a plurality of virtual nodes corresponding to the first server node can be generated. In this way, based on the identification information corresponding to the respective virtual nodes of the first server node, the plurality of virtual nodes of the first server node can be mapped to the hash ring.

[0028] Optionally, the method further includes:

[0029] When removing a third virtual node on the hash ring, disconnect the connection request of the server node corresponding to the third virtual node;

[0030] Re-allocate the disconnected connection request to the server node corresponding to a fourth virtual node; wherein, the fourth virtual node is an adjacent virtual node of the third virtual node in the preset direction on the hash ring.

[0031] In the embodiment, when reducing a virtual node, only those connection requests that were originally between the newly added virtual node and the next node in its counterclockwise or clockwise direction will be re-allocated, so as to reduce the impact on the existing connections.

[0032] Optionally, the method further includes:

[0033] Obtain the number of virtual nodes on the hash ring;

[0034] When the quantity is less than the second threshold, disconnect the connections between the server nodes corresponding to the respective virtual nodes on the hash ring and each terminal;

[0035] Re-determine the positions of the respective virtual nodes on the hash ring, and re-establish the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and each terminal.

[0036] In the embodiment, by obtaining the quantity of virtual nodes on the hash ring, when the quantity is less than the second threshold, disconnect the connections between the server nodes corresponding to the respective virtual nodes on the hash ring and each terminal. Re-determine the positions of the respective virtual nodes on the hash ring, and re-establish the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and each terminal. In this way, when the quantity of virtual nodes on the hash ring is less than the second threshold, disconnect the connections between the terminals and the server nodes on the entire hash ring, and re-order all the virtual nodes on the hash ring so that these virtual nodes are evenly distributed on the hash ring, so that the connection relationships between the terminals and the server nodes can be re-established according to the re-ordered hash ring.

[0037] Optionally, the method further includes:

[0038] When reducing the second server node, obtain the virtual nodes corresponding to the second server node on the hash ring;

[0039] Remove the virtual nodes corresponding to the second server node from the hash ring.

[0040] In the embodiment, when reducing the second server node in the server node cluster, the virtual nodes corresponding to the second server node on the hash ring can be obtained, and the virtual nodes corresponding to the second server node are removed from the hash ring. In this way, by timely removing the virtual nodes corresponding to the server nodes that do not provide services on the hash ring, the situation of connection request allocation failure can be avoided to improve the efficiency of load balancing.

[0041] Optionally, the method further includes:

[0042] Obtain the weights of the multiple server nodes respectively, where the weights are positively correlated with the load capabilities of the server nodes;

[0043] Based on the weights, determine the quantities of the virtual nodes mapped by the multiple server nodes on the hash ring respectively.

[0044] In the embodiments provided by the present disclosure, the weights of multiple server nodes can be obtained respectively, and the number of virtual nodes mapped by the multiple server nodes on the hash ring can be determined based on the weights. In the embodiments, the number of virtual nodes corresponding to each server node can be determined according to the load capacity of the server node. The greater the load capacity, the more the corresponding number of virtual nodes can be; the smaller the load capacity, the fewer the corresponding number of virtual nodes can be. In this way, the server node with a higher load capacity can process more connection requests, and the server node with a lower load capacity can reduce the connection requests to be processed, and load balancing can be better achieved.

[0045] According to a second aspect of the present disclosure, there is provided a load balancing device, the device comprising:

[0046] A connection request receiving module, configured to receive a connection request sent by a terminal, where the connection request carries identification information of the terminal;

[0047] A hash calculation module, configured to calculate a hash value corresponding to the identification information through a preset hash function;

[0048] A target virtual node determination module, configured to obtain a position corresponding to the hash value on a pre-established hash ring, and obtain a target virtual node closest to the position on the hash ring in a preset direction; wherein, the hash ring includes multiple virtual nodes, the multiple virtual nodes are distributed on the hash ring by means of hash mapping, each virtual node corresponds to a server node, each server node corresponds to multiple virtual nodes, and the number of the server nodes includes multiple;

[0049] A server node allocation module, configured to allocate the connection request to the server node corresponding to the target virtual node.

[0050] According to a third aspect of the present disclosure, there is provided a load balancer. The load balancer includes: a memory and a processor, where a computer program is stored on the memory, and when the processor executes the program, the method as described above is implemented.

[0051] According to a fourth aspect of the present disclosure, there is provided a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the above method of the present disclosure is implemented.

[0052] According to a fifth aspect of the present disclosure, there is provided a computer program product, including a computer program, and when the computer program is executed by a processor, the above method of the present disclosure is implemented. Description of the Drawings

[0053] In the following description of the exemplary embodiments in conjunction with the drawings, more details, features and advantages of the present disclosure are disclosed. In the drawings:

[0054] Figure 1 System architecture diagram provided for an exemplary embodiment of the present disclosure;

[0055] Figure 2 Schematic diagram of server node selection provided for an exemplary embodiment of the present disclosure;

[0056] Figure 3 Schematic diagram of server node addition provided for an exemplary embodiment of the present disclosure;

[0057] Figure 4 Schematic diagram of server node reduction provided for an exemplary embodiment of the present disclosure;

[0058] Figure 5 Flowchart of the load balancing method provided for an exemplary embodiment of the present disclosure;

[0059] Figure 6 Schematic block diagram of the functional modules of the load balancing device provided for an exemplary embodiment of the present disclosure;

[0060] Figure 7 Structural block diagram of the electronic device provided for an exemplary embodiment of the present disclosure;

[0061] Figure 8 Structural block diagram of the computer system provided for an exemplary embodiment of the present disclosure. Detailed implementation manners

[0062] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.

[0063] It should be understood that the steps recorded in the method embodiments of the present disclosure can be executed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this regard.

[0064] As used herein, the term "including" and its variations are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description. It should be noted that the concepts such as "first", "second", etc. mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0065] It should be noted that the modification of "one" and "multiple" mentioned in this disclosure is illustrative rather than restrictive. Those skilled in the art should understand that, unless otherwise clearly specified in the context, it should be understood as "one or more".

[0066] The names of the messages or information exchanged between multiple devices in the embodiments of this disclosure are only for illustrative purposes and are not used to limit the scope of these messages or information.

[0067] It can be understood that before using the technical solutions disclosed in the embodiments of this disclosure, the types, usage scopes, usage scenarios, etc. of the personal information involved in this disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0068] For example, when receiving the user's active request, a prompt message is sent to the user to clearly prompt the user that the operation requested by the user will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, an application program, a server, or a storage medium that performs the operations of the technical solutions of this disclosure according to the prompt message.

[0069] As an optional but non-limiting implementation manner, the manner of sending a prompt message to the user in response to receiving the user's active request can be, for example, in the form of a pop-up window. The prompt message can be presented in text in the pop-up window. In addition, the pop-up window can also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device. It can be understood that the above notification and obtaining user authorization process is only illustrative and does not limit the implementation manner of this disclosure. Other manners that meet relevant laws and regulations can also be applied to the implementation manner of this disclosure.

[0070] In the embodiments provided by this disclosure, as Figure 1 shown, Figure 1 is a system architecture diagram provided for an exemplary embodiment of this disclosure. The system can include a terminal 10, a load balancer 20, and a server cluster 30.

[0071] The terminal 10, which can be located in the corresponding terminal, is used to send a connection request to the load balancer 20. The connection request can be used to access network resources, or for instant messaging or real-time voting, etc. The embodiments are not limited thereto.

[0072] The load balancer 20 is configured to receive the connection request sent by the terminal 10, and according to the identification information of the terminal 10 in the connection request, calculate the hash value corresponding to the identification information by using a corresponding hash function. And map the hash value to a pre-established hash ring to obtain the position corresponding to the hash value on the hash ring.

[0073] In an embodiment, a hash ring can be pre-established. The hash ring includes multiple virtual nodes, and each virtual node corresponds to a server node. The number of server nodes is multiple. Each server node can map multiple virtual nodes on the hash ring. These multiple virtual nodes respectively mapped to the hash ring by multiple server nodes will be evenly distributed on the hash ring. In this way, according to the received connection request, the load balancer 20 maps the terminal 10 to the corresponding position on the hash ring, and can find the virtual node closest to this position in the clockwise direction, and allocate the connection request to the server node corresponding to the virtual node for processing. Among them, the hash value corresponding to the node identifier of each virtual node can be calculated, and the virtual node is mapped to the hash ring. The hash ring is a logically awakened structure, and the virtual nodes on the hash ring are sorted according to the hash value.

[0074] As Figure 2 shown, Figure 2 is a schematic diagram of server node selection provided in an embodiment of the present disclosure. Combining Figure 2 shown, for example, the above server cluster 30 includes three server nodes, namely server node A, server node B, and server node C. Server node A includes 4 virtual nodes, which are respectively represented by A1, A2, A3, and A4 when mapped to the hash ring. Server node B includes 2 virtual nodes, which are respectively identified by B1 and B2 when mapped to the hash ring. Server node C includes 2 virtual nodes, which are respectively identified by C1 and C2 when mapped to the hash ring. Among them, the hash ring is a circular ring from 0 to the maximum hash value.

[0075] Combining Figure 2 shown, the load balancer 20 can receive the connection request sent by the terminal 10, and the connection request can carry the identification information of the terminal 10. The load balancer 20 can calculate the hash value of the identification information through a preset hash function. Since different positions on the hash ring respectively correspond to hash values, in this way, the hash value corresponding to the identification information can map the terminal 10 to the corresponding position on the hash ring, as Figure 2X in it is the mapping position of the terminal 10 on the hash ring.

[0076] In the embodiment, through Figure 2 the virtual nodes adjacent to X can be determined, namely virtual node B1 and virtual node A2. Among them, virtual node B1 is located in the counterclockwise direction of X on the hash ring, and virtual node A2 is located in the clockwise direction of X on the hash ring. The embodiment can obtain the virtual node closest to X on the hash ring in the clockwise or counterclockwise direction as needed. For example, the virtual node A2 closest to X on the hash ring can be obtained in the clockwise direction, so that the access request sent by the terminal 10 can be processed by the server node A corresponding to the virtual node A2.

[0077] In the embodiment, as the load balancer 20 receives access requests sent by multiple different terminals, the load balancer 20 can calculate the corresponding hash values according to the identification information of the multiple different terminals, and can evenly map the multiple different terminals onto the hash ring. By respectively determining the virtual node closest to each terminal on the hash ring in the counterclockwise or clockwise direction, and accessing the connection request sent by the corresponding terminal through the server node corresponding to the virtual node, the load balancing of the server can be effectively realized, and thus the performance of the server cluster can be improved.

[0078] In the embodiment, in combination with Figure 2 as shown, when mapping the virtual nodes corresponding to the above server node A, server node B, and server node C onto the hash ring, for each actual node, such as server node A, server node B, and server node C, the hash values of their corresponding virtual nodes can be calculated respectively. This can be achieved by adding the virtual node serial number to the identifier (such as IP address or host name) of the actual node and then using the hash function to calculate its hash value. For example, for the 4 virtual nodes A1, A2, A3, and A4 corresponding to server node A, they can be respectively represented by the following identifiers, namely "NodeA#1", "NodeA#2", "NodeA#3", and "NodeA#4". In this way, the hash values of "NodeA#1", "NodeA#2", "NodeA#3", and "NodeA#4" can be calculated respectively. In this way, the hash values of the virtual nodes corresponding to server node B and server node C can be obtained respectively, and through modulo operation on these hash values, these hash values are mapped onto the hash ring.

[0079] In the embodiment, by mapping the virtual nodes corresponding to the above server node A, server node B, and server node C onto the hash ring respectively, and through modulo operation on the hash values corresponding to these virtual nodes respectively, it can be realized Figure 2The 8 virtual nodes in it are evenly distributed on the hash ring. In this way, there will be multiple virtual nodes on the hash ring, and each virtual node has a unique hash value.

[0080] It should be noted that when calculating the hash value through the hash function in the above embodiments, hash functions such as MD5 or SHA-1 can be used, and the embodiments are not limited thereto. When calculating the hash value based on the identifier of the terminal 10, the hash function used needs to be the same as when calculating the hash value based on the identifier of the virtual node. For example, when selecting a hash function, if considering performance, MD5 or the like can be selected, and the embodiments are not limited thereto.

[0081] Combined with Figure 2 As shown, when the load balancer 20 receives a connection request sent by the terminal 10, the load balancer 20 will calculate the hash value of the terminal identifier through the above hash function and map it to the hash ring. It can pass through Figure 2 X in it represents the mapping of this terminal on the hash ring. At this time, the nearest virtual node A2 can be found in the clockwise direction. This virtual node A2 corresponds to the server node A. At this time, this connection request can be connected to the server node A, and this connection request is processed by the server node A.

[0082] In the embodiment, combined with Figure 2 As shown, the hash ring can be divided into multiple intervals according to the positions of the virtual nodes on the hash ring. Different intervals on the hash ring correspond to different ranges of hash values. In this way, when the load balancer 20 receives a connection request sent by the terminal 10, by calculating the corresponding hash value based on the identifier of the terminal 10, it can be determined which interval on the hash ring this hash value will fall into. For example, when it falls into the interval from B1 to A2, the nearest virtual node A2 can be found in the clockwise direction, and this connection request can be allocated to the server node A.

[0083] Through the hash calculation of the identifier of the terminal 10, it is determined that it will fall into the corresponding interval on the hash ring, and then the server node that needs to process the connection request sent by the terminal 10 can be determined, which can reduce the time-consuming caused by the terminal polling for addressing and reduce the computing power.

[0084] In the embodiments provided by the present disclosure, the number of server nodes in the server cluster 30 can be increased or decreased according to the load condition of the server cluster 30. For example, when the load in the server cluster 30 increases, the number of server nodes in the server cluster 30 can be increased accordingly; when the load in the server cluster 30 decreases, the number of server nodes in the server cluster 30 can be decreased accordingly.

[0085] When the number of server nodes in the server cluster 30 increases, since each server node can correspond to multiple virtual nodes, multiple virtual nodes will correspondingly be added to the hash ring at this time. This requires reallocating some of the connection requests accessed on the hash ring to different servers.

[0086] Exemplarily, when adding a server node D to the server cluster, if this server node D corresponds to two virtual nodes D1 and D2, then two virtual nodes will be correspondingly added to the hash ring. As Figure 3 shown, Figure 3 is a schematic diagram of adding a server node provided by an embodiment of the present disclosure. Originally, the connection requests between B1 and D were allocated to the virtual node A2. At this time, these connection requests need to be disconnected from the server node A corresponding to the virtual node A2 and reallocated to the virtual node D1, that is, these connection requests are re-accessed through the server node D. This will affect the connection requests falling within the interval B1 to D1, but will not affect the connection requests falling within the interval D1 to A2.

[0087] Therefore, originally the connection requests in the interval B1 to D1 were allocated to the server node A. At this time, these connection requests need to be disconnected from the server node A and reallocated to the server node D, which can reduce the load pressure on the server node A.

[0088] When adding a new virtual node, only those connection requests that were originally located between the newly added virtual node and the next node in its counterclockwise or clockwise direction will be reallocated. Therefore, when adding a new server node to the server cluster 30, the embodiment can minimize the impact on existing connections.

[0089] Exemplarily, when reducing a server node A in the server cluster, multiple virtual nodes of the server node A on the hash ring will also be removed. As Figure 4 shown, Figure 4 is a schematic diagram of reducing a server node provided by an embodiment of the present disclosure. At this time, Figure 4 the connection requests originally allocated to the virtual node A2 will also be reallocated to the virtual node C1, that is, this connection request will be disconnected from the server node A and re-accessed through the server node C. This will affect the connection requests falling within the interval B1 to A2, but will not affect the connection requests falling within the interval A2 to C1. The connection requests originally in the interval B1 to A2 were allocated to the virtual node A2 and processed by the server node A. At this time, these connection requests need to be disconnected from the server node A and reallocated to the virtual node C1, and re-accessed through the server node C.

[0090] Therefore, when reducing server nodes in the server cluster 30, the embodiments can minimize the impact on existing connections. When reducing a virtual node, only those connection requests that were originally between the newly added virtual node and the next node in its counterclockwise or clockwise direction will be reallocated, so as to reduce the impact on existing connections.

[0091] It should be noted that the number of virtual nodes corresponding to each server node in the embodiments can be determined according to the load capacity of the server node. The greater the load capacity, the more virtual nodes can be corresponding; the smaller the load capacity, the fewer virtual nodes can be corresponding. Therefore, the number of virtual nodes corresponding to a server node is positively correlated with the load capacity of the server node.

[0092] In the embodiments, as the number of server nodes in the server cluster 30 continuously increases or decreases, the number of corresponding virtual nodes on the hash ring may change greatly, making the virtual nodes on the hash ring unable to be evenly distributed on the hash ring, resulting in a large load pressure on some server nodes, while some server nodes are relatively idle, thereby affecting the efficiency of load balancing.

[0093] Therefore, in the embodiments, the number of virtual nodes on the hash ring can be counted. When the number of virtual nodes on the hash ring is greater than the first threshold, or when the number of virtual nodes on the hash ring is less than the second threshold, the connections between the terminals and the server nodes on the entire hash ring are disconnected, and all the virtual nodes on the hash ring are re-sorted so that these virtual nodes are evenly distributed on the hash ring. In this way, the connection relationship between the terminals and the server nodes can be re-established according to the re-sorted hash ring. Specifically, the connection requests can be re-allocated to the corresponding server nodes in the manner of the above embodiments, which will not be elaborated here.

[0094] Based on the above, the embodiments of the present disclosure further provide a load balancing method, which can be applied to the load balancing in the above embodiments, such as Figure 5 shown, the method may include the following steps:

[0095] In step S510, a connection request sent by a terminal is received. Among them, the connection request carries the identification information of the terminal.

[0096] In the embodiments, the load balancer can receive the connection requests sent by each terminal. The connection request can be used to access network resources, or for instant messaging or real-time voting, etc., and the embodiments are not limited thereto. Among the connection requests received by the load balancer, the identification information of the terminal will be carried, such as the ID (identity document, identity number) of the terminal, etc.

[0097] In step S520, calculate the hash value corresponding to the identification information through a preset hash function.

[0098] In the embodiment, the preset hash function can select an existing hash function as needed, such as MD5 or SHA-1, etc., and the embodiment is not limited thereto.

[0099] In step S530, obtain the position corresponding to the hash value on the pre-established hash ring, and obtain the target virtual node closest to the position on the hash ring in a preset direction.

[0100] Among them, the hash ring includes multiple virtual nodes. The multiple virtual nodes are distributed on the hash ring through hash mapping. Each virtual node corresponds to a server node, each server node corresponds to multiple virtual nodes, and the number of server nodes includes multiple. In addition, in the embodiment, the preset direction can be the clockwise direction or the counterclockwise direction.

[0101] Combined Figure 2 As shown, for example, there are three actual server nodes: server node A, server node B, and server node C. Among them, server node A includes 4 virtual nodes, which are mapped to the hash ring as A1, A2, A3, and A4 respectively. Server node B includes 2 virtual nodes, which are mapped to the hash ring as B1 and B2 respectively. Server node C includes 2 virtual nodes, which are mapped to the hash ring as C1 and C2 respectively.

[0102] In the embodiment, calculate the hash value corresponding to the identification information of the terminal through a preset hash function, and map the hash value to the hash ring, such as Figure 2 X in. In this way, along the clockwise direction for example, the virtual node A2 closest to X can be found, and A2 is the target virtual node.

[0103] In step S540, allocate the connection request to the server node corresponding to the target virtual node.

[0104] In the embodiment, after determining the target virtual node on the hash ring, the server node corresponding to the target virtual node can be obtained, and the connection request sent by the terminal is allocated to the server node for processing. For example, Figure 2 if the target virtual node in is A2, and the corresponding actual server node is server node A, then the load balancer can allocate the connection request to server node A.

[0105] In an embodiment of the present disclosure, a connection request including identification information sent by a terminal is received, and a hash value corresponding to the identification information is calculated. By obtaining the position corresponding to the hash value on a pre-established hash ring, and obtaining the target virtual node closest to the position on the hash ring in a preset direction, the connection request is allocated to the server node corresponding to the target virtual node. Since the hash ring contains multiple virtual nodes respectively corresponding to each server node, and these multiple virtual nodes are distributed on the hash ring by means of hashing. When a problem occurs in one of the server nodes due to overload, it will not cause all connection requests on the server node to be allocated to the same server node, and thus it can largely prevent problems caused by overload in a large number of servers, can effectively achieve load balancing, and thus can improve the performance of the server cluster.

[0106] Based on the above embodiment, in another embodiment provided by the present disclosure, the above step S530 may specifically further include the following steps:

[0107] In step S531, obtain the target hash value interval corresponding to the hash value on the hash ring.

[0108] Wherein, each virtual node on the hash ring corresponds to a hash value, and multiple hash value intervals are formed between the hash values respectively corresponding to the multiple virtual nodes on the hash ring.

[0109] In step S532, obtain the endpoint hash values of the target hash value interval in the preset direction, and use the virtual node corresponding to the endpoint hash value as the target virtual node.

[0110] In the embodiment, the hash ring can be divided into multiple intervals according to the positions of the virtual nodes on the hash ring, and different intervals on the hash ring respectively correspond to different ranges of hash values. In this way, when the load balancer receives a connection request sent by a terminal, by calculating the corresponding hash value based on the identification information of the terminal, it can be determined that the hash value will fall within the target interval on the hash ring. In this way, the endpoint hash values of the target hash value interval in the preset direction can be obtained, and the virtual node corresponding to the endpoint hash value can be used as the target virtual node.

[0111] For example, as shown in Figure 2 , when the calculated hash value falls within the target interval from B1 to A2, the virtual node A2 closest to this position can be found in the clockwise direction, and the connection request can be allocated to the corresponding server node A.

[0112] In this way, through the hash calculation of the terminal identification information, the target interval on the hash ring is determined, and then the server node that needs to process the connection request can be determined, which can reduce the time-consuming caused by terminal polling for addressing and can save computing power.

[0113] Based on the above embodiments, in another embodiment provided by the present disclosure, the method may further include the following steps:

[0114] In step S550, when a first virtual node is newly added to the hash ring, the connection request between the first virtual node and the second virtual node is disconnected.

[0115] Wherein, the second virtual node is a virtual node adjacent to the first virtual node in the opposite direction of the preset direction on the hash ring. In the embodiment, the preset direction is taken as an example of the clockwise direction for illustration.

[0116] In the embodiment, when a first server node is newly added, a plurality of virtual nodes corresponding to the first server node may be generated. Based on the identification information respectively corresponding to the plurality of virtual nodes of the first server node, the plurality of virtual nodes of the first server node can be mapped to the hash ring.

[0117] For example, for the 4 virtual nodes corresponding to the server node A, namely NodeA#1, NodeA#2, NodeA#3, and NodeA#4, the hash values of NodeA#1, NodeA#2, NodeA#3, and NodeA#4 can be calculated respectively, and through the method of hash mapping, the 4 virtual nodes can be mapped to the hash ring.

[0118] In step S560, the disconnected connection request is reallocated to the service node corresponding to the first virtual node.

[0119] In the embodiment, when a virtual node is newly added, only those connection requests originally located between the newly added virtual node and the next node in its counterclockwise or clockwise direction will be reallocated, so as to minimize the impact on the existing connections.

[0120] Combined with Figure 3 as shown, the first virtual node may be Figure 3 the virtual node D1 in Figure 3 and the second virtual node may be the virtual node B1 in

[0121] In the embodiments provided by the present disclosure, the number of virtual nodes on the hash ring can also be obtained, and when the number is greater than the first threshold, the connection relationships between the servers corresponding to the respective virtual nodes on the hash ring and the respective terminals are disconnected. By re-determining the positions of the respective virtual nodes on the hash ring and re-establishing the connection relationships between the servers corresponding to the respective virtual nodes on the hash ring and the respective terminals.

[0122] In this way, when the number of virtual nodes on the hash ring is greater than the first threshold, the connections between the terminals and the servers on the entire hash ring are disconnected, and all the virtual nodes on the hash ring are re-sorted so that these virtual nodes are evenly distributed on the hash ring to achieve load balancing.

[0123] Based on the above embodiments, in another embodiment provided by the present disclosure, the method may further include the following steps:

[0124] In step S570, when removing the third virtual node on the hash ring, the connection request of the server corresponding to the third virtual node is disconnected.

[0125] In the embodiment, when reducing the second server node in the server cluster, the virtual nodes corresponding to the second server node on the hash ring can be obtained and the virtual nodes corresponding to the second server node are removed from the hash ring. In this way, by timely removing the virtual nodes corresponding to the server nodes that do not provide services on the hash ring, the situation of connection request allocation failure can be avoided to improve the efficiency of load balancing.

[0126] In step S580, the disconnected connection requests are re-allocated to the server node corresponding to the fourth virtual node.

[0127] Wherein, the fourth virtual node is the adjacent virtual node of the third virtual node in the preset direction on the hash ring.

[0128] In the embodiment, when reducing one virtual node, only those connection requests that were originally between the newly added virtual node and the next node in its counterclockwise or clockwise direction will be re-allocated, so as to reduce the impact on the existing connections.

[0129] Combined with Figure 4 As shown, when reducing one server node A in the server cluster, the multiple virtual nodes of the server node A on the hash ring will also be removed. For example, the third virtual node can be Figure 4 the virtual node A2 in Figure 4 and the fourth virtual node can be Figure 4The connection request allocated to the virtual node A2 in the Central Plains will also be reallocated to the virtual node C1, that is, this connection request will be disconnected from the server node A and reconnected to this connection request through the server node C. At this time, it will affect the connection requests falling in the interval from B1 to A2, but will not affect the connection requests falling in the interval from A2 to C1.

[0130] In the embodiment, by obtaining the number of virtual nodes on the hash ring, when the number is less than the second threshold, the connections between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals are disconnected. The positions of the respective virtual nodes on the hash ring are re-determined, and the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals are re-established. In this way, when the number of virtual nodes on the hash ring is less than the second threshold, the connections between the terminals and the servers on the entire hash ring are disconnected, and all the virtual nodes on the hash ring are re-sorted so that these virtual nodes are evenly distributed on the hash ring. In this way, the connection relationships between the terminals and the server nodes can be re-established according to the re-sorted hash ring.

[0131] It should be noted that in the embodiments provided in the present disclosure, the current load capacities of multiple server nodes can be respectively obtained, and based on the load capacities, the numbers of virtual nodes mapped by the multiple server nodes on the hash ring can be determined. In the embodiment, the weight of the server node can also be determined according to the load capacity of the server node, and this weight is positively correlated with the load capacity of the server node. In this way, the weights of multiple server nodes can be respectively obtained, and based on the weights, the numbers of virtual nodes mapped by the multiple server nodes on the hash ring can be determined.

[0132] In this way, the number of virtual nodes corresponding to each server node in the embodiment can be determined according to the load capacity of the server node. The greater the load capacity, the more the corresponding number of virtual nodes can be; the smaller the load capacity, the fewer the corresponding number of virtual nodes can be. In this way, the server node with a higher load capacity can process more connection requests, and the server node with a lower load capacity can reduce the processed connection requests, which can better achieve load balancing.

[0133] In the embodiments provided by the present disclosure, the distribution of virtual nodes on the hash ring can also be detected in real time or periodically to determine areas where the distribution of virtual nodes on the hash ring is too dense or too sparse. For example, when the number of virtual nodes within a unit hash interval exceeds a third threshold, the unit hash interval can be determined as an overly dense interval, and the number of virtual nodes in this unit interval can be reduced. Similarly, when the number of virtual nodes within a unit hash interval is less than a fourth threshold, the unit hash interval can be determined as an overly sparse interval, and the number of virtual nodes in this unit interval can be increased. In fact, the third threshold is greater than the fourth threshold, and a unit hash interval can be understood as an interval on the hash ring that includes a target hash value range.

[0134] Therefore, in the embodiments, if it is found that the virtual nodes in certain areas are too dense or sparse, the number of virtual nodes can be dynamically adjusted. For example, more virtual nodes can be allocated to server nodes with higher loads, and fewer virtual nodes can be allocated to server nodes with lower loads. The embodiments can also re-partition the intervals and adjust the distribution of virtual nodes to ensure that the interval lengths occupied by each server node on the hash ring are approximately equal.

[0135] In the case of dividing each functional module according to corresponding functions, the embodiments of the present disclosure provide a load balancing device, which can be a server, a terminal, or a chip applied to a server. Figure 6 It is a schematic block diagram of the functional modules of the load balancing device provided by an exemplary embodiment of the present disclosure. As Figure 6 shown, the load balancing device includes:

[0136] A connection request receiving module 61, configured to receive a connection request sent by a terminal, where the connection request carries identification information of the terminal;

[0137] A hash calculation module 62, configured to calculate a hash value corresponding to the identification information through a preset hash function;

[0138] A target virtual node determination module 63, configured to obtain a position corresponding to the hash value on a pre-established hash ring, and obtain a target virtual node closest to the position on the hash ring in a preset direction; wherein, the hash ring includes a plurality of virtual nodes, the plurality of virtual nodes are distributed on the hash ring through a hash mapping method, each virtual node corresponds to a server node, each server node corresponds to a plurality of virtual nodes, and the number of server nodes includes a plurality;

[0139] A server node allocation module 64, configured to allocate the connection request to the server node corresponding to the target virtual node.

[0140] In another embodiment provided by the present disclosure, obtaining the target virtual node on the hash ring that is closest to the position in the preset direction includes:

[0141] Obtaining the target hash value range corresponding to the hash value on the hash ring; wherein, each virtual node on the hash ring corresponds to a hash value, and multiple hash value ranges are formed between the hash values corresponding to the multiple virtual nodes on the hash ring respectively;

[0142] Obtaining the endpoint hash values of the target hash value range in the preset direction, and using the virtual nodes corresponding to the endpoint hash values as the target virtual nodes.

[0143] In another embodiment provided by the present disclosure, the method further includes:

[0144] When a first virtual node is newly added to the hash ring, disconnecting the connection request between the first virtual node and the second virtual node; wherein, the second virtual node is the virtual node adjacent to the first virtual node in the opposite direction of the preset direction on the hash ring;

[0145] Reallocating the disconnected connection request to the service node corresponding to the first virtual node.

[0146] In another embodiment provided by the present disclosure, the method further includes:

[0147] Obtaining the number of virtual nodes on the hash ring;

[0148] When the number is greater than a first threshold, disconnecting the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals;

[0149] Re-determining the positions of the respective virtual nodes on the hash ring, and re-establishing the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals.

[0150] In another embodiment provided by the present disclosure, the method further includes:

[0151] When a first server node is newly added, generating a plurality of virtual nodes corresponding to the first server node;

[0152] Mapping the plurality of virtual nodes of the first server node to the hash ring based on the identification information corresponding to the plurality of virtual nodes of the first server node.

[0153] In another embodiment provided by the present disclosure, the method further includes:

[0154] When removing the third virtual node on the hash ring, disconnect the connection request of the server node corresponding to the third virtual node;

[0155] Reallocate the disconnected connection request to the server node corresponding to the fourth virtual node; wherein, the fourth virtual node is the adjacent virtual node of the third virtual node in the preset direction on the hash ring.

[0156] In another embodiment provided by the present disclosure, the method further includes:

[0157] Obtain the number of virtual nodes on the hash ring;

[0158] When the number is less than the second threshold, disconnect the connections between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals;

[0159] Redetermine the positions of the respective virtual nodes on the hash ring, and re - establish the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals.

[0160] In another embodiment provided by the present disclosure, the method further includes:

[0161] When reducing the second server node, obtain the virtual nodes corresponding to the second server node on the hash ring;

[0162] Remove the virtual nodes corresponding to the second server node from the hash ring.

[0163] In another embodiment provided by the present disclosure, the method further includes:

[0164] Obtain the weights of the multiple server nodes respectively, where the weights are positively correlated with the load capacities of the server nodes;

[0165] Based on the weights, determine the number of virtual nodes mapped by the multiple server nodes on the hash ring respectively.

[0166] In an embodiment of the present disclosure, a connection request including identification information sent by a terminal is received, and a hash value corresponding to the identification information is calculated. By obtaining the position corresponding to the hash value on a pre-established hash ring and obtaining the target virtual node closest to the position on the hash ring in a preset direction, the connection request is allocated to the server node corresponding to the target virtual node. Since the hash ring contains multiple virtual nodes respectively corresponding to each server node, and these multiple virtual nodes are distributed on the hash ring by means of hashing. When a problem occurs due to overload in one of the server nodes, it will not cause all the connection requests on that server node to be allocated to the same server node, but rather be relatively evenly allocated to other server nodes. In this way, problems caused by overload of a large number of servers can be effectively prevented, load balancing can be effectively achieved, and thus the performance of the server cluster can be improved.

[0167] An embodiment of the present disclosure further provides a load balancer, including: at least one processor; a memory for storing executable instructions of the at least one processor; wherein, the at least one processor is configured to execute the instructions to implement the above method disclosed in the embodiment of the present disclosure.

[0168] Figure 7 It is a schematic structural diagram of an electronic device provided for an exemplary embodiment of the present disclosure. As Figure 7 shown, the electronic device may specifically be the above load balancer. The electronic device 700 includes at least one processor 701 and a memory 702 coupled to the processor 701, and the processor 701 can execute the corresponding steps in the above method disclosed in the embodiment of the present disclosure.

[0169] The above-mentioned processor 701 can also be referred to as a central processing unit (CPU). It can be an integrated circuit chip with the ability to process signals. Each step in the above methods disclosed in the embodiments of the present disclosure can be completed by the integrated logic circuit in the hardware of the processor 701 or instructions in the form of software. The above-mentioned processor 701 can be a general-purpose processor, a digital signal processor (DSP), an ASIC (Application Specific Integrated Circuit), an FPGA (field-programmable gate array), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the methods disclosed in combination with the embodiments of the present disclosure can be directly embodied as being executed and completed by the hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. The software module can be located in the memory 702, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, and other mature storage media in the art. The processor 701 reads the information in the memory 702 and combines its hardware to complete the steps of the above methods.

[0170] In addition, when various operations / processes according to the present disclosure are implemented by software and / or firmware, a program constituting the software can be installed from a storage medium or a network into a computer system having a dedicated hardware structure, such as Figure 8 the computer system 800 shown. When various programs are installed in the computer system, it can execute various functions, including functions such as those described above. Figure 8 It is a block diagram of the structure of a computer system provided by an exemplary embodiment of the present disclosure.

[0171] The computer system 800 is intended to represent various forms of digital electronic computer devices, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described herein and / or claimed.

[0172] As Figure 8As shown, computer system 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the computer system 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0173] Multiple components in the computer system 800 are connected to the I / O interface 805, including: an input unit 806, an output unit 807, a storage unit 808, and a communication unit 809. The input unit 806 can be any type of device that can input information into the computer system 800. The input unit 806 can receive input digital or character information, and generate key signal inputs related to the user settings and / or function controls of the electronic device. The output unit 807 can be any type of device that can present information, and can include but is not limited to a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 808 can include but is not limited to a magnetic disk, an optical disk. The communication unit 809 allows the computer system 800 to exchange information / data with other devices through a network such as the Internet, and can include but is not limited to a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a BluetoothTM device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0174] The computing unit 801 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include but are not limited to a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 801 executes the various methods and processes described above. For example, in some embodiments, the above methods disclosed in the embodiments of the present disclosure can be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as the storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device via the ROM 802 and / or the communication unit 809. In some embodiments, the computing unit 801 can be configured to execute the above methods disclosed in the embodiments of the present disclosure in any other appropriate manner (for example, by means of firmware).

[0175] Embodiments of the present disclosure also provide a computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the above-mentioned methods disclosed in the embodiments of the present disclosure.

[0176] The computer-readable storage medium in the embodiments of the present disclosure may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The above computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specifically, the above computer-readable storage medium may include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0177] The above computer-readable medium may be included in the above electronic device; or may exist separately without being assembled into the electronic device.

[0178] Embodiments of the present disclosure also provide a computer program product, including a computer program, wherein when the computer program is executed by a processor, the above-mentioned methods disclosed in the embodiments of the present disclosure are implemented.

[0179] In embodiments of the present disclosure, computer program code for performing the operations of the present disclosure may be written in one or more programming languages or combinations thereof. The above programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network (including a local area network (LAN) or a wide area network (WAN)), or may be connected to an external computer.

[0180] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks may occur in a different order than that noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0181] The modules, components, or units described in the embodiments of the present disclosure can be implemented in software or in hardware. In some cases, the names of the modules, components, or units do not constitute a limitation on the modules, components, or units themselves.

[0182] The functions described above can be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary hardware logic components that can be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on a chip (SOCs), complex programmable logic devices (CPLDs), and so on.

[0183] The above description is only some embodiments of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosure concept. For example, technical solutions formed by mutually replacing the above features with technical features having similar functions (but not limited to) disclosed in the present disclosure.

[0184] Although some specific embodiments of the present disclosure have been described in detail by way of examples, those skilled in the art should understand that the above examples are for illustrative purposes only and not for limiting the scope of the present disclosure. Those skilled in the art should understand that the above embodiments can be modified without departing from the scope and spirit of the present disclosure. The scope of the present disclosure is defined by the appended claims.

Claims

1. A load balancing method, characterized in that, The method includes: Receiving a connection request sent by a terminal, where the connection request carries identification information of the terminal; Calculating a hash value corresponding to the identification information through a preset hash function; Obtaining a position corresponding to the hash value on a pre-established hash ring, and obtaining a target virtual node on the hash ring that is closest to the position in a preset direction; wherein, the hash ring includes multiple virtual nodes, the multiple virtual nodes are distributed on the hash ring through a hash mapping method, each virtual node corresponds to a server node, each server node corresponds to multiple virtual nodes, and the number of server nodes includes multiple; Allocating the connection request to the server node corresponding to the target virtual node.

2. The method according to claim 1, wherein The obtaining the target virtual node on the hash ring that is closest to the position in a preset direction includes: Obtaining a target hash value interval corresponding to the hash value on the hash ring; wherein, each virtual node on the hash ring corresponds to a hash value, and multiple hash value intervals are formed between the hash values corresponding to the multiple virtual nodes on the hash ring respectively; Obtaining an endpoint hash value of the target hash value interval in the preset direction, and using the virtual node corresponding to the endpoint hash value as the target virtual node.

3. The method according to claim 1, characterized in that, The method further includes: When a first virtual node is newly added to the hash ring, disconnecting a connection request between the first virtual node and a second virtual node; wherein, the second virtual node is a virtual node adjacent to the first virtual node in the opposite direction of the preset direction on the hash ring; Reallocating the disconnected connection request to the service node corresponding to the first virtual node.

4. The method according to claim 3, characterized in that, The method further includes: Obtaining the number of virtual nodes on the hash ring; When the number is greater than a first threshold, disconnecting the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals; Re-determining the positions of the respective virtual nodes on the hash ring, and re-establishing the connection relationships between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals.

5. The method according to claim 3 or 4, characterized in that The method further includes: When a first server node is newly added, generating multiple virtual nodes corresponding to the first server node; Mapping the multiple virtual nodes of the first server node to the hash ring based on the identification information corresponding to the multiple virtual nodes of the first server node respectively.

6. The method according to claim 1, wherein The method further includes: When a third virtual node is removed from the hash ring, disconnecting the connection request of the server node corresponding to the third virtual node; Reallocating the disconnected connection request to the server node corresponding to a fourth virtual node; wherein, the fourth virtual node is a virtual node adjacent to the third virtual node in the preset direction on the hash ring.

7. The method according to claim 6, wherein The method further includes: Obtaining the number of virtual nodes on the hash ring; When the number is less than a second threshold, disconnecting the connections between the server nodes corresponding to the respective virtual nodes on the hash ring and the respective terminals; Redetermine the positions of the virtual nodes on the hash ring, and re - establish the connection relationships between the server nodes corresponding to the virtual nodes on the hash ring and each terminal respectively.

8. The method according to claim 6 or 7, characterized in that, The method further includes: When reducing the second server node, obtain the virtual nodes corresponding to the second server node on the hash ring; Remove the virtual nodes corresponding to the second server node from the hash ring.

9. The method according to claim 1, characterized in that, The method further includes: Obtain the weights of multiple server nodes respectively, where the weights are positively correlated with the load - bearing capacity of the server nodes; Based on the weights, determine the number of virtual nodes mapped by the multiple server nodes on the hash ring respectively.

10. A load balancer, characterized in that, It includes: At least one processor; A memory for storing instructions executable by the at least one processor; Wherein, the at least one processor is configured to execute the instructions to implement the method according to any one of claims 1 - 9.

Citation Information

Cited By

  • Data synchronous transmission method based on cloud edge collaboration

    CN120768910A