Method, system, client and server for load balancing of secure registry connections
By coordinating client and server operations, the connection weight and load status of the registry center nodes are dynamically adjusted, which solves the problem of unbalanced connections of the registry center nodes and ensures the stability and availability of the microservice architecture.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING CHIBO INFORMATION ENG CO LTD
- Filing Date
- 2023-04-06
- Publication Date
- 2026-07-28
AI Technical Summary
In a microservice architecture, uneven connection load on the registry node can cause some nodes to become overloaded, making them prone to failure and affecting the stability and availability of the entire cluster.
The client randomly selects the address of a node in the registry cluster at preset time intervals to initiate an HTTP request. The server node queries the latest cluster list and connection count, sets the node weight based on the connection count, and the client reselects a node to connect to based on the load status to ensure load balancing.
This achieves load balancing of the registry center server connections, ensuring the safe and stable operation of the registry center and reducing the risk of failure caused by node overload.
Smart Images

Figure CN116389498B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of microservices technology, and in particular to a method, system, client, and server for ensuring load balancing of registry connections. Background Technology
[0002] This section is intended to provide background or context for the embodiments of the invention set forth in the claims. The description herein is not an admission that it is prior art simply because it is included in this section.
[0003] With technological advancements and the expansion of application clusters, microservice architecture is gaining increasing popularity. Microservice architecture achieves service decoupling, technological heterogeneity, and ease of deployment, improving application high availability and scalability. As the control plane, the registry center promptly pushes service management information to microservice applications. As a core infrastructure service within the microservice framework, the stability and availability of the registry center are crucial.
[0004] In general, when multiple application clients connect to the registry cluster via persistent connections, the following situations may lead to uneven load distribution across nodes within the cluster: A node in the cluster may restart, causing clients connected to that node to automatically be reassigned to other nodes; when the cluster expands and new nodes are added, existing client persistent connections will not be routed to the newly added nodes; clients may choose inappropriate server address selection strategies, causing most clients to connect to a single node in the cluster; These situations can result in some registry nodes having excessive network connection load while others are nearly idle, all of which are detrimental to the overall stability of the cluster. Heavily loaded nodes are prone to failure, and when client persistent connections are distributed unevenly across other nodes, a cascading failure-like phenomenon may occur, ultimately rendering the entire cluster unusable. Summary of the Invention
[0005] This invention provides a method for ensuring load balancing of connections to a registry server. This method is applied to a system to ensure load balancing of connections to a registry server. The method includes:
[0006] The client randomly selects a server node address in the registration center cluster at preset time intervals to initiate an HTTP request;
[0007] When a randomly selected server node receives an HTTP request, it queries the latest cluster list and the number of connections for each node in the registry cluster; it determines the load status of each node based on the number of connections for each node and the preset allowed connection ratio threshold; it sets the weight of each node according to the number of connections for each node; and it sends the latest cluster list, the load status of each node, and its weight to the client.
[0008] When the client determines that the load of the connected registry center node is abnormal based on the load status of each node, it re-selects a registry center node to connect to based on the latest cluster list, the load status and weight of each node, and registers and subscribes after the connection is successful.
[0009] This invention also provides a method for ensuring load balancing of connections to a registry server. This method is applied to a client to ensure load balancing of connections to the registry server. The method includes:
[0010] At preset time intervals, an HTTP request is initiated by randomly selecting one server node address in the registry cluster. Upon receiving the HTTP request, the server node in the registry queries the latest cluster list and the number of connections for each node in the registry cluster. Based on the number of connections for each node and a preset allowed connection ratio threshold, the load status of each node is determined. The weight of each node is set according to the number of connections for each node. The latest cluster list, the load status of each node, and the weight are sent to the client.
[0011] When it is determined that the load of a connected registry center node is abnormal based on the load status of each node, a new registry center node is selected for connection based on the latest cluster list, the load status and weight of each node, and registration and subscription are performed after the connection is successful.
[0012] This invention also provides a method for ensuring load balancing of connections to a registry server. This method is applied to the server side to ensure load balancing of connections to the registry server. The method includes:
[0013] Upon receiving an HTTP request, the system queries the latest cluster list and the connection count of each node in the registry center cluster; the HTTP request is initiated by the client at preset time intervals by randomly selecting a server node address in the registry center cluster.
[0014] The load status of each node is determined based on the number of connections to each node and the preset allowed connection ratio threshold.
[0015] Each node is assigned a weight based on its number of connections. The latest cluster list, the load status of each node, and its weight are sent to the client. When the client determines that the load of a connected registry node is abnormal based on the load status of each node, it reselects a registry node to connect to based on the latest cluster list, the load status of each node, and its weight. After a successful connection, the client registers and subscribes.
[0016] This invention also provides a system for ensuring load balancing of connections to a registry center server, the system comprising:
[0017] The client is used to randomly select a server node address in the registration center cluster at preset time intervals to initiate an HTTP request; when it is determined that the load of the connected registration center node is abnormal based on the load status of each node, the client re-selects a registration center node to connect to based on the latest cluster list, the load status and weight of each node, and registers and subscribes after the connection is successful.
[0018] A randomly selected server node is used to query the latest cluster list and the number of connections for each node in the registry cluster when an HTTP request is received; determine the load status of each node based on the number of connections for each node and the preset allowed connection ratio threshold; set the weight of each node according to the number of connections for each node; and send the latest cluster list, the load status of each node and its weight to the client.
[0019] This invention also provides a registry client for ensuring load balancing of registry server connections, the client comprising:
[0020] The initiating unit is used to randomly select a server node address in the registry cluster at preset time intervals to initiate an HTTP request; when the server node of the registry receives the HTTP request, it queries the latest cluster list and the number of connections of each node in the registry cluster; it determines the load status of each node according to the number of connections of each node and the preset allowed connection ratio threshold; it sets the weight of each node according to the number of connections of each node; and it sends the latest cluster list, the load status and weight of each node to the client.
[0021] The optimization unit is used to reselect a registration center node to connect to when the load status of each node indicates that the load of the connected registration center node is abnormal. Based on the latest cluster list, the load status and weight of each node, the optimization unit will then register and subscribe.
[0022] This invention also provides a registry server that ensures load balancing of registry server connections, the server comprising:
[0023] The query unit is used to query the latest cluster list and the connection count of each node in the registry center cluster when an HTTP request is received; the HTTP request is initiated by the client randomly selecting a server node address in the registry center cluster every preset time interval;
[0024] The load status determination unit is used to determine the load status of each node based on the number of connections of each node and a preset allowable connection ratio threshold.
[0025] The sending unit is used to set the weight of each node according to the number of connections of each node; send the latest cluster list, the load status and weight of each node to the client; when the client determines that the load of the connected registration center node is abnormal according to the load status of each node, it reselects the registration center node to connect to according to the latest cluster list, the load status and weight of each node, and registers and subscribes after the connection is successful.
[0026] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described method for ensuring load balancing of connections to the registry center server.
[0027] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for ensuring load balancing of connections to the registry center server.
[0028] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described method for ensuring load balancing of connections to the registry center server.
[0029] In this embodiment of the invention, the scheme for ensuring load balancing of the registry center server connections works as follows: The client randomly selects a server node address in the registry center cluster every preset time interval to initiate an HTTP request; upon receiving the HTTP request, the randomly selected server node queries the latest cluster list and the connection count of each node in the registry center cluster; based on the connection count of each node and a preset allowed connection ratio threshold, it determines the load status of each node; it sets the weight of each node according to its connection count; and it sends the latest cluster list, the load status of each node, and its weight to the client; when the client determines that the load of a connected registry center node is abnormal based on the load status of each node, it reselects a registry center node to connect to based on the latest cluster list, the load status of each node, and its weight. After a successful connection, registration and subscription are performed.
[0030] Compared to existing technologies where some registry center nodes within a cluster experience excessive network connection load while others are nearly idle, both of which are detrimental to the overall stability of the cluster and prone to failure, the solution provided in this invention for ensuring load balancing of registry center server connections offers the following advantages: Firstly, the client periodically sends requests to the registry center, obtaining the latest cluster list, allowing long connections to be routed to newly added nodes. Secondly, it obtains the load status and weight of each node. When it is determined that a connected registry center node is under abnormal load based on the load status of each node, the system reselects a registry center node for connection based on the latest cluster list, load status, and weight of each node, ensuring load balancing of the registry center server connections and thus guaranteeing the safe and stable operation of the registry center. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:
[0032] Figure 1 This is a flowchart illustrating a method for ensuring load balancing of the system's registry server connections, as described in an embodiment of the present invention.
[0033] Figure 2 This is a schematic diagram illustrating the principle of ensuring load balancing of the registration center server connection in an embodiment of the present invention;
[0034] Figure 3 This is a flowchart illustrating a method for ensuring load balancing of the registry center server connection applied to the client in an embodiment of the present invention.
[0035] Figure 4 This is a flowchart illustrating a method for ensuring server-side connection load balancing in a registry center, as described in an embodiment of the present invention.
[0036] Figure 5 This is a schematic diagram of the system architecture for ensuring load balancing of the registry server connection in an embodiment of the present invention;
[0037] Figure 6 This is a schematic diagram of the client structure that ensures load balancing of the registration center server connection in an embodiment of the present invention;
[0038] Figure 7This is a schematic diagram of the structure of the server that ensures the connection of the registration center server to the load-balanced server in an embodiment of the present invention. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0040] The acquisition, storage, use, and processing of data in this application comply with relevant laws and regulations.
[0041] The existing design involves the registry client randomly selecting from the configured registry node address list and initiating a registration request when the application service starts. This ensures that the known address list is evenly distributed when there are a certain number of connections. When the application is closed, or when network instability between the client and the registry cluster causes a connection interruption, the client is automatically deregistered and the next address in the address list is selected as the retry target address.
[0042] The existing design has the following problems:
[0043] 1. When the connection of the registry center nodes (server) is severely unbalanced, it will cause some registry center nodes to be overloaded, while other registry center nodes will not be under pressure.
[0044] 2. When a new registry node is added, existing client connections will not be able to discover the new node and will not be routed to the new node.
[0045] 3. After a problem is diagnosed, the nodes in the cluster are unable to actively and dynamically adjust the load.
[0046] To address the aforementioned technical problems, this invention proposes a solution for ensuring load balancing of connections to the registry center server. This solution is compatible with existing solutions while:
[0047] 1. When the nodes of the registry center diagnose a severe imbalance in connections, the client optimizes the selection strategy to ensure a relatively balanced number of connections across the nodes, thereby guaranteeing the stability of the registry center cluster.
[0048] 2. When the registry center expands by adding new nodes, the changes in the cluster address list can be notified to existing clients, meaning that application clients can discover the new nodes.
[0049] The following section provides a detailed introduction to the solution for ensuring load balancing of the registry center server connections.
[0050] Figure 1This is a flowchart illustrating a method for ensuring load balancing of registry center server connections applied to a system according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:
[0051] Step 101: Every preset time interval, the client randomly selects a server node address in the registration center cluster and initiates an HTTP request;
[0052] Step 102: When a randomly selected server node receives an HTTP request, it queries the latest cluster list and the number of connections for each node in the registry cluster; it determines the load status of each node based on the number of connections for each node and the preset allowed connection ratio threshold; it sets the weight of each node according to the number of connections for each node; and it sends the latest cluster list, the load status of each node, and its weight to the client.
[0053] Step 103: When the client determines that the load of the connected registry center node is abnormal based on the load status of each node, it re-selects a registry center node to connect to based on the latest cluster list, the load status and weight of each node, and registers and subscribes after the connection is successful.
[0054] The method for ensuring load balancing of registry center server connections provided in this embodiment of the invention operates as follows: During operation, the client randomly selects a server node address in the registry center cluster every preset time interval to initiate an HTTP request; the registry center server (e.g., ...) Figure 5 As shown, the server (which can be any server node obtained randomly) queries the latest cluster list and the connection count of each node in the registry cluster when it receives an HTTP request; it determines the load status of each node based on the connection count of each node and the preset allowed connection count ratio threshold; it sets the weight of each node according to the connection count of each node; and it sends the latest cluster list, the load status of each node, and its weight to the client. When the client determines that the load of the connected registry node is abnormal based on the load status of each node, it reselects a registry node to connect to based on the latest cluster list, the load status of each node, and its weight. After a successful connection, it registers and subscribes.
[0055] Compared to existing technologies where some registry center nodes within a cluster have excessive network connection loads while others are nearly idle, both of which are detrimental to the overall stability of the cluster and can lead to failures in heavily loaded nodes. In such cases, client long-connection loads can be distributed to other unevenly distributed nodes, potentially causing a cascading failure and rendering the entire cluster unusable. The beneficial technical effects of the method for ensuring load balancing of registry center server connections provided in this invention are as follows: First, the client periodically sends requests to the registry center, obtaining the latest cluster list so that long-connections are routed to newly added nodes. Second, it obtains the load status and weight of each node, and determines, based on the load status of each node, that a connected registry center node is under abnormal load (e.g., ...). Figure 2 When a node is overloaded (as shown in the diagram), the system re-selects a registry center node to connect to based on the latest cluster list, the load status and weight of each node, ensuring load balancing of the registry center server connections and thus guaranteeing the safe and stable operation of the registry center. The following section provides a detailed introduction to this method for ensuring load balancing of registry center server connections.
[0056] In this embodiment of the invention, the registration center client obtains the latest cluster information through a scheduled task. When connecting to the registration center cluster, it can select a node with a lower load to ensure a relative balance in the number of connections to each node. Figure 2 As shown, the method includes:
[0057] 1) The registry center can dynamically set the proportion of allowed connections in the cluster, which is an allowed range (preset allowed connection proportion threshold).
[0058] 2) When the client starts, it starts a scheduled task to connect to the registry center, retrieves the latest registry center cluster address from the cache, and retrieves it through local configuration if the cache is empty.
[0059] 3) The client randomly selects a cluster address and sends an HTTP request to the registry center to obtain the latest cluster list from the registry center.
[0060] 4) The registry center queries the latest cluster list and the number of connections for each node, and calculates whether the proportion of each node's connections in the cluster is within the allowed range configured. If it is not within the range, the load is considered abnormal. The server sets the weight of each node according to the number of connections. The weight of each node is the total number of connections in the cluster minus its own number of connections. That is, in one embodiment, the weight of each node is the total number of connections in the cluster minus its own number of connections.
[0061] 5) The registry center returns the cluster list, weights, and load status to the client, and the client caches the returned results.
[0062] 6) The client selects a registry center node to connect to based on the returned result using a long connection.
[0063] 7) After a successful connection, registration and subscription are performed. If the connection fails, the client connects to the next registry center node according to the weight information. That is, in one embodiment, the above method for ensuring load balancing of registry center server connections may further include: when the client fails to connect, it connects to the next registry center node in the latest cluster list according to the weight.
[0064] 8) The client repeatedly executes the scheduled task, retrieves the cluster address from the cache, randomly selects one of the registry center addresses to obtain the registry center cluster list, weight, load status and cache.
[0065] 9) If the registered node already connected to the client is overloaded, a new cluster node is selected for registration and subscription according to the weight. If the registered node load is normal, the scheduled task is re-executed. That is, in one embodiment, the above method for ensuring load balancing of the registration center server connection may further include: when the client determines that the load of the connected registration center node is normal based on the load status of each node, it re-executes the step of randomly selecting a server node address in the registration center cluster every preset time period to initiate an HTTP request.
[0066] In one embodiment, the above method for ensuring load balancing of registry center server connections may further include: when a new registry center node joins the registry center cluster, randomly selecting server nodes to dynamically adjust the cluster list, using the changed cluster list as the latest cluster list, and dynamically adjusting the preset allowed connection ratio threshold.
[0067] In practice, when a new registry node joins the cluster, the registry dynamically adjusts the proportion of each node's allowed connections in the cluster and the latest cluster list. Clients can re-register and subscribe based on the registry's load status, thus achieving a relatively balanced number of connections in the registry cluster.
[0068] In one embodiment, the above method for ensuring load balancing of the registry center server connection may further include: after a problem is diagnosed by a node in the cluster, the load number is actively and dynamically adjusted to further ensure the stable and secure operation of the registry center cluster.
[0069] In summary, the embodiments of the present invention achieve the following: when the connection of the registry center nodes is severely unbalanced, the connection of the clients is balanced through a rebalancing strategy; when the registry center is expanded to add new nodes, existing clients can discover the new nodes.
[0070] The beneficial effects of the technical solution of this invention are as follows: when the connection of the registration center nodes is severely unbalanced, this invention can ensure the stability of the registration center cluster and provide a relatively balanced number of connections by optimizing the selection strategy of the client; when the registration center is expanded to add new nodes, existing clients can discover the new nodes, which is beneficial to application expansion and helps to reduce the impact on the system when some registration center nodes change under high load.
[0071] This invention also provides a method for load balancing of registry server connections applied to a client, as described in the following embodiments. Since the principle behind this method is similar to that of the method for load balancing of registry server connections applied to a system, the implementation of this method can refer to the implementation of the method for load balancing of registry server connections applied to a system; repeated details will not be elaborated further.
[0072] Figure 3 This is a flowchart illustrating a method for load balancing of client-side connections to a registry server, as described in an embodiment of the present invention. Figure 3 As shown, the method includes the following steps:
[0073] Step 201: Randomly select a server node address in the registry cluster at preset time intervals to initiate an HTTP request; When the server node of the registry receives the HTTP request, it queries the latest cluster list and the number of connections of each node in the registry cluster; Determines the load status of each node based on the number of connections of each node and the preset allowed connection ratio threshold; Sets the weight of each node according to the number of connections of each node; Sends the latest cluster list, the load status of each node and its weight to the client;
[0074] Step 202: When it is determined that the load of the connected registry center node is abnormal based on the load status of each node, a new registry center node is selected for connection based on the latest cluster list, the load status and weight of each node, and registration and subscription are performed after successful connection.
[0075] In one embodiment, the method for ensuring load balancing of the registry server connection described above may further include: when the client fails to connect, it connects to the next registry node in the latest cluster list according to the weight.
[0076] In one embodiment, the method for ensuring load balancing of the registration center server connection may further include: when the client determines that the load of the connected registration center node is normal based on the load status of each node, it re-executes the step of randomly selecting a server node address in the registration center cluster every preset time interval to initiate an HTTP request.
[0077] In one embodiment, the weight of each node is the total number of connections in the cluster minus its own number of connections.
[0078] This invention also provides a method for load balancing of registry server connections applied to the server side, as described in the following embodiments. Since the principle behind this method is similar to that of the method for load balancing of registry server connections applied to the system, the implementation of this method can refer to the implementation of the method for load balancing of registry server connections applied to the system; repeated details will not be elaborated further.
[0079] Figure 4 This is a flowchart illustrating a method for load balancing of a registry server connection applied to the server side in an embodiment of the present invention. Figure 4 As shown, the method includes the following steps:
[0080] Step 301: Upon receiving an HTTP request, query the latest cluster list and the connection count of each node in the registry cluster; the HTTP request is initiated by the client at preset time intervals by randomly selecting a server node address in the registry cluster.
[0081] Step 302: Determine the load status of each node based on the number of connections for each node and the preset allowed connection ratio threshold;
[0082] Step 303: Set the weight of each node according to the number of connections of each node; send the latest cluster list, the load status and weight of each node to the client; when the client determines that the load of the connected registration center node is abnormal according to the load status of each node, it reselects the registration center node to connect to according to the latest cluster list, the load status and weight of each node, and registers and subscribes after the connection is successful.
[0083] In one embodiment, the above-mentioned method for ensuring load balancing of registry server connections applied to the server side may further include: when a new registry node joins the registry cluster, the registry server node dynamically adjusts the cluster list, uses the changed cluster list as the latest cluster list, and dynamically adjusts the preset allowed connection ratio threshold.
[0084] In one embodiment, the weight of each node is the total number of connections in the cluster minus its own number of connections.
[0085] This invention also provides a system for load balancing of server-side connections in a registry center, as described in the following embodiments. Since the principle behind this system's problem-solving is similar to the method for load balancing of server-side connections in a registry center, the implementation of this system can refer to the implementation of the method for load balancing of server-side connections in a registry center, and will not be repeated here.
[0086] Figure 5 This is a schematic diagram of the system architecture for ensuring load balancing of the registry server connection in an embodiment of the present invention, as shown below. Figure 5 As shown, the system includes:
[0087] Client 01 is used to randomly select a server node address in the registration center cluster at preset time intervals to initiate an HTTP request; when it is determined that the load of the connected registration center node is abnormal based on the load status of each node, the registration center node is re-selected for connection according to the latest cluster list, the load status and weight of each node, and registration and subscription are performed after successful connection.
[0088] The registry center server node 02 is used to query the latest cluster list and the number of connections for each node in the registry center cluster when it receives an HTTP request; determine the load status of each node based on the number of connections for each node and the preset allowed connection ratio threshold; set the weight of each node according to the number of connections for each node; and send the latest cluster list, the load status of each node and its weight to the client.
[0089] Figure 5 The system shown is a schematic diagram of a client connecting to the registry center. In actual implementation, multiple clients can connect to the registry center.
[0090] In one embodiment, the registry server node is also used to dynamically adjust the cluster list when a new registry node joins the registry cluster, using the changed cluster list as the latest cluster list, and dynamically adjust the preset allowed connection ratio threshold.
[0091] In one embodiment, the client is also used to connect to the next registry node in the latest cluster list according to the weight when the connection fails.
[0092] In one embodiment, the client is further configured to, when it is determined that the connected registry center node is under normal load based on the load status of each node, re-execute the step of randomly selecting a server node address in the registry center cluster every preset time interval to initiate an HTTP request.
[0093] In one embodiment, the weight of each node is the total number of connections in the cluster minus its own number of connections.
[0094] This invention also provides a client for ensuring load balancing of registry server connections, as described in the following embodiments. Since the principle behind this client's problem-solving is similar to the method for ensuring load balancing of registry server connections applied to a system, the implementation of this client can refer to the implementation of the method for ensuring load balancing of registry server connections applied to a system; repeated details will not be elaborated further.
[0095] Figure 6 This is a schematic diagram of the client structure that ensures load balancing of connections to the registry center server in an embodiment of the present invention, as shown below. Figure 6 As shown, the client includes:
[0096] Initiating unit 011 is used to randomly select a server node address in the registration center cluster at preset time intervals to initiate an HTTP request; when the server node of the registration center receives the HTTP request, it queries the latest cluster list and the number of connections of each node in the registration center cluster; determines the load status of each node according to the number of connections of each node and the preset allowed connection ratio threshold; sets the weight of each node according to the number of connections of each node; and sends the latest cluster list, the load status and weight of each node to the client.
[0097] The optimization unit 012 is used to reselect a registration center node to connect to when the load status of each node determines that the load of the connected registration center node is abnormal. Based on the latest cluster list, the load status and weight of each node, the optimization unit 012 performs registration and subscription.
[0098] In one embodiment, the optimization unit is further configured to: connect to the next registry center node in the latest cluster list according to the weight when a connection fails.
[0099] In one embodiment, the optimization unit is further configured to: when it is determined that the load of the connected registry center node is normal based on the load status of each node, re-execute the step of randomly selecting a server node address in the registry center cluster every preset time period to initiate an HTTP request.
[0100] In one embodiment, the weight of each node is the total number of connections in the cluster minus its own number of connections.
[0101] This invention also provides a server for ensuring load balancing of registry server connections, as described in the following embodiments. Since the principle behind this server's problem-solving is similar to the method for ensuring load balancing of registry server connections applied to a system, the implementation of this server can refer to the implementation of the method for ensuring load balancing of registry server connections applied to a system; repeated details will not be elaborated further.
[0102] Figure 7 This is a schematic diagram of the structure of the server that ensures load balancing of the registration center server in an embodiment of the present invention, as shown below. Figure 7 As shown, the server includes:
[0103] The query unit 021 is used to query the latest cluster list and the connection count of each node in the registry cluster when an HTTP request is received; the HTTP request is initiated by the client randomly selecting a server node address in the registry cluster every preset time interval;
[0104] The load status determination unit 022 is used to determine the load status of each node based on the number of connections of each node and a preset allowed connection ratio threshold.
[0105] Sending unit 023 is used to set the weight of each node according to the number of connections of each node; send the latest cluster list, the load status and weight of each node to the client; when the client determines that the load of the connected registration center node is abnormal according to the load status of each node, it reselects the registration center node to connect to according to the latest cluster list, the load status and weight of each node, and registers and subscribes after the connection is successful.
[0106] In one embodiment, the above-mentioned method for ensuring load balancing of registry server connections applied to the server side may further include: when a new registry node joins the registry cluster, the registry server node dynamically adjusts the cluster list, uses the changed cluster list as the latest cluster list, and dynamically adjusts the preset allowed connection ratio threshold.
[0107] In one embodiment, the weight of each node is the total number of connections in the cluster minus its own number of connections.
[0108] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described method for ensuring load balancing of connections to the registry center server.
[0109] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for ensuring load balancing of connections to the registry center server.
[0110] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described method for ensuring load balancing of connections to the registry center server.
[0111] In this embodiment of the invention, the scheme for ensuring load balancing of the registry center server connections works as follows: The client randomly selects a server node address in the registry center cluster every preset time interval to initiate an HTTP request; upon receiving the HTTP request, the randomly selected server node queries the latest cluster list and the connection count of each node in the registry center cluster; based on the connection count of each node and a preset allowed connection ratio threshold, it determines the load status of each node; it sets the weight of each node according to its connection count; and it sends the latest cluster list, the load status of each node, and its weight to the client; when the client determines that the load of a connected registry center node is abnormal based on the load status of each node, it reselects a registry center node to connect to based on the latest cluster list, the load status of each node, and its weight. After a successful connection, registration and subscription are performed.
[0112] Compared to existing technologies where some registry center nodes within a cluster experience excessive network connection load while others are nearly idle, both of which are detrimental to the overall stability of the cluster and prone to failure, the solution provided in this invention for ensuring load balancing of registry center server connections offers the following advantages: Firstly, the client periodically sends requests to the registry center, obtaining the latest cluster list, allowing long connections to be routed to newly added nodes. Secondly, it obtains the load status and weight of each node. When it is determined that a connected registry center node is under abnormal load based on the load status of each node, the system reselects a registry center node for connection based on the latest cluster list, load status, and weight of each node, ensuring load balancing of the registry center server connections and thus guaranteeing the safe and stable operation of the registry center.
[0113] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0114] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0115] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0116] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0117] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for ensuring load balancing of registry center connections, characterized in that, This method is applied to the system, including: When the client starts, it starts a scheduled task to connect to the registry center, retrieves the latest registry center cluster address from the cache, and retrieves it through local configuration if the cache is empty. At preset time intervals, it randomly selects the address of a server node in the registry center cluster and initiates an HTTP request. When a randomly selected server node receives an HTTP request, it queries the latest cluster list and the connection count of each node in the registry cluster. Based on the connection count of each node and the preset allowed connection ratio threshold, it calculates whether the proportion of each node's connection count in the cluster is within the allowed range configured. If it is not within the range, it determines that the node's load status is abnormal. It sets the weight of each node according to the connection count of each node, with the weight of each node being the total number of connections in the cluster minus its own connection count. The latest cluster list, the load status of each node, and its weight are sent to the client and cached by the client. When the client determines that the load of a connected registry center node is abnormal based on the load status of each node, it re-selects a registry center node to connect to based on the latest cluster list, the load status and weight of each node, and registers and subscribes after a successful connection. When the connection fails, the client connects to the next registry center node in the latest cluster list according to the weight. When the client determines that the load of a connected registry center node is normal based on the load status of each node, it re-executes the step of randomly selecting a server node address in the registry center cluster and initiating an HTTP request every preset time interval.
2. The method as described in claim 1, characterized in that, Also includes: When a new registry node joins the registry cluster, the registry server node dynamically adjusts the cluster list, using the changed cluster list as the latest cluster list, and dynamically adjusts the preset allowed connection ratio threshold.
3. A method for ensuring load balancing of registry center connections, characterized in that, This method is applied to the client and includes: Upon startup, a scheduled task for connecting to the registry center is initiated. The latest registry center cluster address is retrieved from the cache; if the cache is empty, it is retrieved through local configuration. At preset time intervals, an HTTP request is initiated to a server node address randomly selected from the registry center cluster. Upon receiving an HTTP request, the server node in the registry center queries the latest cluster list and the connection count of each node in the cluster. Based on the connection count of each node and a preset allowed connection count threshold, the proportion of each node's connections in the cluster is calculated to determine if it falls within the allowed range configured. If it does not fall within the range, the node's load status is determined to be abnormal. A weight is set for each node according to its connection count, with each node's weight being the total cluster connections minus its own connection count. The latest cluster list, the load status of each node, and its weight are sent to the client and cached by the client. When it is determined that the load of a connected registry center node is abnormal based on the load status of each node, a new registry center node is selected for connection based on the latest cluster list, the load status and weight of each node. After successful connection, registration and subscription are performed. If the connection fails, the next registry center node in the latest cluster list is connected according to the weight. When it is determined that the load of a connected registry center node is normal based on the load status of each node, the step of randomly selecting a server node address in the registry center cluster and initiating an HTTP request every preset time period is repeated.
4. A method for ensuring load balancing of registry center connections, characterized in that, This method is applied to the registry center server and includes: Upon receiving an HTTP request, the system queries the latest cluster list and the connection count of each node in the registry center cluster; the HTTP request is initiated by the client at preset time intervals by randomly selecting a server node address in the registry center cluster. Based on the number of connections of each node and the preset allowed connection ratio threshold, calculate whether the proportion of the number of connections of each node in the cluster is within the allowed range of the configured proportion. If it is not within the range, it is determined that the load status of the node is abnormal. Each node is assigned a weight based on its connection count, with the weight being the total cluster connections minus its own connection count. The latest cluster list, the load status of each node, and its weight are sent to the client and cached by the client. When the client determines that a connected registry node is not under load based on the load status of each node, it re-selects a registry node to connect to based on the latest cluster list, the load status of each node, and its weight. Upon successful connection, registration and subscription are performed. If the connection fails, the client connects to the next registry node in the latest cluster list according to its weight. When the client determines that a connected registry node is under load based on the load status of each node, it re-executes the step of randomly selecting a server node address in the registry cluster and initiating an HTTP request every preset time interval.
5. A load balancing system for ensuring the connection of a registry center, characterized in that, include: The client is used to start a scheduled task to connect to the registry center upon startup. It retrieves the latest registry center cluster address from the cache; if the cache is empty, it retrieves it through local configuration. Every preset time interval, it randomly selects a server node address in the registry center cluster and initiates an HTTP request. If the load status of each node indicates that a connected registry center node is not functioning correctly, it re-selects a registry center node to connect to based on the latest cluster list, the load status of each node, and its weight. Upon successful connection, it registers and subscribes. If the connection fails, it connects to the next registry center node in the latest cluster list according to its weight. When the load status of each node indicates that the load of a connected registry center node is normal, it re-executes the step of randomly selecting a server node address in the registry center cluster and initiating an HTTP request every preset time interval. A randomly selected server node is used to query the latest cluster list and the number of connections for each node in the registry center cluster when an HTTP request is received. Based on the number of connections of each node and the preset allowed connection ratio threshold, calculate whether the proportion of the number of connections of each node in the cluster is within the allowed range of the configured proportion. If it is not within the range, it is determined that the load status of the node is abnormal. Each node is assigned a weight based on its number of connections. The weight of each node is the total number of connections in the cluster minus its own number of connections. The latest cluster list, the load status and weight of each node are sent to the client and cached by the client.
6. A method for ensuring connection to a registry center's load balancing client, characterized in that, include: The initiating unit is used to start a scheduled task to connect to the registry center at startup, obtain the latest registry center cluster address from the cache, or obtain it through local configuration if the cache is empty, and randomly select a server node address in the registry center cluster at preset time intervals to initiate an HTTP request; when the server node of the registry center receives the HTTP request, it queries the latest cluster list and the connection count of each node in the registry center cluster. Based on the number of connections of each node and the preset allowed connection ratio threshold, calculate whether the proportion of the number of connections of each node in the cluster is within the allowed range of the configured proportion. If it is not within the range, it is determined that the load status of the node is abnormal. Each node is assigned a weight based on its number of connections. The weight of each node is the total number of connections in the cluster minus its own number of connections. The latest cluster list, the load status and weight of each node are sent to the client and cached by the client. The optimization unit is used to, when it is determined that the load of a connected registry center node is abnormal based on the load status of each node, reselect a registry center node to connect to according to the latest cluster list, the load status and weight of each node, and register and subscribe after successful connection; when the connection fails, connect to the next registry center node in the latest cluster list according to the weight; when it is determined that the load of a connected registry center node is normal based on the load status of each node, re-execute the step of randomly selecting a server node address in the registry center cluster and initiating an HTTP request every preset time period.
7. A method for ensuring the connection between a registration center and a load balancer server, characterized in that, include: The query unit is used to query the latest cluster list and the number of connections for each node in the registry center cluster when an HTTP request is received; The HTTP request is initiated by the client at preset time intervals by randomly selecting the address of a server node in the registration center cluster. The load status determination unit is used to calculate whether the proportion of each node's connection count in the cluster is within the allowed range of the configured proportion, based on the number of connections of each node and the preset allowed connection count ratio threshold. If it is not within the range, the load status of the node is determined to be abnormal. The sending unit is used to set the weight of each node according to the number of connections of each node. The weight of each node is the total number of connections of the cluster minus its own number of connections. The latest cluster list, the load status and weight of each node are sent to the client and cached by the client. When the client determines that the load of a connected registry center node is abnormal based on the load status of each node, it re-selects a registry center node to connect to according to the latest cluster list, the load status and weight of each node, and registers and subscribes after a successful connection. If the connection fails, it connects to the next registry center node in the latest cluster list according to the weight. When the client determines that the load of a connected registry center node is normal based on the load status of each node, it re-executes the step of randomly selecting a server node address in the registry center cluster every preset time interval to initiate an HTTP request.
8. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 4.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 4.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 4.