Message processing method, device and electronic device
By sending messages to be consumed between the producer node and the consumer node and receiving feedback messages, load balancing is performed based on the pressure-related information of the consumer node, which solves the problem of poor load balancing effect in the prior art, and improves the Efficiency and accuracy of message processing.
Patent Information
- Application Number
- CN202210986802.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-17
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-08-17
Smart Images

Figure CN116132367B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a message processing method, device and electronic equipment. Background Art
[0002] With the expansion of Internet business areas, the business volume carried in various business areas is getting larger and larger. The traditional point-to-point information interaction mode has long been unable to carry business needs. Under this premise, a horizontal expansion cluster mode has been introduced, such as message consumer clusters, message producer clusters, and message middleware clusters.
[0003] In practical applications, cluster-to-cluster interaction, whether it is direct interaction between consumer nodes and producer nodes through the Transmission Control Protocol (TCP) / Hypertext Transfer Protocol (HTTP), or interaction between producer nodes and consumer nodes through the message middleware after the introduction of the message middleware, faces the problem of allowing instances in each consumer node of the consumer cluster to consume messages at a certain speed without causing accumulation, that is, load balancing between consumer nodes. At present, the amount of messages consumed by each consumer node is usually equalized based on the sharding algorithm. This load balancing method fails to take into account the actual situation of the consumer nodes, resulting in poor load balancing effect. Summary of the invention
[0004] The embodiments of the present invention provide a message processing method, device and electronic device to solve the problem of poor load balancing effect in the prior art.
[0005] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:
[0006] In a first aspect, an embodiment of the present invention provides a message processing method, which is applied to a first producer node, wherein a communication connection is established between the first producer node and at least two consumer nodes, and the method includes:
[0007] Sending a message to be consumed to at least one consumer node of the at least two consumer nodes;
[0008] Respectively receiving a feedback message sent by each consumer node of the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node, and the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node;
[0009] Load balancing is performed according to pressure-related information of part or all of the at least two consumer nodes.
[0010] In a second aspect, an embodiment of the present invention further provides a message processing method, which is applied to a first consumer node, and the method includes:
[0011] Receive the message to be consumed sent by the first producer node;
[0012] Perform message consumption on the message to be consumed;
[0013] A feedback message for the message to be consumed is sent to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node, and the pressure-related information of the first consumer node is used to characterize the load pressure status of the first consumer node.
[0014] In a third aspect, an embodiment of the present invention further provides a message processing device, which is applied to a first producer node, wherein a communication connection is established between the first producer node and at least two consumer nodes, and the device includes:
[0015] A first sending module, configured to send a message to be consumed to at least one consumer node among the at least two consumer nodes;
[0016] A first receiving module, configured to respectively receive a feedback message sent by each consumer node of the at least one consumer node in response to the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node, and the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node;
[0017] The load balancing module is used to perform load balancing according to pressure-related information of some or all of the at least two consumer nodes.
[0018] In a fourth aspect, an embodiment of the present invention further provides a message processing device, applied to a first consumer node, the device comprising:
[0019] A first receiving module, used to receive a message to be consumed sent by a first producer node;
[0020] A message consumption module, used for consuming the message to be consumed;
[0021] The first sending module is used to send a feedback message for the message to be consumed to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node, and the pressure-related information of the first consumer node is used to characterize the load pressure status of the first consumer node.
[0022] In a fifth aspect, an embodiment of the present invention further provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the message processing method provided in the first aspect are implemented, or the steps of the message processing method provided in the second aspect are implemented.
[0023] In the sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the message processing method provided in the first aspect are implemented, or the steps of the message processing method provided in the second aspect are implemented.
[0024] In an embodiment of the present invention, a first producer node sends a message to be consumed to at least one consumer node among at least two consumer nodes; respectively receives feedback messages sent by each consumer node among the at least one consumer node for the message to be consumed, wherein each feedback message carries pressure-related information of the corresponding consumer node; and performs load balancing according to pressure-related information of some or all of the at least two consumer nodes. Since the first producer node performs load balancing according to the actual pressure conditions of each message consumer node, the load balancing effect can be improved. In addition, since each consumer node carries the pressure-related information of the message consumer node in the feedback message for the message to be consumed, the network resource overhead of the pressure-related information feedback can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0026] Figure 1 is a schematic diagram of a point-to-point interaction provided by an embodiment of the present invention;
[0027] Figure 2 This is one of the schematic diagrams of inter-cluster interaction provided by an embodiment of the present invention;
[0028] Figure 3 is a flow chart of a message processing method provided by an embodiment of the present invention;
[0029] Figure 4 This is a second schematic diagram of an inter-cluster interaction provided by an embodiment of the present invention;
[0030] Figure 5This is a third schematic diagram of an inter-cluster interaction provided by an embodiment of the present invention;
[0031] Figure 6 is a flowchart of a message processing method provided by another embodiment of the present invention;
[0032] Figure 7 is a structural diagram of a message processing device provided by an embodiment of the present invention;
[0033] Figure 8 is a structural diagram of a message processing device provided by another embodiment of the present invention;
[0034] Fig. 9 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0036] For ease of understanding, some contents involved in the embodiments of the present invention are described below:
[0037] Load Balancing: It can be understood as distributing the work to multiple operating units for execution, such as Web servers, File Transfer Protocol (FTP) servers, enterprise key application servers and other mission-critical servers, so as to complete the work tasks together.
[0038] The producer node, also known as the message producer node, is the initiator of the business and is responsible for producing messages and providing them to the consumer node.
[0039] Consumer node: also known as message consumer node, is a business processor responsible for obtaining messages from producer nodes and performing business logic processing. Consumer nodes can obtain messages directly from producer nodes through synchronous interfaces or through message middleware.
[0040] Message middleware: also known as message queue, refers to the use of efficient and reliable message transmission mechanism for platform-independent data exchange, and the integration of distributed systems based on data communication. By providing message transmission and message queue models, process communication can be expanded in a distributed environment.
[0041] Input Output (IO) intensive: refers to the system's CPU performance being much better than that of the hard disk and memory. At this time, when the system is running, most of the time the CPU is waiting for I / O (hard disk / memory) read / write operations, and the CPU load is not high. In most cases, for distributed systems, the above IO usually refers to the network IO overhead.
[0042] Point-to-point interaction: It can also be called single-node interaction, that is, a producer node interacts with only one consumer node. For example, Figure 1 As shown, the producer node sends a message to the consumer node, and the consumer node returns a feedback message after processing the message. It can be understood that in the single-node interaction mode, there is no load balancing problem.
[0043] Inter-cluster interaction: that is, the interaction between multiple producer nodes and multiple consumer nodes, for example, Figure 2 As shown, each producer node in the producer cluster can interact with multiple consumers in the consumer cluster. The producer node sends a message to the consumer node, and the consumer node returns a feedback message after processing the message.
[0044] The embodiment of the present invention provides a message processing method, which is applied to a first producer node, wherein a communication connection is established between the first producer node and at least two consumer nodes. Figure 3 , Figure 3 is a flow chart of a message processing method provided by an embodiment of the present invention, such as Figure 3 As shown, the following steps are included:
[0045] Step 301: Send a message to be consumed to at least one consumer node among at least two consumer nodes.
[0046] In this embodiment, a communication connection is established between the first producer node and at least two consumer nodes, that is, each of the at least two consumer nodes can receive the message to be consumed sent by the first producer node. For example, Figure 4 As shown, each producer node can deliver messages to be consumed to multiple consumer nodes. Among them, the above-mentioned first producer node can be any producer node.
[0047] The at least one consumer node mentioned above may include some or all of the at least two consumer nodes mentioned above. In actual applications, the first consumer node may send messages to be consumed to all consumer nodes in one message delivery, or may only send messages to be consumed to some consumer nodes. In addition, it can be understood that the messages to be consumed sent by the first consumer node to different consumer nodes are different. For example, the first consumer node sends message A to be consumed to consumer node A, and the first consumer node sends message B to be consumed to consumer node B, and so on.
[0048] Step 302: respectively receive feedback messages sent by each consumer node in the at least one consumer node in response to the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node, and the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node.
[0049] For example, Figure 4 As shown, after each consumer node completes processing of the message to be consumed, it can send a feedback message for the message to be consumed to the first producer node, and the feedback message carries the pressure-related information of the consumer node. For example, if the first consumer node sends a message A to be consumed to consumer node A, then after consumer node A completes processing of message A to be consumed, it can send a feedback message for message A to be consumed to the first consumer node, and the feedback message carries the pressure-related information of consumer node A; if the first consumer node sends a message B to be consumed to consumer node B, then after consumer node B completes processing of message B to be consumed, it can send a feedback message for message B to be consumed to the first consumer node, and the feedback message carries the pressure-related information of consumer node B, and so on.
[0050] The pressure-related information of the above-mentioned consumer node is used to characterize the load pressure status of the consumer node. That is to say, the load pressure status of the consumer node can be known through the pressure-related information of the consumer node, for example, the load pressure is large or the load pressure is small. Exemplarily, the pressure-related information of the above-mentioned consumer node may include but is not limited to at least one of a pressure index value, a pressure evaluation value, etc. Among them, the above-mentioned pressure index value may include one or more of disk occupancy, CPU occupancy, memory occupancy, downstream call response time, disk write speed, thread pool size, etc. The above-mentioned pressure evaluation value may be calculated based on one or more pressure index values. For example, a pressure evaluation score may be calculated based on CPU occupancy and memory occupancy, and the pressure evaluation score may be fed back to the producer node.
[0051] In some optional embodiments, when the first producer node receives pressure-related information of each consumer node in at least one consumer node, it may store the pressure-related information of each consumer node in at least one consumer node, for example, in a local cache or a shared cache, wherein the above-mentioned shared cache may also be referred to as a distributed cache, which can be read and written by multiple producer nodes.
[0052] Step 303: Perform load balancing according to pressure-related information of some or all of the at least two consumer nodes.
[0053] For the above step 303, exemplarily, the first producer node can directly perform load balancing based on the pressure-related information of each consumer node in the above at least one consumer node received, or the first producer node can read the pressure-related information of each consumer node in the above at least two consumer nodes from a cache (for example, a local cache or a shared cache, etc.), and perform load balancing based on the pressure-related information of each consumer node in the above at least two consumer nodes read. Among them, the above load balancing based on the pressure-related information of the consumer nodes, exemplarily, allocates fewer messages to be consumed to consumer nodes with greater load pressure, and allocates more messages to be consumed to consumer nodes with less load pressure.
[0054] The message processing method provided by the embodiment of the present invention is as follows: the first producer node sends a message to be consumed to at least one of at least two consumer nodes; respectively receives feedback messages sent by each of the at least one consumer node for the message to be consumed, wherein each feedback message carries pressure-related information of the corresponding consumer node; and performs load balancing according to the pressure-related information of some or all of the at least two consumer nodes. Since the first producer node performs load balancing according to the actual pressure conditions of each message consumer node, the effect of load balancing can be improved. In addition, since each consumer node carries the pressure-related information of the message consumer node in the feedback message for the message to be consumed, the network resource overhead of the feedback of the pressure-related information can be reduced. It should also be noted that since the consumer node directly reports the above-mentioned pressure-related information to the producer node, that is, there is no interaction with other devices except the consumer node and the producer node, the delay in reporting the pressure-related information of the consumer node can be reduced, so that the pressure-related information of the consumer node obtained by the producer node can more accurately reflect the current pressure condition of the consumer node, thereby improving the effect of load balancing based on the pressure-related information of the consumer node.
[0055] Optionally, each of the at least two consumer nodes establishes a communication connection with at least two producer nodes, and the first producer node is any producer node of the at least two producer nodes;
[0056] After respectively receiving the feedback message sent by each consumer node of the at least one consumer node for the message to be consumed, the method further includes:
[0057] storing the pressure-related information of each consumer node in the at least one consumer node in a shared cache, wherein the shared cache supports sharing between the at least two producer nodes;
[0058] The performing load balancing according to the pressure-related information of some or all of the at least two consumer nodes includes:
[0059] Obtaining pressure-related information of each of the at least two consumer nodes from the shared cache at intervals of a first preset time;
[0060] Load balancing is performed according to the pressure-related information of each consumer node of the at least two consumer nodes.
[0061] The first preset duration can be reasonably set according to actual conditions, for example, 1 minute, 5 minutes or 10 minutes, etc. In some optional embodiments, the first preset duration can be set according to the service type, for example, for a service with a large amount of messages, the first preset duration can be set to be smaller, and for a service with a small amount of messages, the first preset duration can be set to be larger.
[0062] For example, Figure 5 As shown, each producer node stores the pressure-related information of the consumer node in the shared cache when receiving the pressure-related information of the consumer node returned by the consumer node. In addition, each of the above producer nodes can read the latest pressure-related information of each consumer node from the shared cache every first preset time period, and perform load balancing based on the latest pressure-related information of each consumer node.
[0063] In this embodiment, each producer node can store the pressure-related information received from the consumer node in a shared cache, so that the shared cache can store the latest pressure-related information of each consumer node, and then each producer node can obtain the latest pressure-related information of each consumer node based on the shared cache for load balancing, which can improve the load balancing effect of each consumer node. In addition, in this embodiment, the producer nodes are equivalent to each other, there is no central node or master node, so there is no cluster election action, and there will be no phenomenon of cluster unavailability during the election process. It also avoids the possibility of having a central node or a master node causing a "brain split" and transforming into two different and unrelated clusters, thereby avoiding data inconsistency and improving cluster stability.
[0064] In some optional embodiments, the method further includes:
[0065] When no message to be consumed is sent to the first consumer node within a second preset time period, receiving pressure-related information of the first consumer node sent by the first consumer node, wherein the first consumer node is any consumer node of the at least two consumer nodes.
[0066] In this embodiment, the second preset duration can be reasonably set according to actual conditions, for example, 15 minutes, 30 minutes, 1 hour, etc.
[0067] In this embodiment, the consumer node can actively feedback its pressure-related information to the producer node if it has not received any messages to be consumed for a long time. In this way, the producer node can update the stored pressure-related information of the consumer node based on the pressure-related information actively fed back by the consumer node, so that the producer node can perform load balancing based on the latest pressure-related information of each consumer node to improve the load balancing effect.
[0068] In some optional embodiments, the pressure-related information of the consumer node includes at least one of the following: a pressure index value and a pressure evaluation value of the consumer node;
[0069] The pressure evaluation value is determined according to the pressure index value of the consumer node.
[0070] In some optional embodiments, the pressure indicator value may include but is not limited to at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.
[0071] The above-mentioned pressure evaluation value can be directly used to evaluate the pressure size of the above-mentioned consumer node. For example, the above-mentioned pressure evaluation value can be a pressure score value calculated based on at least one pressure index value, wherein the larger the pressure score value of the consumer node, the greater the load pressure of the consumer node, and the smaller the pressure score value of the consumer node, the smaller the load pressure of the consumer node.
[0072] In one embodiment, each consumer node may report at least one pressure indicator value to the producer node, such as disk occupancy, CPU occupancy, memory occupancy, downstream call response time, etc., so that the producer node can calculate the load balancing weight value or load balancing score corresponding to each consumer node according to the at least one pressure indicator value reported by each consumer node, and then perform load balancing based on the load balancing weight value or load balancing score corresponding to each consumer node. This method is conducive to ensuring the consistency of the calculation method of the load balancing weight value or load balancing score corresponding to each consumer node, thereby improving the accuracy of load balancing.
[0073] In another embodiment, each consumer node can report to the producer node a pressure evaluation value calculated based on at least one pressure indicator value, so that the producer node can directly perform load balancing based on the pressure evaluation value of each consumer node without performing additional calculations. This not only reduces the resource overhead of the consumer node for reporting pressure-related information, but also saves the computing resources of the producer node.
[0074] In some optional embodiments, performing load balancing according to pressure-related information of some or all of the at least two consumer nodes includes:
[0075] Load balancing is performed based on pressure-related information of each consumer node among the at least two consumer nodes and the message response time corresponding to each of the consumer nodes, wherein the message response time is the time from the first producer node sending the message to be consumed to the first producer node receiving a feedback message for the message to be consumed.
[0076] In actual applications, there may be differences in the network status between the producer node and each consumer node. For a consumer node with a better network status, its message response time is often shorter. At this time, the producer node often hopes to send more messages to be consumed to the consumer node; while for a consumer node with a poor network status, its message response time is often longer. At this time, the producer node often hopes to send fewer messages to be consumed to the consumer node, which is beneficial to improving the efficiency of message push.
[0077] This embodiment performs load balancing by integrating the pressure-related information and message response time of each consumer node. For example, the producer node can perform weighted calculation on the pressure assessment value and message response time of the consumer node to obtain a load balancing score, and perform load balancing based on the load balancing score. This ensures the load balancing effect between consumer nodes while taking into account the message push efficiency.
[0078] Figure 6 is a flowchart of a message processing method provided by another embodiment of the present invention, the message processing method is applied to a first consumer node, such as Figure 6 As shown, the following steps are included:
[0079] Step 601: Receive a message to be consumed sent by a first producer node.
[0080] In this embodiment, the first producer node may be any producer node, wherein a communication connection is established between the first producer node and at least two consumer nodes, that is, each of the at least two consumer nodes may receive the message to be consumed sent by the first producer node. The first consumer node may be any consumer node of the at least two consumer nodes.
[0081] Step 602: Consume the message to be consumed.
[0082] The first consumer node can consume the message to be consumed, which can be understood as the first consumer node performing relevant processing on the message to be consumed. For example, if the message to be consumed is an account query request message, the first consumer node can query relevant information of the corresponding account based on the account query request message.
[0083] Step 603: Send a feedback message for the message to be consumed to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node, and the pressure-related information of the first consumer node is used to characterize the load pressure status of the first consumer node.
[0084] The pressure-related information of the above-mentioned consumer node is used to characterize the load pressure status of the consumer node. That is to say, the load pressure status of the consumer node can be known through the pressure-related information of the consumer node, for example, the load pressure is large or the load pressure is small. Exemplarily, the pressure-related information of the above-mentioned consumer node may include but is not limited to at least one of a pressure index value, a pressure evaluation value, etc. Among them, the above-mentioned pressure index value may include one or more of disk occupancy, CPU occupancy, memory occupancy, downstream call response time, disk write speed, thread pool size, etc. The above-mentioned pressure evaluation value may be calculated based on one or more pressure index values. For example, a pressure evaluation score may be calculated based on CPU occupancy and memory occupancy, and the pressure evaluation score may be fed back to the producer node.
[0085] Exemplarily, if the message to be consumed is an account query request message, the feedback message of the message to be consumed may include relevant information of the corresponding account. In addition, the feedback message may also carry pressure-related information of the first consumer node.
[0086] In some optional embodiments, the first consumer node may carry the pressure-related information of the first consumer node in the feedback message of the message to be consumed each time the first consumer node receives the message to be consumed; or, the first consumer node may carry the pressure-related information of the first consumer node in the feedback message of the most recently received message to be consumed only when the pressure-related information changes.
[0087] In actual applications, the first producer node can send messages to be consumed to multiple consumer nodes. For example, Figure 4 As shown, after each consumer node receives the message to be consumed and completes the processing of the message to be consumed, it can send a feedback message for the message to be consumed to the first producer node, and the feedback message carries the pressure-related information of the consumer node. For example, after consumer node A completes the processing of message A to be consumed, it can send a feedback message for message A to be consumed to the first consumer node, and the feedback message carries the pressure-related information of consumer node A; after consumer node B completes the processing of message B to be consumed, it can send a feedback message for message B to be consumed to the first consumer node, and the feedback message carries the pressure-related information of consumer node B, and so on. In this way, the first producer node can perform load balancing based on the pressure-related information of each consumer node, for example, allocate fewer messages to be consumed to consumer nodes with greater load pressure, and allocate more messages to be consumed to consumer nodes with less load pressure.
[0088] In the message processing method provided by the embodiment of the present invention, a first consumer node receives a message to be consumed sent by a first producer node, consumes the message to be consumed, and carries pressure-related information of the first consumer node in a feedback message for the message to be consumed sent to the first producer node. Since the consumer node carries pressure-related information of the consumer node in the feedback message for the message to be consumed, the network resource overhead of pressure-related information feedback can be reduced. In addition, since the consumer node directly reports the above-mentioned pressure-related information to the producer node, that is, there is no interaction with other devices except the consumer node and the producer node, the delay in reporting the pressure-related information of the consumer node can be reduced. This can ensure that the pressure-related information of the consumer node obtained by the producer node can more accurately reflect the current pressure situation of the consumer node, thereby improving the effect of load balancing based on the pressure-related information of the consumer node.
[0089] In some optional embodiments, the method further includes:
[0090] When no to-be-consumed message sent by the first producer node is received within a second preset time period, sending pressure-related information of the first consumer node to the first producer node;
[0091] or
[0092] When no message to be consumed is received from any producer node among the at least two producer nodes within a second preset time period, pressure-related information of the first consumer node is sent to the producer node among the at least two producer nodes, wherein a communication connection is established between the first consumer node and the at least two producer nodes, and the at least two producer nodes include the first producer node.
[0093] In this embodiment, the second preset duration can be reasonably set according to actual conditions, for example, 15 minutes, 30 minutes, 1 hour, etc.
[0094] In one embodiment, if the first consumer node does not receive a message to be consumed sent by a producer node within a second preset time period, the first consumer node can actively report the pressure-related information of the first consumer node to the producer node. This can ensure that each producer node can directly obtain the latest pressure-related information of the first consumer node.
[0095] In another embodiment, the first consumer node may actively report the pressure-related information of the first consumer node to any one or more of the at least two producer nodes if it does not receive any message to be consumed sent by any producer node within a second preset time period, or may actively report the pressure-related information of the first consumer node to a specific one of the at least two producer nodes. For example, the pressure-related information of the first consumer node may be actively reported to a target producer node among the at least two producer nodes, wherein the most recently received message to be consumed by the first consumer node is the message to be consumed sent by the target producer node. In this way, when the first consumer node interacts with at least two producer nodes, the network resource overhead of the first consumer node for reporting pressure-related messages can be saved.
[0096] In some optional embodiments, the pressure-related information of the consumer node includes at least one of the following: a pressure index value and a pressure evaluation value of the consumer node;
[0097] The pressure evaluation value is determined according to the pressure index value of the consumer node.
[0098] In some optional embodiments, the pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.
[0099] The above-mentioned pressure evaluation value can be directly used to evaluate the pressure size of the above-mentioned consumer node. For example, the above-mentioned pressure evaluation value can be a pressure score value calculated based on at least one pressure index value, wherein the larger the pressure score value of the consumer node, the greater the load pressure of the consumer node, and the smaller the pressure score value of the consumer node, the smaller the load pressure of the consumer node.
[0100] In one embodiment, each consumer node may report at least one pressure indicator value to the producer node, such as disk occupancy, CPU occupancy, memory occupancy, downstream call response time, etc., so that the producer node can calculate the load balancing weight value or load balancing score corresponding to each consumer node according to the at least one pressure indicator value reported by each consumer node, and then perform load balancing based on the load balancing weight value or load balancing score corresponding to each consumer node. This method is conducive to ensuring the consistency of the calculation method of the load balancing weight value or load balancing score corresponding to each consumer node, thereby improving the accuracy of load balancing.
[0101] In another embodiment, each consumer node can report to the producer node a pressure evaluation value calculated based on at least one pressure indicator value, so that the producer node can directly perform load balancing based on the pressure evaluation value of each consumer node without performing additional calculations. This not only reduces the resource overhead of the consumer node for reporting pressure-related information, but also saves the computing resources of the producer node.
[0102] In some optional embodiments, the stress evaluation value is calculated based on at least two stress index values of the consumer node and a target weight group, wherein the target weight group includes the weight of each of the at least two stress index values.
[0103] In this embodiment, the target weight group may be a preset weight group or a weight group selected from a plurality of weight groups.
[0104] Exemplarily, the at least two stress indicator values include CPU occupancy and memory occupancy, and the target weight group includes a first weight and a second weight, wherein the first weight is the weight of the CPU occupancy and the second weight is the weight of the memory occupancy. The first consumer node can multiply the CPU occupancy by the first weight to obtain a first value, multiply the memory occupancy by the second weight to obtain a second value, and add the first value to the second value to obtain the above-mentioned pressure assessment value.
[0105] In some optional embodiments, the target weight group is a weight group corresponding to a target calculation cycle, the target calculation cycle is a calculation cycle with the smallest corresponding variance value among N calculation cycles, N is an integer greater than 1, the N calculation cycles correspond to N different weight groups respectively, and each of the weight groups includes the weight of each of the at least two pressure index values;
[0106] The variance value corresponding to the i-th calculation cycle in the N calculation cycles is determined in the following manner:
[0107] In the i-th calculation cycle, an i-th pressure evaluation value is calculated according to at least two pressure indicator values of the consumer node and the i-th weight group; the value range of i is [1, N];
[0108] Sending the i-th pressure evaluation value to the first producer node, so that the first producer node performs load balancing according to the i-th pressure evaluation value;
[0109] Counting the number of request responses corresponding to each time unit in M time units within the i-th calculation cycle, where M is an integer greater than 1;
[0110] Respectively calculating the ratio of the number of request responses corresponding to each time unit in the M time units to the i-th pressure assessment value to obtain M ratios;
[0111] Calculate the variance values of the M ratios to obtain the variance value corresponding to the i-th calculation cycle.
[0112] In this embodiment, the length of the above-mentioned calculation cycle can be reasonably set according to actual conditions, for example, 1 minute or 5 minutes. The above-mentioned time unit can be reasonably set according to actual conditions, for example, 1 second, 10 seconds, 30 seconds or 1 minute. It should be noted that a calculation cycle includes M or more time units. The above-mentioned N calculation cycles can be historical N calculation cycles. The number of request responses corresponding to the above-mentioned time unit may include the number of messages to be consumed processed within the time unit, or the number of messages to be consumed received within the time unit, etc.
[0113] The weight group corresponding to each calculation cycle in the above-mentioned N calculation cycles can be pre-set; it can also be determined according to a pre-set weight value range. For example, the weight value range corresponding to each pressure index value is set in advance, and for each calculation cycle, the weight corresponding to each pressure index value is obtained from the weight value range corresponding to each pressure index value in turn according to the preset step size to obtain the weight group corresponding to the calculation cycle.
[0114] Specifically, each consumer node calculates the pressure assessment value corresponding to the calculation cycle based on the corresponding weight group in each calculation cycle and reports it to the first producer node. The first producer node can perform load balancing based on the pressure assessment value reported by each consumer node. In this way, each consumer node can count the ratio of the number of request responses corresponding to each time unit in each calculation cycle and the pressure assessment value corresponding to the calculation cycle, and can calculate the variance value of the ratio corresponding to M time units as the variance value corresponding to the calculation cycle. After obtaining the variance value corresponding to each calculation cycle in N calculation cycles, the weight group corresponding to the calculation cycle with the smallest variance value can be used as the target weight group.
[0115] In this embodiment, the first consumer node calculates the pressure evaluation value based on the corresponding weight group in each calculation cycle and sends it to the first producer node, so that the first producer node performs load balancing based on the reported pressure evaluation value. In this way, the first consumer node can count the number of request responses corresponding to multiple time units in the corresponding calculation cycle after load balancing based on each pressure evaluation value, so as to calculate the variance value corresponding to each calculation cycle, and select the weight group corresponding to the calculation cycle with the smallest variance value as the target weight group. Since the number of request responses corresponding to multiple time units in the corresponding calculation cycle after load balancing based on each pressure evaluation value can more accurately reflect the effect of load balancing based on the pressure evaluation value calculated based on each weight group, selecting the target weight group based on the variance value calculated based on the number of request responses corresponding to multiple time units in each calculation cycle can ensure that the selected target weight group is more reasonable, thereby improving the effect of load balancing based on the pressure evaluation value calculated based on the target weight group.
[0116] In some optional embodiments, the first consumer node may also provide a reconstruction function. For example, it may provide an interface for changing the pressure assessment value calculation. The pressure assessment value calculation method may be changed through the interface. For example, the pressure index values and weights involved in the pressure assessment value calculation may be changed. This allows the consumer node to calculate the pressure assessment value based on its own characteristics and provide a pressure assessment value calculation that meets its own needs.
[0117] In summary, the message processing method provided by this embodiment can make the overall resource pressure of consumer nodes relatively balanced, can more finely manage and use computing resources, can enhance cluster robustness, and avoid cluster "avalanche" caused by single node failure; no central coordination node is required; it can be achieved in more frequent network business interactions without the need for additional network overhead for load balancing data, and can also achieve the frequency of active reporting when there are fewer businesses or when a node is temporarily under greater pressure and less data is requested. Compared with traditional load balancing, it can reduce the cost of load balancing equipment, reduce the cost of load balancing information transmission, and improve the effect of daily load balancing.
[0118] See also Figure 7 , Figure 7 is a structural diagram of a message processing device provided in an embodiment of the present invention, wherein the message processing device is applied to a first producer node, wherein a communication connection is established between the first producer node and at least two consumer nodes, such as Figure 7 As shown, the message processing device 700 includes:
[0119] A first sending module 701, configured to send a message to be consumed to at least one consumer node among the at least two consumer nodes;
[0120] A first receiving module 702 is configured to respectively receive a feedback message sent by each consumer node of the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node, and the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node;
[0121] The load balancing module 703 is used to perform load balancing according to pressure-related information of some or all of the at least two consumer nodes.
[0122] Optionally, each of the at least two consumer nodes establishes a communication connection with at least two producer nodes, and the first producer node is any producer node of the at least two producer nodes;
[0123] The device also includes:
[0124] A storage module, configured to store the pressure-related information of each consumer node in the at least one consumer node in a shared cache after receiving the feedback message sent by each consumer node in the at least one consumer node for the message to be consumed, wherein the shared cache supports sharing between the at least two producer nodes;
[0125] The load balancing module is specifically used for:
[0126] Obtaining pressure-related information of each of the at least two consumer nodes from the shared cache at intervals of a first preset time;
[0127] Load balancing is performed according to the pressure-related information of each consumer node of the at least two consumer nodes.
[0128] Optionally, the device further comprises:
[0129] The second receiving module is used to receive pressure-related information of the first consumer node sent by the first consumer node when no message to be consumed is sent to the first consumer node within a second preset time period, wherein the first consumer node is any consumer node of the at least two consumer nodes.
[0130] Optionally, the pressure-related information of the consumer node includes at least one of the following: a pressure index value and a pressure evaluation value of the consumer node;
[0131] The pressure evaluation value is determined according to the pressure index value of the consumer node.
[0132] Optionally, the pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.
[0133] Optionally, the load balancing module is specifically used to:
[0134] Load balancing is performed based on pressure-related information of each consumer node among the at least two consumer nodes and the message response time corresponding to each of the consumer nodes, wherein the message response time is the time from the first producer node sending the message to be consumed to the first producer node receiving a feedback message for the message to be consumed.
[0135] The message processing device 700 provided in the embodiment of the present invention can implement each process in the above-mentioned first producer node side method embodiment, and will not be described again here to avoid repetition.
[0136] See also Figure 8 , Figure 8 is a structural diagram of a message processing device provided by an embodiment of the present invention, and the message processing device is applied to a first consumer node. Figure 8 As shown, the message processing device 800 includes:
[0137] The first receiving module 801 is used to receive a message to be consumed sent by a first producer node;
[0138] A message consumption module 802, used for consuming the message to be consumed;
[0139] The first sending module 803 is used to send a feedback message for the message to be consumed to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node, and the pressure-related information of the first consumer node is used to characterize the load pressure status of the first consumer node.
[0140] Optionally, the device further includes a second sending module, wherein the second sending module is specifically configured to:
[0141] When no to-be-consumed message sent by the first producer node is received within a second preset time period, sending pressure-related information of the first consumer node to the first producer node;
[0142] or
[0143] When no message to be consumed is received from any producer node among the at least two producer nodes within a second preset time period, pressure-related information of the first consumer node is sent to the producer node among the at least two producer nodes, wherein a communication connection is established between the first consumer node and the at least two producer nodes, and the at least two producer nodes include the first producer node.
[0144] Optionally, the pressure-related information of the consumer node includes at least one of the following: a pressure index value and a pressure evaluation value of the consumer node;
[0145] The pressure evaluation value is determined according to the pressure index value of the consumer node.
[0146] Optionally, the pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.
[0147] Optionally, the stress evaluation value is calculated based on at least two stress index values of the consumer node and a target weight group, wherein the target weight group includes the weight of each of the at least two stress index values.
[0148] Optionally, the target weight group is a weight group corresponding to a target calculation cycle, the target calculation cycle is a calculation cycle with the smallest corresponding variance value among N calculation cycles, N is an integer greater than 1, the N calculation cycles correspond to N different weight groups respectively, and each of the weight groups includes the weight of each of the at least two pressure index values;
[0149] The variance value corresponding to the i-th calculation cycle in the N calculation cycles is determined in the following manner:
[0150] In the i-th calculation cycle, an i-th pressure evaluation value is calculated according to at least two pressure indicator values of the consumer node and the i-th weight group; the value range of i is [1, N];
[0151] Sending the i-th pressure evaluation value to the first producer node, so that the first producer node performs load balancing according to the i-th pressure evaluation value;
[0152] Counting the number of request responses corresponding to each time unit in M time units within the i-th calculation cycle, where M is an integer greater than 1;
[0153] Respectively calculating the ratio of the number of request responses corresponding to each time unit in the M time units to the i-th pressure assessment value to obtain M ratios;
[0154] Calculate the variance values of the M ratios to obtain the variance value corresponding to the i-th calculation cycle.
[0155] The message processing device 800 provided in the embodiment of the present invention can implement each process in the above-mentioned first consumer node side method embodiment, and will not be described again here to avoid repetition.
[0156] See also Fig. 9 , Fig. 9 is a structural diagram of a message processing device provided by another embodiment of the present invention, such as Fig. 9 As shown, the message processing device 900 includes: a processor 901, a memory 902, and a computer program stored in the memory 902 and executable on the processor. The components in the message processing device 900 are coupled together via a bus interface 903. When the computer program is executed by the processor 901, the following steps are implemented:
[0157] Sending a message to be consumed to at least one consumer node of the at least two consumer nodes;
[0158] Respectively receiving a feedback message sent by each consumer node of the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node, and the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node;
[0159] Perform load balancing according to pressure related information of some or all of the at least two consumer nodes;
[0160] or
[0161] Receive the message to be consumed sent by the first producer node;
[0162] Perform message consumption on the message to be consumed;
[0163] A feedback message for the message to be consumed is sent to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node, and the pressure-related information of the first consumer node is used to characterize the load pressure status of the first consumer node.
[0164] It should be understood that in the embodiment of the present invention, when the computer program is executed by the processor 901, it can implement each process in the above-mentioned message processing method embodiment, and to avoid repetition, it will not be described here.
[0165] An embodiment of the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned message processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0166] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above-mentioned message processing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0167] It should be noted that, in this article, the terms "include", "comprises" or any other variations 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, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0168] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0169] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A message processing method, It is characterized in that Applied to a first producer node, a communication connection is established between the first producer node and at least two consumer nodes, each of the at least two consumer nodes is connected to at least two producer nodes, and the first producer node is any producer node of the at least two producer nodes. The method includes: Sending a message to be consumed to at least one consumer node of the at least two consumer nodes; Respectively receiving a feedback message sent by each consumer node of the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node, and the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node; Perform load balancing according to pressure related information of some or all of the at least two consumer nodes; After respectively receiving the feedback message sent by each consumer node of the at least one consumer node for the message to be consumed, the method further includes: The pressure-related information of each consumer node in the at least one consumer node is stored in a shared cache, wherein the shared cache supports sharing between the at least two producer nodes.
2. The method according to claim 1, It is characterized in that The performing load balancing according to the pressure-related information of some or all of the at least two consumer nodes includes: Obtaining pressure-related information of each of the at least two consumer nodes from the shared cache at intervals of a first preset time; Load balancing is performed according to the pressure-related information of each consumer node of the at least two consumer nodes.
3. The method according to claim 1, It is characterized in that The method further comprises: When no message to be consumed is sent to the first consumer node within a second preset time period, receiving pressure-related information of the first consumer node sent by the first consumer node, wherein the first consumer node is any consumer node of the at least two consumer nodes.
4. The method according to claim 1, It is characterized in that The pressure related information of the consumer node includes at least one of the following: a pressure index value and a pressure evaluation value of the consumer node; The pressure evaluation value is determined according to the pressure index value of the consumer node.
5. The method according to claim 4, It is characterized in that The pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.
6. The method according to claim 1, It is characterized in that The performing load balancing according to the pressure-related information of some or all of the at least two consumer nodes includes: Load balancing is performed based on pressure-related information of each consumer node among the at least two consumer nodes and the message response time corresponding to each of the consumer nodes, wherein the message response time is the time from the first producer node sending the message to be consumed to the first producer node receiving a feedback message for the message to be consumed.
7. A message processing method, It is characterized in that Applied to a first consumer node, a communication connection is established between the first consumer node and at least two producer nodes, and the first producer node is any producer node of the at least two producer nodes, and the method includes: Receive the message to be consumed sent by the first producer node; Perform message consumption on the message to be consumed; Sending a feedback message for the message to be consumed to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node, and the pressure-related information of the first consumer node is used to characterize the load pressure status of the first consumer node; The method further comprises: When no to-be-consumed message sent by any producer node among the at least two producer nodes is received within a second preset time period, pressure-related information of the first consumer node is sent to the producer node among the at least two producer nodes.
8. The method according to claim 7, It is characterized in that The method further comprises: When no to-be-consumed message sent by the first producer node is received within a second preset time period, pressure-related information of the first consumer node is sent to the first producer node.
9. The method according to claim 7, It is characterized in that The pressure related information of the consumer node includes at least one of the following: a pressure index value and a pressure evaluation value of the consumer node; The pressure evaluation value is determined according to the pressure index value of the consumer node.
10. The method according to claim 9, It is characterized in that The pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.
11. The method according to claim 9, It is characterized in that The pressure evaluation value is calculated based on at least two pressure index values of the consumer node and a target weight group, wherein the target weight group includes the weight of each pressure index value of the at least two pressure index values.
12. The method according to claim 11, It is characterized in that The target weight group is a weight group corresponding to a target calculation cycle, the target calculation cycle is a calculation cycle with the smallest corresponding variance value among N calculation cycles, N is an integer greater than 1, the N calculation cycles correspond to N different weight groups respectively, and each of the weight groups includes the weight of each of the at least two pressure index values; The variance value corresponding to the i-th calculation cycle in the N calculation cycles is determined in the following manner: In the i-th calculation cycle, an i-th pressure evaluation value is calculated according to at least two pressure indicator values of the consumer node and the i-th weight group; the value range of i is [1, N]; Sending the i-th pressure evaluation value to the first producer node, so that the first producer node performs load balancing according to the i-th pressure evaluation value; Counting the number of request responses corresponding to each time unit in M time units within the i-th calculation cycle, where M is an integer greater than 1; Calculate the ratio of the number of request responses corresponding to each time unit in the M time units to the i-th pressure assessment value to obtain M ratios; Calculate the variance values of the M ratios to obtain the variance value corresponding to the i-th calculation cycle.
13. A message processing device, It is characterized in that Applied to a first producer node, a communication connection is established between the first producer node and at least two consumer nodes, each of the at least two consumer nodes is connected to at least two producer nodes, the first producer node is any producer node of the at least two producer nodes, and the device includes: A first sending module, configured to send a message to be consumed to at least one consumer node among the at least two consumer nodes; A first receiving module, configured to respectively receive a feedback message sent by each consumer node of the at least one consumer node in response to the message to be consumed, wherein each of the feedback messages carries pressure-related information of the corresponding consumer node; A load balancing module, configured to perform load balancing according to pressure-related information of some or all of the at least two consumer nodes; A storage module is used to store the pressure-related information of each consumer node in the at least one consumer node in a shared cache after receiving the feedback message sent by each consumer node in the at least one consumer node in response to the message to be consumed, wherein the shared cache supports sharing between the at least two producer nodes.
14. A message processing device, It is characterized in that Applied to a first consumer node, a communication connection is established between the first consumer node and at least two producer nodes, the first producer node is any producer node of the at least two producer nodes, and the device includes: A first receiving module, used to receive a message to be consumed sent by a first producer node; A message consumption module, used for consuming the message to be consumed; A first sending module, configured to send a feedback message for the message to be consumed to the first producer node, wherein the feedback message carries pressure-related information of the first consumer node; The second sending module is used to send the pressure-related information of the first consumer node to the producer node among the at least two producer nodes when no to-be-consumed message sent by any producer node among the at least two producer nodes is received within a second preset time length.
15. An electronic device, It is characterized in that The method comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the message processing method as claimed in any one of claims 1 to 6, or implements the steps of the message processing method as claimed in any one of claims 7 to 12.
16. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the message processing method according to any one of claims 1 to 6 are implemented, or the steps of the message processing method according to any one of claims 7 to 12 are implemented.
