Client load balancing method and device and storage medium
By acquiring and storing load balancing information through client-side drivers, and supporting multiple strategies, this approach addresses the limitations of traditional methods in terms of dynamism and algorithm options, providing a flexible load balancing solution suitable for dynamic clusters and high-concurrency environments.
Patent Information
- Application Number
- CN202510998242.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-11-18
AI Technical Summary
Traditional client-side load balancing methods cannot dynamically update load balancing information and only support a limited number of load balancing algorithm options, making it difficult to adapt to changes in cluster size and the needs of different scenarios.
The client driver obtains and stores load balancing information, supports multiple load balancing strategies such as round-robin address strategy, least connections strategy and automatic partition addressing strategy, dynamically updates load balancing information to adapt to cluster changes, and reselects addresses when a connection fails.
It achieves efficient message distribution in dynamically changing cluster environments, supports multiple load balancing algorithms, is suitable for large-scale distributed systems and high-concurrency environments, and improves the flexibility and adaptability of load balancing.
Smart Images

Figure CN120980024A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of load balancing technology, specifically to a client-side load balancing method, apparatus, and storage medium. Background Technology
[0002] Load balancing is a critical issue in modern distributed systems. In large-scale distributed systems, the number of nodes is enormous and constantly changing. Without load balancing, some nodes will be overloaded while others remain idle, thus degrading the performance of the entire cluster.
[0003] Currently, load balancing methods can be divided into two types: client-side load balancing and server-side load balancing. Client-side load balancing refers to selecting a suitable server using an algorithm before the client initiates a request. Server-side load balancing refers to selecting a suitable node to handle the request based on a specific algorithm after receiving the client request. Compared to server-side load balancing, client-side load balancing offers greater flexibility and can also reduce the load on the server.
[0004] However, traditional client-side load balancing methods have some limitations. First, they cannot dynamically update load balancing information; when the number of nodes in the cluster changes, the load balancing configuration information needs to be manually modified. Second, they only support a limited number of load balancing algorithm options, making it difficult to cope with the needs of different scenarios. Summary of the Invention
[0005] In view of the deficiencies of the prior art mentioned in the background, the purpose of this invention is to provide a client load balancing method, device and storage medium to dynamically adapt to changes in cluster size and support multiple load balancing algorithm options.
[0006] To achieve the above objectives, in a first aspect, embodiments of the present invention provide a client-side load balancing method, comprising:
[0007] Select a target node and establish a connection between the client and the target node; the target node can be any node in the cluster.
[0008] Obtain and store load balancing information; the load balancing information is the cluster information of the connected nodes.
[0009] Based on the load balancing information and load balancing strategy, a target request address is selected, and a connection is established between the client and the target request address.
[0010] Send a client request to the target request address.
[0011] The cluster information includes a list of nodes, the current status of nodes, and the sharding distribution of distributed storage for nodes; the load balancing strategies include a round-robin address strategy, a minimum number of connections strategy, and an automatic partitioning addressing strategy.
[0012] As a specific implementation of this application, the target node is selected as follows:
[0013] When the client driver connects to the cluster, it fills in the address of one node or all nodes in the cluster; all node addresses form an address list.
[0014] Select a node address from the cluster as the target node; or
[0015] Access the address list and select a node address from it as the target node.
[0016] As a specific implementation of this application, the target request address is selected based on the load balancing information and load balancing strategy, specifically as follows:
[0017] The polling address strategy distributes address requests evenly to multiple nodes in the node list in sequence, repeating this process until the target request address is selected.
[0018] The least connection strategy selects the node with the fewest tasks being executed from the node list, sends the address request to that node, and uses the address of that node as the target request address; if there are multiple nodes with the same tasks, a round-robin method is used to select the node.
[0019] The automatic partitioning addressing strategy selects the target request address based on the distribution and sharding of the node's storage.
[0020] Furthermore, as a preferred implementation of this application, if the client fails to connect to the target request address, the abnormal connection is deleted, and a new target request address is selected again according to the load balancing strategy, while simultaneously triggering the load balancing information update.
[0021] Secondly, embodiments of the present invention also provide a client-side load balancing device, comprising:
[0022] A node selection unit is used to select a target node and establish a connection between the client and the target node; the target node can be any node in the cluster.
[0023] A load balancing information acquisition unit is used to acquire and store load balancing information; the load balancing information is the cluster information of the connected nodes.
[0024] The request address selection unit is used to select a target request address based on the load balancing information and load balancing strategy, and to establish a connection between the client and the target request address.
[0025] The request sending unit is used to send a client request to the target request address.
[0026] Furthermore, as a preferred implementation of this application, the client-side load balancing device further includes an exception handling unit, used for:
[0027] If the client fails to connect to the target request address, the abnormal connection is deleted, and a new target request address is selected again according to the load balancing strategy, while the load balancing information is updated.
[0028] Thirdly, embodiments of the present invention also provide a client-side load balancing device, including a processor, an input device, an output device, and a memory, wherein the processor, input device, output device, and memory are interconnected, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method described in the first aspect.
[0029] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a processor, cause the processor to perform the method described in the first aspect.
[0030] The advantages of implementing the embodiments of the present invention are as follows:
[0031] 1. This invention provides a more flexible and dynamic load balancing solution, which can achieve efficient message distribution in dynamically changing cluster environments.
[0032] 2. Supports multiple load balancing algorithm options: round-robin address strategy, least connections strategy, and automatic partitioning addressing strategy, which can better meet the needs of different scenarios.
[0033] Among them, the round-robin address strategy selects an address from the routing table of stored addresses by round-robin; the least connections strategy is used to find the service address with the fewest active connections in the routing table; and the automatic partition addressing strategy obtains the partition by parsing the primary key and internal ID, and then maps the service address from the load balancing information.
[0034] 3. This method also has the function of automatically updating load balancing information, making it applicable to load balancing problems in large-scale distributed systems and high-concurrency environments. Attached Figure Description
[0035] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the specific embodiments or the prior art will be briefly introduced below.
[0036] Figure 1 This is a flowchart of the client load balancing method provided in the embodiments of the present invention;
[0037] Figure 2 This is a flowchart of the load balancing information update process;
[0038] Figure 3 This is a structural diagram of the client-side load balancing device provided in an embodiment of the present invention;
[0039] Figure 4 yes Figure 3 Another structural diagram of the client-side load balancing device is shown. Detailed Implementation
[0040] 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, not all, of the embodiments of the present invention. Based on the 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.
[0041] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0042] The inventive concept of this invention is:
[0043] To address the problems of traditional load balancing methods, this invention proposes a novel load balancing approach that dynamically adapts to changes in cluster size and supports multiple load balancing algorithm options. Specifically, this method is implemented through a client-driven mechanism. After the user specifies an address, the required load balancing information is retrieved from the distributed cluster and temporarily stored. Subsequent client requests are sent directly to different target addresses based on the load balancing algorithm. If the selected address becomes unreachable (potentially due to a node failure), the load balancing information for that address is removed, and a new address is selected. Furthermore, the load balancing information is dynamically updated periodically to ensure the correctness and rationality of message distribution.
[0044] Please refer to Figure 1 The client-side load balancing method provided in this embodiment of the invention includes the following steps:
[0045] S1: Connection.
[0046] In practice, when connecting to the cluster, the client driver will fill in either the address of one of the nodes in the cluster or a list of addresses for all nodes. This step will attempt to connect to one address; if it's from a list of addresses, it will select one from the list.
[0047] S2: Obtain and store load balancing information.
[0048] In practice, after connecting to any node in the cluster, the client obtains the cluster information of that node as load balancing information. This cluster information includes, but is not limited to, the total number of nodes (node list), the status of these nodes, and the sharding distribution of the distributed storage. All this information provides the metrics for subsequent load balancing strategies.
[0049] S3: Select an address based on the strategy.
[0050] Combined with step S2, the target request address is selected based on load balancing information and load balancing strategy.
[0051] Existing load balancing strategies include round-robin address strategy, least connections strategy, automatic partitioning and addressing strategy, and optimal resource strategy.
[0052] The round-robin address strategy distributes requests evenly to the nodes in the cluster's node list in a continuous loop.
[0053] The least connections strategy selects the node with the fewest tasks currently executing from the list to send requests. If nodes have the same number of tasks, they are selected in a round-robin fashion.
[0054] The automatic partitioning and addressing strategy selects nodes based on their sharding information from the load balancing data. In a distributed cluster, the primary replica's data resides on only one node, and user update requests are sent directly to the primary replica. If a request were sent to a backup replica node, the backup replica node would also need to communicate with the primary replica node, increasing transmission overhead. This strategy prevents requests from being sent to backup replica nodes, accelerating request processing time and reducing network resource consumption.
[0055] S4: Attempt to obtain a connection to the selected address.
[0056] In a high-availability scenario, all network connections are unreliable. When an address connection sends a request, it attempts to acquire a connection and verifies whether the connection is available.
[0057] S5: Clear the load balancing information for this address.
[0058] If a connection becomes unavailable, the faulty connection will be deleted, and the system will return to selecting an address again based on the policy. Simultaneously, an update to the load balancing information will be triggered.
[0059] It's important to note that timeliness is crucial for selecting suitable nodes through load balancing strategies. Therefore, continuous updates to load balancing information are necessary, primarily through both proactive and reactive updates.
[0060] In this case, proactive updates occur when an abnormal connection occurs. A persistent connection is established between the client and server, but the response can vary depending on the keepalive settings of different network configurations. For example, if the connection has actually been broken, but the client is unaware of it, the client will only detect the anomaly when sending a request. If, after the connection is broken, the client immediately receives an RST or FIN request, it will proactively trigger a change in load balancing information, immediately accessing the server to request and update the load balancing information.
[0061] Passive updates, on the other hand, periodically verify and update based on the configured time, such as... Figure 2 As shown in the diagram. For each request, it checks whether the load balancing information needs updating. If not, it selects the appropriate strategy based on the current load balancing information. If an update is needed, it retrieves the latest load balancing information from the server, updates the local data, and then selects the appropriate strategy.
[0062] S6: Send a request to this address.
[0063] After determining the node and address, a request is sent to the address selected by the load balancer.
[0064] The advantages of implementing the client-side load balancing method provided in this embodiment of the invention are as follows:
[0065] 1. This invention provides a more flexible and dynamic load balancing solution, which can achieve efficient message distribution in dynamically changing cluster environments.
[0066] 2. Supports multiple load balancing algorithm options: round-robin address strategy, least connections strategy, and automatic partitioning addressing strategy, which can better meet the needs of different scenarios.
[0067] Among them, the round-robin address strategy selects an address from the routing table of stored addresses by round-robin; the least connections strategy is used to find the service address with the fewest active connections in the routing table; and the automatic partition addressing strategy obtains the partition by parsing the primary key and internal ID, and then maps the service address from the load balancing information.
[0068] 3. This method also has the function of automatically updating load balancing information, making it applicable to load balancing problems in large-scale distributed systems and high-concurrency environments.
[0069] Based on the same inventive concept, embodiments of the present invention also provide a client-side load balancing device, such as... Figure 3 As shown, it includes:
[0070] A node selection unit is used to select a target node and establish a connection between the client and the target node; the target node can be any node in the cluster.
[0071] A load balancing information acquisition unit is used to acquire and store load balancing information; the load balancing information is the cluster information of the connected nodes.
[0072] The request address selection unit is used to select a target request address based on the load balancing information and load balancing strategy, and to establish a connection between the client and the target request address.
[0073] The request sending unit is used to send a client request to the target request address;
[0074] An exception handling unit is used to delete the abnormal connection if the client fails to connect to the target request address, and select a new target request address according to the load balancing strategy, while triggering the load balancing information update.
[0075] Furthermore, the node selection unit is specifically used for:
[0076] When the client driver connects to the cluster, it fills in the address of one node or all nodes in the cluster; all node addresses form an address list.
[0077] Select a node address from the cluster as the target node; or
[0078] Access the address list and select a node address from it as the target node.
[0079] Furthermore, the cluster information includes a node list, the current status of the nodes, and the sharding distribution of the distributed storage of the nodes; the load balancing strategy includes a round-robin address strategy, a least-connections strategy, and an automatic partitioning addressing strategy; the request address selection unit is specifically used for:
[0080] The polling address strategy distributes address requests evenly to multiple nodes in the node list in sequence, repeating this process until the target request address is selected.
[0081] The least connection strategy selects the node with the fewest tasks being executed from the node list, sends the address request to that node, and uses the address of that node as the target request address; if there are multiple nodes with the same tasks, a round-robin method is used to select the node.
[0082] The automatic partitioning addressing strategy selects the target request address based on the distribution and sharding of the node's storage.
[0083] It should be noted that the specific workflow of this embodiment is described in the foregoing method embodiment section, and will not be repeated here.
[0084] Furthermore, another embodiment of the present invention also provides a client-side load balancing device, such as... Figure 4 As shown, the system may include one or more processors 101, one or more input devices 102, one or more output devices 103, and a memory 104. The processors 101, input devices 102, output devices 103, and memory 104 are interconnected via a bus 105. The memory 104 stores a computer program, which includes program instructions. The processor 101 is configured to invoke the program instructions to execute the method described in the above-described method embodiment.
[0085] It should be understood that, in this embodiment of the invention, the processor 101 may be a central processing unit (CPU), but it may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0086] Input device 102 may include a keyboard, etc., and output device 103 may include a display (LCD, etc.), a speaker, etc.
[0087] The memory 104 may include read-only memory and random access memory, and provides instructions and data to the processor 101. A portion of the memory 104 may also include non-volatile random access memory. For example, the memory 104 may also store device type information.
[0088] In specific implementations, the processor 101, input device 102, and output device 103 described in the embodiments of the present invention can execute the implementation methods described in the embodiments of the client load balancing method provided in the embodiments of the present invention, which will not be repeated here.
[0089] Accordingly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a processor, implement the above-described client load balancing method.
[0090] The computer-readable storage medium can be an internal storage unit of the system described in any of the foregoing embodiments, such as the system's hard disk or memory. The computer-readable storage medium can also be an external storage device of the system, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the computer-readable storage medium can include both internal storage units and external storage devices. The computer-readable storage medium is used to store the computer program and other programs and data required by the system. The computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
[0091] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0092] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices or units, or may be electrical, mechanical or other forms of connection.
[0093] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.
[0094] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0095] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0096] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A client-side load balancing method, characterized in that, include: Select a target node and establish a connection between the client and the target node; The target node can be any node in the cluster; Obtain and store load balancing information; The load balancing information is the cluster information of the connected nodes; Based on the load balancing information and load balancing strategy, a target request address is selected, and a connection is established between the client and the target request address. Send a client request to the target request address.
2. The client-side load balancing method as described in claim 1, characterized in that, The specific steps for selecting the target node are as follows: When the client driver connects to the cluster, it fills in the address of one node or all nodes in the cluster; all node addresses form an address list. Select one node address in the cluster as the target node; or Access the address list and select a node address from it as the target node.
3. The client-side load balancing method as described in claim 1, characterized in that, The cluster information includes a list of nodes, the current status of the nodes, and the sharding distribution of the distributed storage of the nodes.
4. The client-side load balancing method as described in claim 3, characterized in that, The load balancing strategy includes a round-robin address strategy, a least-connections strategy, and an automatic partitioning addressing strategy; the target request address is selected based on the load balancing information and the load balancing strategy, specifically as follows: The polling address strategy distributes address requests evenly to multiple nodes in the node list in sequence, repeating this process until the target request address is selected. The least connection strategy selects the node with the fewest tasks being executed from the node list, sends the address request to that node, and uses the address of that node as the target request address; if there are multiple nodes with the same tasks, a round-robin method is used to select the node. The automatic partitioning addressing strategy selects the target request address based on the distribution and sharding of the node's storage.
5. The client-side load balancing method as described in claim 1, characterized in that, If the client fails to connect to the target request address, the abnormal connection is deleted, and a new target request address is selected again according to the load balancing strategy, while the load balancing information is updated.
6. A client-side load balancing device, characterized in that, include: A node selection unit is used to select a target node and establish a connection between the client and the target node; The target node can be any node in the cluster; The load balancing information acquisition unit is used to acquire and store load balancing information. The load balancing information is the cluster information of the connected nodes; The request address selection unit is used to select a target request address based on the load balancing information and load balancing strategy, and to establish a connection between the client and the target request address. The request sending unit is used to send a client request to the target request address.
7. The client-side load balancing device as described in claim 6, characterized in that, The node selection unit is specifically used for: When the client driver connects to the cluster, it fills in the address of one node or all nodes in the cluster; all node addresses form an address list. Select one node address in the cluster as the target node; or Access the address list and select a node address from it as the target node.
8. The client-side load balancing device as described in claim 6 or 7, characterized in that, It also includes an exception handling unit, used for: If the client fails to connect to the target request address, the abnormal connection is deleted, and a new target request address is selected again according to the load balancing strategy, while the load balancing information is updated.
9. A client-side load balancing device, characterized in that, The system includes a processor, an input device, an output device, and a memory, which are interconnected. The memory is used to store a computer program, which includes program instructions. The processor is configured to invoke the program instructions to perform the method as described in any one of claims 1-5.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1-5.