Load balancing method, device and equipment for message queue system
By introducing proxy nodes into the message queue system, the dual-layer load balancing is solved, and the problem of excessive impact of load balancing policy adjustment in the existing technology is solved, and the system performance is improved.
Patent Information
- Application Number
- CN202510059900.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-05-13
AI Technical Summary
The impact range of the load balancing strategy adjustment of existing message queue systems is too large, resulting in poor overall performance. Especially when changes in consumer nodes and message storage nodes, global load balancing will be triggered, and the impact range will be too large.
Introduce proxy nodes to realize double-layer load balancing. By responding to changes in the connection status of the consumer node and the message storage node, the proxy nodes are triggered to perform local load balancing operations respectively to reduce the impact of load balancing policy adjustment.
It effectively reduces the impact range of load balancing strategy adjustment, improves the overall performance of the message queue system, and reduces the impact of load balancing on consumption.
Smart Images

Figure CN119996409A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of distributed systems, and in particular to a load balancing method, device and equipment for a message queue system. Background Art
[0002] In the message queue system, users can be divided into producers and consumers according to their roles. Producers refer to the generators of messages. After the messages are generated, they are sent to the message queue. Consumers refer to the users of messages. After the producers send messages to the message queue, the message queue will send the messages to the consumers.
[0003] In a distributed message queue system, the message queue system includes multiple devices, and the message consumers can also include multiple devices. At this time, the load balancing system is required to adjust the message delivery to ensure that the overall consumption of multiple devices of consumers is uniform. In addition, the load balancing system needs to perform corresponding load balancing in scenarios such as message queue system adjustment and consumer device distribution adjustment to ensure consumer load balancing. At this time, the load balancing of the message queue system will determine the overall consumption performance of the message queue system.
[0004] At present, a single-layer load balancing system is usually used in the load balancing system. Changes in consumer nodes and message storage nodes will cause the overall message queue system to be load balanced, resulting in a large impact range of load balancing strategy adjustment, which in turn leads to poor overall performance of the message queue system. Summary of the invention
[0005] In view of this, embodiments of the present application provide a load balancing method, apparatus, and device for a message queue system to improve the overall performance of the message queue system.
[0006] To solve the above problems, the technical solutions provided in the embodiments of the present application are as follows:
[0007] In a first aspect, an embodiment of the present application provides a load balancing method for a message queue system, wherein the message queue system includes a consumer node, a proxy node, and a message storage node, and the method includes:
[0008] In response to a change in the connection state of a target consumer node, triggering a first proxy node to perform a load balancing operation on a consumer node connected to the first proxy node; the target consumer node is any one of the consumer nodes, and the first proxy node is a proxy node connected to the target consumer node;
[0009] In response to a change in the connection state of a target message storage node, a second proxy node is triggered to perform a load balancing operation on the message storage node, the second proxy node being a proxy node connected to the target message storage node.
[0010] In a second aspect, an embodiment of the present application provides a load balancing device for a message queue system, wherein the message queue system includes a consumer node, a proxy node, and a message storage node, and the device includes:
[0011] A first load balancing unit, configured to trigger a first proxy node to perform a load balancing operation on a consumer node connected to the first proxy node in response to a change in the connection state of a target consumer node; the target consumer node is any one of the consumer nodes, and the first proxy node is a proxy node connected to the target consumer node;
[0012] The second load balancing unit is used to trigger a second proxy node to perform a load balancing operation on the message storage node in response to a change in the connection state of the target message storage node, where the second proxy node is a proxy node connected to the target message storage node.
[0013] In a third aspect, an embodiment of the present application provides a load balancing device for a message queue system, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a load balancing method for a message queue system as described above is implemented.
[0014] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes the load balancing method of the message queue system as described above.
[0015] It can be seen that the embodiments of the present application have the following beneficial effects:
[0016] In an embodiment of the present application, a proxy node is added to the message queue system, and a two-layer load balancing is implemented based on the proxy node. When the connection state of the target consumer node changes, only the first proxy node connected to the target consumer node is triggered to perform a load balancing operation on the consumer node, and other consumer nodes and message storage nodes are not affected. When the connection state of the target message storage node changes, only the second proxy node related to the change in the connection state is triggered to perform a load balancing operation on the message storage node. That is, the load balancing strategy will only be adjusted in a local range, which effectively reduces the impact range of the load balancing strategy adjustment and improves the overall performance of the message queue system. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of an exemplary application scenario provided for an embodiment of the present application;
[0018] Figure 2A flow chart of a load balancing method for a message queue system provided in an embodiment of the present application;
[0019] Figure 3 Schematic diagram of the impact range of Local Rebalance in an embodiment of the present application;
[0020] Figure 4 Schematic diagram of the impact range of Remote Rebalance in the embodiment of the present application;
[0021] Figure 5 A schematic diagram of a load balancing device for a message queue system provided in an embodiment of the present application;
[0022] Figure 6 A schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0024] In order to facilitate understanding and explanation of the technical solution provided by the embodiments of the present application, the background technology of the embodiments of the present application will be described below.
[0025] In a message queue system (such as the Kafka system), the data of a Topic will be distributed on multiple different Broker nodes (i.e., message storage nodes), and each Broker node is responsible for managing the partitions of each Topic. Partitions are units for parallel processing by producers and consumers. The number of partitions of a Topic limits the maximum number of active consumers in each consumer group. A consumer group is a logical group that groups multiple consumers to balance the load of partitions. When a new consumer joins or the number of subscribed topics changes, a rebalance operation is triggered, which is a mechanism for transferring the ownership of a partition from one consumer to another in the same consumer group.
[0026] In a message queue system (such as Rocketmq), the data of a Topic will be distributed on multiple different Broker nodes, and each Broker has a queue of data. Rocketmq's rebalancing mechanism refers to: redistributing multiple queues under a Topic among multiple consumer instances (consumer nodes) under the same consumer group to maximize the parallelism of message processing.
[0027] Rebalancing is an important operation to ensure load balancing in the message queue system. However, the rebalancing operation may also bring certain side effects, such as consumption suspension, repeated consumption, and fluctuation of consumption traffic.
[0028] Currently, in the design of message queue systems, the actions that trigger rebalancing operations include: maintenance operations such as downtime and upgrades of a single server component (such as Broker nodes of Kafka and Rocketmq); Topic expansion operations, such as expanding Partitions of Kafka and expanding Queues of Rocketmq; abnormal downtime and restart of a single consumer; proactive expansion or reduction of consumers; changes in Topic subscription information, etc.
[0029] In the load balancing system, a single-layer load balancing system is usually used. Changes in consumer nodes and message storage nodes will cause the overall message queue system to be load balanced. In addition, a decentralized load balancing system is usually used in the load balancing system. A decentralized load balancing system means that there is no central node for global consideration in the load balancing system, and only the local optimal solution is considered. The load balancing system is a load balancing system that runs rebalance tasks regularly.
[0030] Therefore, the technical problems of the current solution include: the restart and addition of consumers will affect the normal consumption of other consumers, and the rebalancing operation has a relatively large impact, which will spread to all consumers in the entire consumer group. The normal operation and maintenance operations of the server node will also have a relatively large impact. Frequent rebalancing operations will reduce the consumption speed of messages. Most of the time, consumption and rebalancing operations are repeated. The existing load balancing mechanism cannot control it, resulting in poor overall performance of the message queue system. In addition, the load balancing system is embedded in the message queue system and cannot be independently expanded when a bottleneck is reached.
[0031] Based on this, the embodiments of the present application provide a load balancing method, device and equipment for a message queue system, which changes the original single-layer load balancing system into a two-layer load balancing based on proxy nodes, and calculates the load balancing through the central node, and the proxy node executes the load balancing, thereby reducing the delay and impact range of each load balancing of the consumer and improving the performance of the load balancing system.
[0032] Specifically, it can reduce the impact of a single load balancing operation, including the impact of a single consumer restart and addition, as well as the impact of server expansion and restart. Control the frequency of load balancing to avoid frequent rebalancing operations. To improve the performance of the load balancing system, an independent distributed system can be used to replace the original service thread, improve fault tolerance, and provide independent expansion capabilities for the load balancing system.
[0033] In order to facilitate understanding of the load balancing method of the message queue system provided in the embodiment of the present application, Figure 1 See the example scenario shown in the figure. Figure 1 As shown, this figure is a schematic diagram of an exemplary application scenario provided in an embodiment of the present application.
[0034] The embodiment of the present application can be applied to a message queue system, which includes a server-side Broker node (message storage node), a server-side Proxy node (proxy node), and a Consumer node (consumer node). The Broker node is responsible for the storage and reading and writing of data, the Proxy node is responsible for the management of consumption, and the Consumer is used to consume data. After the data is written to the Broker node, the Proxy node forwards the data to the Consumer to complete a consumption action.
[0035] In the message queue system, each data partition of the Broker node is called a data queue (Queue), and a Broker node can include multiple Queues. Each Queue will be uniquely assigned to a Proxy node, and the Proxy node will be responsible for forwarding all traffic of the Queue. Multiple Queues can be assigned to each Proxy node. Each Consumer node will uniquely connect to a Proxy node and bear part of the traffic on the Proxy node.
[0036] See also Figure 1As shown, for example, the data of a Topic is distributed on two Broker nodes Broker1 and Broker2. Each Broker node includes three data queues Queue0, Queue1, and Queue2. Each Queue will be assigned to a Proxy node. When there are two Proxy nodes Proxy1 and Proxy2, each Proxy node will be assigned to three Queues. Among them, Queue0 and Queue1 of Broker1 and Queue2 of Broker2 are assigned to Proxy1, and Queue0 and Queue1 of Broker2 and Queue2 of Broker1 are assigned to Proxy2. Each Consumer node is connected to a Proxy node, among which Consumer nodes concurrent consumer1, concurrent consumer2, and concurrentconsumer3 are connected to Proxy1, and Consumer nodes order consumer1, order consumer2, and orderconsumer3 are connected to Proxy2. The Consumer node can obtain data from one or more queues of the Proxy. Among them, the Consumer nodes concurrent consumer1, concurrent consumer2, and concurrent consumer3 are connected to Proxy1 to obtain data from the three queues of Proxy1, and the Consumer nodes order consumer1, orderconsumer2, and order consumer3 obtain data from one queue of Proxy2.
[0037] In the embodiment of the present application, a two-layer load balancing method with two Rebalances is used to handle the rebalancing problem. The two-layer load balancing includes the Rebalance tasks that occur when the Consumer node is reconnected and the Rebalance tasks that occur when the Broker node is reconnected, and their impacts are isolated from each other. Among them, the Rebalance task between the Proxy node and the Broker node is called Remote Rebalance, and the Rebalance task between the Proxy node and the Consumer node is called Local Rebalance. For the description of Remote Rebalance and Local Rebalance, please refer to the subsequent embodiments, which will not be repeated here. In the embodiment of the present application, Rebalance can be understood as a load balancing operation.
[0038] Those skilled in the art will understand that Figure 1 The framework diagram shown is only an example in which the embodiments of the present application can be implemented. The scope of application of the embodiments of the present application is not limited by any aspect of the framework.
[0039] To facilitate understanding of the embodiments of the present application, a load balancing method for a message queue system provided in an embodiment of the present application is described below with reference to the accompanying drawings.
[0040] See also Figure 2 As shown, this figure is a flow chart of a load balancing method for a message queue system provided by an embodiment of the present application, such as Figure 2 As shown, the method may include S201-S202:
[0041] S201: In response to a change in the connection state of a target consumer node, trigger a first proxy node to perform a load balancing operation on a consumer node connected to the first proxy node. The target consumer node is any one of the consumer nodes, and the first proxy node is a proxy node connected to the target consumer node.
[0042] In an embodiment of the present application, the message queue system may include multiple consumer nodes (Consumer nodes), multiple proxy nodes (Proxy nodes) and multiple message storage nodes (Broker nodes). When the connection status of any Consumer node (i.e., the target Consumer node) changes, a Local Rebalance is triggered. Changes in connection status include joining, exiting or restarting the target Consumer node. Specifically, triggering a Local Rebalance in S201 can be understood as triggering the first proxy node connected to the target Consumer node to perform a load balancing operation on the connected Consumer node. That is, the first proxy node will trigger a small-scale load balancing, and other Consumer nodes will follow the principle of sticky distribution, and the connection with the original Proxy node will not change. Consumer nodes connected to other Proxy nodes will not be affected, and the connection between the Proxy node and the Broker node will not be affected.
[0043] S202: In response to a change in the connection state of the target message storage node, trigger a second proxy node to perform a load balancing operation on the message storage node. The second proxy node is a proxy node connected to the target message storage node.
[0044] When the connection status of any Broker node (i.e., the target Broker node) changes, a RemoteRebalance is triggered. Changes in connection status include the joining, exiting, or restarting of the target Broker node. Specifically, triggering a Remote Rebalance in S202 can be understood as triggering the second proxy node to perform a load balancing operation on the connected Broker node. The second proxy node can be understood as a proxy node related to the change in the connection status of the target Broker node. The second proxy node will trigger a small-scale load balancing, and the Consumer nodes connected to other Proxy nodes will not be affected, and the connections between other Proxy nodes and Broker nodes will not be affected.
[0045] In an embodiment of the present application, a proxy node is added to the message queue system, and a two-layer load balancing is implemented based on the proxy node. When the connection state of the target consumer node changes, only the first proxy node connected to the target consumer node is triggered to perform a load balancing operation on the consumer node, and other consumer nodes and message storage nodes are not affected. When the connection state of the target message storage node changes, only the second proxy node related to the change in the connection state is triggered to perform a load balancing operation on the message storage node. That is, the load balancing strategy will only be adjusted in a local range, which effectively reduces the impact range of the load balancing strategy adjustment and improves the overall performance of the message queue system.
[0046] The following further describes Local Rebalance in the embodiments of the present application.
[0047] In a possible implementation, S201, in response to a change in the connection state of the target consumer node, triggering the first proxy node to perform a load balancing operation on the consumer node connected to the first proxy node may include:
[0048] A1: In response to the target consumer node disconnecting from the first proxy node, triggering the first proxy node to distribute the traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node.
[0049] When the target Consumer node exits the message queue system, it disconnects from the first proxy node. The first proxy node will redistribute the traffic of each data queue of the first proxy node to all Consumer nodes connected to the first proxy node, affecting only the Consumer nodes connected to the first proxy node. For example, the first proxy node can evenly distribute the traffic of each data queue of the first proxy node to all Consumer nodes connected to the first proxy node, and the first proxy node can distribute the traffic of each data queue of the first proxy node to all Consumer nodes connected to the first proxy node according to the correspondence between the data queue and the Consumer node.
[0050] A2: In response to the target consumer node being connected to the first proxy node, triggering the first proxy node to distribute traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node.
[0051] When the target Consumer node joins the message queue system, it will select the proxy node with the lower current load to connect to achieve the global optimal load balancing, or the target Consumer node can also connect to any proxy node. When the target Consumer node is connected to a first proxy node, the first proxy node will evenly distribute the traffic of each data queue of the first proxy node to all Consumer nodes connected to the first proxy node, including the target Consumer node, and only affect the Consumer nodes connected to the first proxy node.
[0052] When the target Consumer node restarts, it is equivalent to exiting the message queue system first and then joining the message queue system. When the target Consumer node exits the message queue system, it disconnects from the first proxy node, triggering the first proxy node to distribute the traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node. Then rejoin the message queue system and select a proxy node with a lower current load. For example, the target Consumer node is connected to the first proxy node, triggering the first proxy node to distribute the traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node. It is understandable that when the target Consumer node restarts, the proxy nodes connected before and after the restart can be different proxy nodes. In addition, the Consumer node itself will periodically obtain the load of the Proxy node and connect to the low-load Proxy node to achieve global optimal load balancing.
[0053] See also Figure 3As shown, a schematic diagram of the impact range of Local Rebalance is shown. The impact range of Local Rebalance is in the dashed box. For example, if the target Consumer node concurrent consumer1 is disconnected from the first proxy node Proxy1, the first proxy node Proxy1 will redistribute the traffic of Queue0, Queue1, and Queue2 of Proxy1 to other Consumer nodes concurrent consumer2 and concurrent consumer3 connected to Proxy1. In this way, only the Consumer nodes connected to the first proxy node Proxy1 are affected, and the impact range of load balancing is reduced.
[0054] The following further describes Remote Rebalance in the embodiments of the present application.
[0055] In a possible implementation, S202, in response to a change in the connection state of the target message storage node, triggering the second proxy node to perform a load balancing operation on the message storage node may include:
[0056] B1: In response to the target message storage node disconnecting from the second proxy node, triggering the allocation of traffic of data queues of other message storage nodes to the second proxy node.
[0057] When the target Broker node exits the message queue system, it disconnects from the second proxy node, and the second proxy node no longer processes the traffic of the data queue of the target Broker node. The target Broker node can be connected to at least one second proxy node, so the second proxy node can be one or more. At this time, the number of data queues processed by the second proxy node decreases, triggering the allocation of the data queues of the Broker nodes processed by other proxy nodes to the second proxy node for processing. For example, the target Broker node includes 2 data queues. After disconnecting from the second proxy node Proxy1, one data queue of each of the other Broker nodes processed by other proxy nodes Proxy2 and Proxy3 can be allocated to Proxy1, so that the number of data queues of the Broker nodes processed by proxy nodes Proxy1, Proxy2 and Proxy3 is as balanced as possible.
[0058] B2: In response to the target message storage node being connected to the second proxy node, triggering allocation of traffic of the data queue of the target message storage node to the second proxy node.
[0059] When the target Broker node joins the message queue system, there will be a proxy node with a lower current load connected to the target Broker node, and the one or more proxy nodes connected to the target Broker node are the second proxy nodes. The second proxy nodes are triggered to share the traffic of each data queue of the target Broker node, that is, the data queue of the target Broker node is allocated to each second proxy node for processing.
[0060] When the target Broker node restarts, it is equivalent to exiting the message queue system first and then joining the message queue system. When the target Broker node exits the message queue system, it disconnects from the second proxy node, triggering the allocation of the data queue of the Broker node processed by other proxy nodes to the second proxy node for processing. When the target Broker node joins the message queue system, the target Broker node connects to the second proxy node, triggering the allocation of the traffic of the data queue of the target message storage node to the second proxy node. It is understandable that when the target Broker node restarts, the proxy nodes connected before and after the restart can be different proxy nodes.
[0061] In addition, when the data queue processed by the second proxy node is sent and changed, LocalRebalance may be triggered again to trigger the second proxy node to perform a load balancing operation on the consumer nodes connected to the second proxy node.
[0062] See also Figure 4 As shown, a schematic diagram of the scope of influence of Remote Rebalance is shown. The scope of influence of Remote Rebalance is in the dashed box. For example, if the target Broker node Broker 1 disconnects from the second proxy node Proxy1, a part of the data queue of Broker 2 processed by other proxy nodes Proxy2 will be assigned to the second proxy node Proxy1 for processing. In this way, the connection between the proxy nodes Proxy1 and Proxy2 and the Broker node Broker 2 will be affected, but it will still not have an impact on the global Proxy nodes and Broker nodes, and the load balancing impact range will be reduced.
[0063] The embodiment of the present application can also handle load balancing operations in a scenario where the connection status of a proxy node changes.
[0064] In a possible implementation, the method provided in the embodiment of the present application may further include:
[0065] In response to the third proxy node joining the message queue system, when the target consumer node is connected to the third proxy node, it triggers the distribution of the traffic of the data queue of the message storage node to the third proxy node, and triggers the third proxy node to distribute the traffic of the data queue of the third proxy node to the consumer node currently connected to the third proxy node.
[0066] The impact of changes in the connection status between the above Consumer nodes and Broker nodes will be reduced to a very small range. When the Proxy node exits or joins, it will also have a relatively small impact.
[0067] When the third proxy node joins the message queue system, there is no queue allocation at first. When the Consumer node detects the low-load Proxy node, some Consumer nodes will abandon the original connection and reconnect to the newly joined third proxy node. The third proxy node triggers a Remote Rebalance to seize some queues, that is, triggers the allocation of the traffic of the Broker node's data queue to the third proxy node, and also triggers a Local Rebalance to allocate the traffic of the third proxy node's data queue to the consumer node currently connected to the third proxy node.
[0068] In a possible implementation, the method provided in the embodiment of the present application may further include:
[0069] In response to the third proxy node exiting the message queue system, the consumer node connected to the third proxy node is triggered to disconnect from the third proxy node, and the traffic of the data queue of the third proxy node is triggered to be distributed to other proxy nodes.
[0070] When a third-party proxy node needs to exit the message queue system, it will first hide itself in the service route discovery. The Consumer node will find that the third-party proxy node is not in the service route, and then disconnect from the third-party proxy node, reconnect to other proxy nodes to trigger Local Rebalance. When there is no Consumer node connected to the third-party proxy node, Remote Rebalance is triggered to release the Queue it holds, and the released Queue is assigned to other proxy nodes for processing.
[0071] Compared with the single-layer load balancing design, the above two-layer load balancing design can reduce the impact of operations such as joining, exiting, and restarting of all components (Consumer nodes, Broker nodes, and Proxy nodes). Based on the access of proxy nodes, when there are local changes in Consumer nodes and Broker nodes, load balancing operations will only be adjusted in the local range, without affecting the normal consumption behavior of consumer nodes of other proxy nodes, thereby effectively reducing the impact of load balancing on consumption.
[0072] Based on the above embodiment, when triggering Remote Rebalance, there is room for further optimization on how to more efficiently allocate the data queue of the Broker node to the Proxy node when the Proxy node and the Broker node perform the Rebalance task. In the embodiment of the present application, a centralized load balancing system is also provided to further improve the efficiency of triggering Remote Rebalance.
[0073] In practical applications, a centralized load balancing system can be composed of independent distributed services, which are called Coordinators, including multiple nodes, one of which is the master node and the others are slave nodes. When a slave node detects a service anomaly on the master node, it will preempt and try to become the master node.
[0074] The load balancing system has two functions: calculating the load balancing results and applying the load balancing results to the consumption scenario. Based on the centralized load balancing system, the above two functions are split, the master node calculates the load balancing results, and the proxy node in the message queue system is responsible for executing the load balancing results.
[0075] The centralized load balancing system can use different types of queue allocation strategies according to the requirements of actual applications, especially in scenarios with multiple computer rooms or across computer rooms. It can support the following modes: average allocation among multiple computer rooms, priority allocation to the computer room, strict allocation to the same computer room, broadcast consumption in all computer rooms, and weight allocation according to the number of proxy node connections, thereby generating a load balancing result on how to allocate the Queue of the Broker node to the Proxy node.
[0076] In a possible implementation, the method provided in the embodiment of the present application may further include:
[0077] C1: Get the metadata information of the proxy node through the central node.
[0078] During the initialization process of the Coordinator, after the Coordinator determines the master node, the master node as the central node needs to wait to establish connections with all the Proxy nodes, and the Proxy nodes report the metadata information of the Proxy nodes. Metadata information includes all the Group subscription information in the Proxy node. The Group can be understood as a consumer group, so that it can be determined on which Proxy nodes each Group is distributed. When the central node collects the Group subscription information in all the Proxy nodes, it can form the correct Group subscription topology for the entire cluster. At the same time, the central node can also obtain the metadata of the topic and determine the relevant information of the data queue of the Broker node, so that rebalance can be performed correctly.
[0079] C2: Determine the load balancing result according to the metadata information, and send the load balancing result to the second proxy node.
[0080] In actual applications, Rebalance will be triggered in the following situations: changes in the subscription information of the Group, changes in the metadata of the topic, the first startup of the Coordinator, restart of the Broker node or the Proxy node, and other operation and maintenance changes. When Rebalance needs to be triggered, the central node can determine the load balancing result based on the metadata information, for example, based on the metadata of the topic, the list of Proxy nodes determined by the Group subscription information, and the Rebalance strategy, to generate the load balancing result. Determine whether the load balancing result has changed. If so, broadcast it to all Rroxy nodes subscribed to the Group. In the Remote Rebalance scenario of the embodiment of the present application, the load balancing result can be sent to the second proxy node.
[0081] The specific implementation of triggering the second proxy node to perform a load balancing operation on the message storage node in S202 may include:
[0082] The second proxy node is triggered to perform a load balancing operation on the message storage node according to the load balancing result.
[0083] After receiving the load balancing result, the second proxy node applies it locally and then returns a success status code to the central node. Specifically, the load balancing result includes the correspondence between the data queues of the Proxy node and the Broker node. For example, Queue0 and Queue1 of Broker1 and Queue2 of Broker2 are assigned to Proxy1, and Queue0 and Queue1 of Broker2 and Queue2 of Broker1 are assigned to Proxy2. After the central node receives the status codes of all the second proxy nodes of this Remote Rebalance, it means that this round of Remote Rebalance is over.
[0084] Through the central node, the second proxy node can directly perform load balancing operations according to the load balancing results, thereby improving the efficiency of the load balancing operation.
[0085] The embodiment of the present application can also perform rebalance conflict resolution. In a possible implementation, the method provided by the embodiment of the present application can also include:
[0086] If the load balancing result is re-determined when the second proxy node has not completed the load balancing operation, the load balancing result is sent to the second proxy node after a preset delay time.
[0087] If the second proxy node performs load balancing but has not completed the load balancing operation, that is, has not returned a success status code to the central node, and if a new load balancing result is generated, such as changes in the topic metadata or proxy node list, and rebalancing is required, then a rebalancing conflict occurs. At this time, you need to wait for the completion of the first round of rebalancing. When the first round of rebalancing is completed, the second round of rebalancing will be executed immediately.
[0088] If the rebalance is not completed, a delay task will be submitted to delay the second round of rebalance. After the preset delay time, a new rebalance will be executed regardless of whether the first round of rebalance is completed. For example, the preset delay time is 20 seconds, and the embodiment of the present application does not limit the preset delay time.
[0089] This can avoid multiple changes in server nodes in a short period of time, trigger multiple rebalance tasks, and affect the stability of user consumption. This can control the frequency of load balancing and avoid frequent rebalance.
[0090] In a possible implementation, the load balancing result carries a sequence number, and the specific implementation of triggering the second proxy node to perform a load balancing operation on the message storage node according to the load balancing result may include:
[0091] Triggering the second proxy node to determine whether the sequence number of the load balancing result is greater than the sequence number of the load balancing result corresponding to the executed load balancing operation;
[0092] If it is greater, the second proxy node is triggered to perform a load balancing operation on the message storage node according to the load balancing result.
[0093] In order to distinguish multiple load balancing results, the order in which the load balancing results are generated can be marked according to the serial number. The serial number is increased by one after each load balancing result is generated. The load balancing result needs to carry the serial number.
[0094] When the second proxy node receives the load balancing result, it compares the serial number of the load balancing result corresponding to the executed load balancing operation with the serial number of the new load balancing result received. If the serial number of the newly received load balancing result is larger, the new load balancing result will be directly effective. If they are the same or smaller, the load balancing operation will not be performed based on the load balancing result, and the load balancing result can be discarded. After the second proxy node completes the load balancing operation based on the new load balancing result, a successful status code is returned to the central node.
[0095] The design of the centralized load balancing system in the embodiment of the present application greatly improves the efficiency of load balancing, and can quickly generate load balancing results when the server or client changes, reducing problems such as consumption delay and consumption accumulation caused by low load balancing efficiency. An independent distributed system is used to replace the original service thread, improve fault tolerance, and provide independent expansion capabilities for the load balancing system.
[0096] Based on the load balancing method of a message queue system provided by the above method embodiment, the embodiment of the present application also provides a load balancing device of a message queue system, which will be described below in conjunction with the accompanying drawings.
[0097] See also Figure 5 As shown in FIG. 1 , this figure is a schematic diagram of the structure of a load balancing device of a message queue system provided in an embodiment of the present application. The message queue system includes a consumer node, a proxy node, and a message storage node, such as Figure 5 As shown, the load balancing device of the message queue system includes:
[0098] A first load balancing unit 501 is used to trigger a first proxy node to perform a load balancing operation on a consumer node connected to the first proxy node in response to a change in the connection state of a target consumer node; the target consumer node is any one of the consumer nodes, and the first proxy node is a proxy node connected to the target consumer node;
[0099] The second load balancing unit 502 is used to trigger a second proxy node to perform a load balancing operation on the message storage node in response to a change in the connection state of the target message storage node, where the second proxy node is a proxy node connected to the target message storage node.
[0100] In a possible implementation manner, the first load balancing unit is specifically configured to:
[0101] In response to the target consumer node disconnecting from the first proxy node, triggering the first proxy node to distribute the traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node;
[0102] In response to the target consumer node being connected to the first proxy node, the first proxy node is triggered to distribute traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node.
[0103] In a possible implementation manner, the second load balancing unit is specifically configured to:
[0104] In response to the target message storage node disconnecting from the second proxy node, triggering the allocation of traffic of data queues of other message storage nodes to the second proxy node;
[0105] In response to the target message storage node being connected to the second proxy node, triggering the allocation of traffic of the data queue of the target message storage node to the second proxy node.
[0106] In a possible implementation manner, the device further includes:
[0107] The third load balancing unit is used to respond to the third proxy node joining the message queue system. When the target consumer node is connected to the third proxy node, it triggers the distribution of the traffic of the data queue of the message storage node to the third proxy node, and triggers the third proxy node to distribute the traffic of the data queue of the third proxy node to the consumer node currently connected to the third proxy node.
[0108] In a possible implementation manner, the device further includes:
[0109] The fourth load balancing unit is used to trigger the consumer node connected to the third proxy node to disconnect from the third proxy node in response to the third proxy node exiting the message queue system, and to trigger the distribution of the traffic of the data queue of the third proxy node to other proxy nodes.
[0110] In a possible implementation manner, the device further includes:
[0111] An acquisition unit, used for acquiring metadata information of the proxy node through a central node;
[0112] a sending unit, configured to determine a load balancing result according to the metadata information, and send the load balancing result to the second proxy node;
[0113] The second load balancing unit is specifically used for:
[0114] The second proxy node is triggered to perform a load balancing operation on the message storage node according to the load balancing result.
[0115] In a possible implementation manner, the sending unit is further configured to:
[0116] If the load balancing result is re-determined when the second proxy node has not completed the load balancing operation, the load balancing result is sent to the second proxy node after a preset delay time.
[0117] In a possible implementation manner, the load balancing result carries a sequence number, and the second load balancing unit is specifically configured to:
[0118] Triggering the second proxy node to determine whether the sequence number of the load balancing result is greater than the sequence number of the load balancing result corresponding to the executed load balancing operation;
[0119] If it is greater, trigger the second proxy node to perform a load balancing operation on the message storage node according to the load balancing result.
[0120] An embodiment of the present application further provides a computer program product, including computer program instructions. When the computer program instructions are executed on a computer, the computer executes the load balancing method for a message queue system as described in any one of the above items.
[0121] Based on the load balancing method of a message queue system provided by the above method embodiment, the present application also provides an electronic device, including: one or more processors; a storage device, on which one or more programs are stored, when the one or more programs are executed by the one or more processors, the one or more processors implement the load balancing method of the message queue system described in any of the above embodiments.
[0122] Reference below Figure 6 , which shows a schematic diagram of the structure of an electronic device 1300 suitable for implementing the embodiment of the present application. The terminal device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (portable android devices), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs (televisions), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0123] like Figure 6 As shown, the electronic device 1300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1302 or a program loaded from a storage device 1306 into a random access memory (RAM) 1303. In the RAM 1303, various programs and data required for the operation of the electronic device 1300 are also stored. The processing device 1301, the ROM 1302, and the RAM 1303 are connected to each other via a bus 1304. An input / output (I / O) interface 1305 is also connected to the bus 1304.
[0124] Typically, the following devices may be connected to the I / O interface 1305: an input device 1306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1306 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1309. The communication device 1309 may allow the electronic device 1300 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 1300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0125] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 1309, or installed from the storage device 1306, or installed from the ROM 1302. When the computer program is executed by the processing device 1301, the above-mentioned functions defined in the method of the embodiment of the present application are executed.
[0126] The electronic device provided in the embodiment of the present application and the load balancing method of a message queue system provided in the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0127] Based on the load balancing method of a message queue system provided by the above method embodiment, an embodiment of the present application provides a computer-readable medium on which a computer program is stored, wherein when the program is executed by a processor, the load balancing method of a message queue system as described in any of the above embodiments is implemented.
[0128] It should be noted that the computer-readable medium in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In an embodiment of the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0129] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0130] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0131] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the load balancing method of the message queue system.
[0132] The computer program code for performing the operation of the embodiment of the present application can be written in one or more programming languages or a combination thereof, and the above-mentioned 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 "C" language or similar programming languages. The program code can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can 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 it can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0133] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0134] The units involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the unit / module does not, in some cases, constitute a limitation on the unit itself.
[0135] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0136] In the context of the present application embodiment, machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable medium can include but is not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the above. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.
[0137] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system or device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0138] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0139] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0140] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0141] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A load balancing method for a message queue system, characterized in that: The message queue system includes a consumer node, a proxy node and a message storage node, and the method includes: In response to a change in the connection state of a target consumer node, triggering a first proxy node to perform a load balancing operation on a consumer node connected to the first proxy node; the target consumer node is any one of the consumer nodes, and the first proxy node is a proxy node connected to the target consumer node; In response to a change in the connection state of a target message storage node, a second proxy node is triggered to perform a load balancing operation on the message storage node, the second proxy node being a proxy node connected to the target message storage node.
2. The method according to claim 1, characterized in that The step of triggering the first proxy node to perform a load balancing operation on the consumer nodes connected to the first proxy node in response to a change in the connection state of the target consumer node comprises: In response to the target consumer node disconnecting from the first proxy node, triggering the first proxy node to distribute the traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node; In response to the target consumer node being connected to the first proxy node, the first proxy node is triggered to distribute traffic of the data queue of the first proxy node to the consumer node currently connected to the first proxy node.
3. The method according to claim 1, characterized in that The step of triggering the second proxy node to perform a load balancing operation on the message storage node in response to a change in the connection state of the target message storage node comprises: In response to the target message storage node disconnecting from the second proxy node, triggering the allocation of traffic of data queues of other message storage nodes to the second proxy node; In response to the target message storage node being connected to the second proxy node, triggering the allocation of traffic of the data queue of the target message storage node to the second proxy node.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: In response to the third proxy node joining the message queue system, when the target consumer node is connected to the third proxy node, it triggers the allocation of traffic of the data queue of the message storage node to the third proxy node, and triggers the third proxy node to allocate traffic of the data queue of the third proxy node to the consumer node currently connected to the third proxy node.
5. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: In response to the third proxy node exiting the message queue system, the consumer node connected to the third proxy node is triggered to disconnect from the third proxy node, and the traffic of the data queue of the third proxy node is triggered to be distributed to other proxy nodes.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Obtaining metadata information of the proxy node through a central node; Determine a load balancing result according to the metadata information, and send the load balancing result to the second proxy node; The triggering the second proxy node to perform a load balancing operation on the message storage node includes: The second proxy node is triggered to perform a load balancing operation on the message storage node according to the load balancing result.
7. The method according to claim 6, characterized in that The method further comprises: If the load balancing result is re-determined when the second proxy node has not completed the load balancing operation, the load balancing result is sent to the second proxy node after a preset delay time.
8. The method according to claim 6, characterized in that The load balancing result carries a sequence number, and the triggering of the second proxy node to perform a load balancing operation on the message storage node according to the load balancing result includes: Triggering the second proxy node to determine whether the sequence number of the load balancing result is greater than the sequence number of the load balancing result corresponding to the executed load balancing operation; If it is greater, trigger the second proxy node to perform a load balancing operation on the message storage node according to the load balancing result.
9. A load balancing device for a message queue system, characterized in that: The message queue system includes a consumer node, a proxy node and a message storage node, and the device includes: A first load balancing unit, configured to trigger a first proxy node to perform a load balancing operation on a consumer node connected to the first proxy node in response to a change in the connection state of a target consumer node; the target consumer node is any one of the consumer nodes, and the first proxy node is a proxy node connected to the target consumer node; The second load balancing unit is used to trigger a second proxy node to perform a load balancing operation on the message storage node in response to a change in the connection state of the target message storage node, where the second proxy node is a proxy node connected to the target message storage node.
10. A load balancing device for a message queue system, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the load balancing method for the message queue system according to any one of claims 1 to 8 is implemented.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the load balancing method for a message queue system according to any one of claims 1 to 8.