CN116132367A - A message processing method, device and electronic equipment - Google Patents

A message processing method, device and electronic equipment Download PDF

Info

Publication number
CN116132367A
CN116132367A CN202210986802.9A CN202210986802A CN116132367A CN 116132367 A CN116132367 A CN 116132367A CN 202210986802 A CN202210986802 A CN 202210986802A CN 116132367 A CN116132367 A CN 116132367A
Authority
CN
China
Prior art keywords
node
consumer
pressure
message
producer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210986802.9A
Other languages
Chinese (zh)
Other versions
CN116132367B (en
Inventor
王镇航
吴鹏
蒋宁
吴海英
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Mashang Consumer Finance Co Ltd
Original Assignee
Mashang Consumer Finance Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Mashang Consumer Finance Co Ltd filed Critical Mashang Consumer Finance Co Ltd
Priority to CN202210986802.9A priority Critical patent/CN116132367B/en
Publication of CN116132367A publication Critical patent/CN116132367A/en
Application granted granted Critical
Publication of CN116132367B publication Critical patent/CN116132367B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/12Avoiding congestion; Recovering from congestion
    • H04L47/125Avoiding congestion; Recovering from congestion by balancing the load, e.g. traffic engineering
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides a message processing method, a message processing device and electronic equipment, wherein the method comprises the following steps: sending a message to be consumed to at least one consumer node of the at least two consumer nodes; receiving feedback messages sent by each consumer node of the at least one consumer node for the message to be consumed respectively, wherein each feedback message carries pressure related information of the corresponding consumer node, and the pressure related information of the consumer node is used for representing the load pressure condition of the consumer node; and carrying out load balancing according to the pressure related information of part or all of the at least two consumer nodes. The message processing method provided by the invention can improve the effect of load balancing and reduce the network resource overhead of pressure related information feedback.

Description

一种消息处理方法、装置及电子设备A message processing method, device and electronic equipment

技术领域technical field

本发明涉及数据处理技术领域,尤其涉及一种消息处理方法、装置及电子设备。The present invention relates to the technical field of data processing, in particular to a message processing method, device and electronic equipment.

背景技术Background technique

随着互联网业务领域的扩展,在各个业务领域承载的业务量越来越大,传统的点对点的信息交互模式早已不能承载业务需求,在此前提下,引入了横向扩展的集群模式,例如,消息消费者集群,消息生产者集群,以及消息中间件集群等。With the expansion of the Internet business field, the amount of business carried in various business fields is increasing. The traditional point-to-point information interaction mode has long been unable to carry business needs. On this premise, a horizontally expanded cluster mode is introduced. Consumer clusters, message producer clusters, and message middleware clusters, etc.

实际应用中,集群与集群的交互,无论是通过传输控制协议(TCP,TransmissionControl Protocol)/超文本传输协议(Hyper Text Transfer Protocol,HTTP)进行消费者节点与生产者节点直接交互,还是在引入消息中间件以后,生产者节点经由消息中间件与消费者节点的交互,都面临让消费者集群各个消费者节点中的实例能够以一定的速度消费消息,而又不产生堆积的问题,即在消费者节点之间进行负载均衡。目前,通常是基于分片算法让各个消费者节点消费的消息量均等,这种负载均衡方式未能考虑消费者节点的实际情况,导致负载均衡的效果较差。In practical applications, the interaction between clusters, whether it is direct interaction between consumer nodes and producer nodes through Transmission Control Protocol (TCP, Transmission Control Protocol)/Hyper Text Transfer Protocol (Hyper Text Transfer Protocol, HTTP), or introducing message After the middleware, the interaction between the producer node and the consumer node through the message middleware is faced with the problem of enabling the instances in each consumer node of the consumer cluster to consume messages at a certain speed without causing accumulation. load balancing between nodes. At present, the amount of messages consumed by each consumer node is usually based on the sharding algorithm. This load balancing method fails to consider the actual situation of the consumer nodes, resulting in a poor load balancing effect.

发明内容Contents of the invention

本发明实施例提供一种消息处理方法、装置及电子设备,以解决现有技术中负载均衡的效果较差的问题。Embodiments of the present invention provide a message processing method, device and electronic equipment to solve the problem of poor load balancing effect in the prior art.

为了解决上述技术问题,本发明是这样实现的:In order to solve the problems of the technologies described above, the present invention is achieved in that:

第一方面,本发明实施例提供了一种消息处理方法,应用于第一生产者节点,所述第一生产者节点与至少两个消费者节点之间建立有通信连接,所述方法包括:In the first aspect, an embodiment of the present invention provides a message processing method, which is applied to a first producer node, and communication connections are established between the first producer node and at least two consumer nodes, and the method includes:

向所述至少两个消费者节点中的至少一个消费者节点发送待消费消息;sending a message to be consumed to at least one of the at least two consumer nodes;

分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息,所述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况;Respectively receive a feedback message sent by each consumer node in 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 consumer The pressure related information of the node is used to characterize the load pressure condition of the consumer node;

根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡。Load balancing is performed according to the pressure-related information of some or all of the consumer nodes in the at least two consumer nodes.

第二方面,本发明实施例还提供了一种消息处理方法,应用于第一消费者节点,所述方法包括:In the second aspect, the embodiment of the present invention also provides a message processing method, which is applied to the first consumer node, 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 It is used to characterize the load pressure condition of the first consumer node.

第三方面,本发明实施例还提供一种消息处理装置,应用于第一生产者节点,所述第一生产者节点与至少两个消费者节点之间建立有通信连接,所述装置包括:In the third aspect, the embodiment of the present invention also provides a message processing device, which is applied to a first producer node, and communication connections are established between the first producer node and at least two consumer 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 in the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries the pressure of the corresponding consumer node Related information, the pressure related information of the consumer node is used to characterize the load pressure condition of the consumer node;

负载均衡模块,用于根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡。A load balancing module, configured to perform load balancing according to pressure-related information of some or all of the consumer nodes among the at least two consumer nodes.

第四方面,本发明实施例还提供一种消息处理装置,应用于第一消费者节点,所述装置包括:In the fourth aspect, the embodiment of the present invention also provides a message processing device, which is applied to the first consumer node, and the device includes:

第一接收模块,用于接收第一生产者节点发送的待消费消息;The first receiving module is configured to receive the message to be consumed sent by the first producer node;

消息消费模块,用于对所述待消费消息进行消息消费;A message consumption module, configured to consume 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, and the first The pressure related information of the consumer node is used to characterize the load pressure condition of the first consumer node.

第五方面,本发明实施例还提供一种电子设备,包括处理器、存储器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述计算机程序被所述处理器执行时实现上述第一方面提供的消息处理方法的步骤,或者实现上述第二方面提供的消息处理方法的步骤。In the fifth aspect, 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 operable on the processor, and the computer program is executed by the processor When implementing the steps of the message processing method provided by the above first aspect, or implementing the steps of the message processing method provided by the above second aspect.

第六方面,本发明实施例还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现上述第一方面提供的消息处理方法的步骤,或者实现上述第二方面提供的消息处理方法的步骤。In a sixth aspect, an 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, the message processing method provided in the above-mentioned first aspect is implemented. or implement the steps of the message processing method provided in the second aspect above.

本发明实施例中,第一生产者节点通过向至少两个消费者节点中的至少一个消费者节点发送待消费消息;分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息;根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡,由于第一生产者节点根据各个消息消费者节点的实际压力情况进行负载均衡,可以提高负载均衡的效果,此外,由于各个消费者节点在针对待消费消息的反馈消息中携带该消息消费者节点的压力相关信息,这样可以减少压力相关信息反馈的网络资源开销。In the embodiment of the present invention, the first producer node sends a message to be consumed to at least one consumer node among at least two consumer nodes; respectively receives each consumer node in the at least one consumer node for the Feedback messages to be sent by messages to be consumed, wherein each of the feedback messages carries pressure-related information of a corresponding consumer node; load is performed according to the pressure-related information of some or all of the at least two consumer nodes Balanced, since the first producer node performs load balancing according to the actual pressure of each message consumer node, the effect of load balancing can be improved. In addition, since each consumer node carries the message consumer in the feedback message for the message to be consumed Pressure-related information of nodes, which can reduce network resource overhead for pressure-related information feedback.

附图说明Description of drawings

为了更清楚地说明本发明实施例的技术方案,下面将对本发明实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the accompanying drawings that need to be used in the description of the embodiments of the present invention. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those skilled in the art, other drawings can also be obtained based on these drawings without any creative effort.

图1是本发明实施例提供的一种点对点交互的示意图;FIG. 1 is a schematic diagram of a point-to-point interaction provided by an embodiment of the present invention;

图2是本发明实施例提供的一种集群间交互的示意图之一;FIG. 2 is one of the schematic diagrams of inter-cluster interaction provided by an embodiment of the present invention;

图3是本发明实施例提供的消息处理方法的流程图;FIG. 3 is a flowchart of a message processing method provided by an embodiment of the present invention;

图4是本发明实施例提供的一种集群间交互的示意图之二;FIG. 4 is a second schematic diagram of inter-cluster interaction provided by an embodiment of the present invention;

图5是本发明实施例提供的一种集群间交互的示意图之三;FIG. 5 is a third schematic diagram of inter-cluster interaction provided by an embodiment of the present invention;

图6是本发明又一实施例提供的消息处理方法的流程图;Fig. 6 is a flow chart of a message processing method provided by another embodiment of the present invention;

图7是本发明实施例提供的消息处理装置的结构图;FIG. 7 is a structural diagram of a message processing device provided by an embodiment of the present invention;

图8是本发明又一实施例提供的消息处理装置的结构图;Fig. 8 is a structural diagram of a message processing device provided by another embodiment of the present invention;

图9是本发明实施例提供的电子设备的结构图。FIG. 9 is a structural diagram of an electronic device provided by an embodiment of the present invention.

具体实施方式Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some of the embodiments of the present invention, but not all of them. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.

为了便于理解,以下对本发明实施例涉及的一些内容进行说明:For ease of understanding, the following describes some of the content involved in the embodiments of the present invention:

负载均衡(Load Balance):可以理解为分摊到多个操作单元上进行执行,例如,Web服务器、文件传输协议(File Transfer Protocol,FTP)服务器、企业关键应用服务器和其它关键任务服务器等,从而共同完成工作任。Load Balance: It can be understood as being distributed to multiple operating units for execution, such as Web servers, File Transfer Protocol (File Transfer Protocol, FTP) servers, key enterprise application servers, and other mission-critical servers, so as to jointly Complete tasks.

生产者(Producer)节点,也可称为消息生产者节点,属于业务的发起方,负责生产消息提供给消费者节点。Producer nodes, also known as message producer nodes, belong to the initiator of the business and are responsible for producing messages and providing them to consumer nodes.

消费者(Consumer)节点:也可以称为消息消费者节点,属于业务的处理方,负责从生产者节点获取消息并进行业务逻辑处理,其中,消费者节点可以通过同步接口直接从生产者节点获取消息,也可以通过消息中间件从生产者节点获取消息。Consumer (Consumer) node: It can also be called a message consumer node, which belongs to the business processor and is responsible for obtaining messages from the producer node and performing business logic processing. Among them, the consumer node can directly obtain from the producer node through the synchronous interface Messages can also be obtained from producer nodes through message middleware.

消息中间件:也可以称消息队列,是指用高效可靠的消息传递机制进行与平台无关的数据交流,并基于数据通信来进行分布式系统的集成。通过提供消息传递和消息队列模型,可以在分布式环境下扩展进程的通信。Message middleware: It can also be called message queue, which refers to the platform-independent data exchange with efficient and reliable message delivery mechanism, and the integration of distributed systems based on data communication. By providing a message passing and message queue model, the communication of processes can be extended in a distributed environment.

输入输出(Input Output,IO)密集型:指的是系统的CPU性能相对硬盘、内存要好很多,此时,系统运作,大部分的状况是CPU在等I/O(硬盘/内存)的读/写操作,此时CPU负载(Loading)并不高,绝大部分情况下,对于分布式系统,上述IO通常是指网络IO的开销。Input/Output (IO)-intensive: refers to the CPU performance of the system is much better than that of the hard disk and memory. At this time, the system is running, and most of the situation is that the CPU is waiting for the I/O (hard disk/memory) read/write For write operations, the CPU load (Loading) is not high at this time. In most cases, for distributed systems, the above-mentioned IO usually refers to the overhead of network IO.

点对点交互:也可称为单节点交互,也即一个生产者节点仅与一个消费者节点交互,示例性的,如图1所示,生产者节点向消费者节点发送消息,消费者节点对该消息处理后返回反馈消息。可以理解的是,在单节点交互模式下,不存在负载均衡问题。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, as shown in Figure 1, the producer node sends a message to the consumer node, and the consumer node responds to the Return a feedback message after the message is processed. It can be understood that in the single-node interactive mode, there is no load balancing problem.

集群间交互:也即多个生产者节点和多个消费者节点之间的交互,示例性的,如图2所示,生成者集群中的每个生产者节点可以与消费者集群中的多个消费者交互,生产者节点向消费者节点发送消息,消费者节点对该消息处理后返回反馈消息。Inter-cluster interaction: that is, the interaction between multiple producer nodes and multiple consumer nodes. Exemplarily, as shown in Figure 2, each producer node in the producer cluster can communicate with multiple consumer nodes in the consumer cluster Consumer interaction, the producer node sends a message to the consumer node, and the consumer node returns a feedback message after processing the message.

本发明实施例提供一种消息处理方法,应用于第一生产者节点,所述第一生产者节点与至少两个消费者节点之间建立有通信连接。参见图3,图3是本发明实施例提供的消息处理方法的流程图,如图3所示,包括以下步骤:An embodiment of the present invention provides a message processing method, which is applied to a first producer node, and communication connections are established between the first producer node and at least two consumer nodes. Referring to FIG. 3, FIG. 3 is a flowchart of a message processing method provided by an embodiment of the present invention. As shown in FIG. 3, it includes the following steps:

步骤301、向至少两个消费者节点中的至少一个消费者节点发送待消费消息。Step 301, sending a message to be consumed to at least one consumer node among at least two consumer nodes.

本实施例中,第一生产者节点与至少两个消费者节点之间建立有通信连接,也就是说,上述至少两个消费者节点中的每个消费者节点均可以接收上述第一生产者节点发送的待消费消息,示例性的,如图4所示,每个生产者节点可以向多个消费者节点投递待消费消息。其中,上述第一生产者节点可以是任意的生产者节点。In this embodiment, a communication connection is established between the first producer node and at least two consumer nodes, that is to say, each of the above-mentioned at least two consumer nodes can receive the above-mentioned first producer node For the message to be consumed sent by the node, for example, as shown in FIG. 4 , each producer node may deliver the message to be consumed to multiple consumer nodes. Wherein, the above-mentioned first producer node may be any producer node.

上述至少一个消费者节点可以包括上述至少两个消费者节点中的部分或者全部消费者节点。实际应用中,第一消费者节点在一次消息投递中可能向全部的消费者节点均发送待消费消息,也可能仅向部分消费者节点发送待消费消息。此外,可以理解的是,第一消费者节点向不同的消费者节点发送的待消费消息不同,示例性的,第一消费者节点向消费者节点A发送待消费消息A,第一消费者节点向消费者节点B发送待消费消息B,以此类推。The at least one consumer node may include some or all of the at least two consumer nodes. In practical 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 message to be consumed sent by the first consumer node to different consumer nodes is different. For example, the first consumer node sends the message A to be consumed to consumer node A, and the first consumer node Send message B to be consumed to consumer node B, and so on.

步骤302、分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息,所述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况。Step 302, respectively receiving feedback messages sent by each 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, so The pressure related information of the consumer node is used to characterize the load pressure condition of the consumer node.

示例性的,如图4所示,各个消费者节点完成待消费消息处理后,可以向第一生产者节点发送针对该待消费消息的反馈消息,该反馈消息中携带有该消费者节点的压力相关信息。例如,若第一消费者节点向消费者节点A发送待消费消息A,则消费者节点A完成待消费消息A的处理后,可以向第一消费者节点发送针对待消费消息A的反馈消息,该反馈消息携带有消费者节点A的压力相关信息;若第一消费者节点向消费者节点B发送待消费消息B,则消费者节点B完成待消费消息B的处理后,可以向第一消费者节点发送针对待消费消息B的反馈消息,该反馈消息携带有消费者节点B的压力相关信息,以此类推。Exemplarily, as shown in FIG. 4, after each consumer node finishes processing 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 of the consumer node. Related Information. For example, if the first consumer node sends a message A to be consumed to the consumer node A, after the consumer node A completes the processing of the message A to be consumed, it can send a feedback message for the message A to be consumed to the first consumer node, The feedback message carries the pressure-related information of consumer node A; if the first consumer node sends message B to be consumed to consumer node B, after consumer node B completes the processing of message B to be consumed, it can report to the first consumer node The sender node sends a feedback message for the message B to be consumed, the feedback message carries the pressure-related information of the consumer node B, and so on.

上述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况,也就是说通过消费者节点的压力相关信息可以获知该消费者节点的负载压力情况,例如,负载压力较大或负载压力较小等。示例性的,上述消费者节点的压力相关信息可以包括但不限于压力指标值、压力评估值等中的至少一项。其中,上述压力指标值可以包括磁盘占用率、CPU占用率、内存占用率、下游调用响应时间、磁盘写入速度、线程池大小等中的一种或多种。上述压力评估值可以是基于一种或多种压力指标值计算得到,例如,可以基于CPU占用率和内存占用率计算得到一个压力评估分值,并将该压力评估分值反馈给生产者节点。The above-mentioned pressure-related information of the consumer node is used to characterize the load pressure condition of the consumer node, that is to say, the load pressure condition of the consumer node can be known through the pressure-related information of the consumer node, for example, the load pressure is high or Load pressure is small, etc. Exemplarily, the above-mentioned stress-related information of the consumer node may include but not limited to at least one of a stress index value, a stress evaluation value, and the like. Wherein, the above-mentioned pressure index value may include one or more of disk usage rate, CPU usage rate, memory usage rate, downstream call response time, disk writing speed, thread pool size, and the like. The above pressure assessment value may be calculated based on one or more pressure index values, for example, a pressure assessment score may be calculated based on CPU occupancy rate and memory occupancy rate, and the pressure assessment score value may be fed back to the producer node.

在一些可选的实施例中,第一生产者节点在接收到至少一个消费者节点中每个消费者节点的压力相关信息的情况下,可以将至少一个消费者节点中每个消费者节点的压力相关信息进行存储,例如,存储于本地缓存或者共享缓存,其中,上述共享缓存也可以称为分布式缓存,可供多个生产者节点读写。In some optional embodiments, when the first producer node receives the pressure-related information of each consumer node in the at least one consumer node, it may use the pressure-related information of each consumer node in the at least one consumer node Stress-related information is stored, for example, in a local cache or a shared cache, where the above-mentioned shared cache can also be called a distributed cache, which can be read and written by multiple producer nodes.

步骤303、根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡。Step 303: Perform load balancing according to pressure-related information of some or all of the consumer nodes in the at least two consumer nodes.

对于上述步骤303,示例性的,第一生产者节点可以直接基于上述接收的至少一个消费者节点中每个消费者节点的压力相关信息进行负载均衡,或者第一生产者节点可以从缓存(例如,本地缓存或者共享缓存等)中读取上述至少两个消费者节点中每个消费者节点的压力相关信息,并基于读取的上述至少两个消费者节点中每个消费者节点的压力相关信息进行负载均衡。其中,上述根据消费者节点的压力相关信息进行负载均衡,示例性的,对负载压力较大的消费者节点少分配一些待消费消息,对负载压力较小的消费者节点多分配一些待消费消息。For the above step 303, for example, the first producer node may perform load balancing directly based on the received pressure-related information of each consumer node in the at least one consumer node, or the first producer node may load balance from a cache (for example , local cache or shared cache, etc.) to read the pressure-related information of each of the above-mentioned at least two consumer nodes, and based on the read pressure-related information of each of the above-mentioned at least two consumer nodes information load balancing. Among them, the above load balancing is performed according to the pressure-related information of the consumer nodes. For example, less messages to be consumed are allocated to consumer nodes with higher load pressure, and more messages to be consumed are allocated to consumer nodes with lower load pressure. .

本发明实施例提供的消息处理方法,第一生产者节点通过向至少两个消费者节点中的至少一个消费者节点发送待消费消息;分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息;根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡,由于第一生产者节点根据各个消息消费者节点的实际压力情况进行负载均衡,可以提高负载均衡的效果,此外,由于各个消费者节点在针对待消费消息的反馈消息中携带该消息消费者节点的压力相关信息,这样可以减少压力相关信息反馈的网络资源开销。还需要说明的是,由于消费者节点直接向生产者节点上述压力相关信息,也即除消费者节点和生产者节点以外,不存在与其他设备的交互,这样可以减少消费者节点压力相关信息上报的时延,这样可以保证生产者节点获取的消费者节点的压力相关信息可以更为准确的反应消费者节点当前的压力情况,进而可以提高基于消费者节点的压力相关信息进行负载均衡的效果,In the message processing method provided by the embodiment of the present invention, the first producer node sends a message to be consumed to at least one consumer node among at least two consumer nodes; respectively receives each consumer in the at least one consumer node A feedback message sent by a node for the message to be consumed, wherein each of the feedback messages carries pressure-related information of a corresponding consumer node; according to the pressure of some or all of the consumer nodes in the at least two consumer nodes Relevant information is used for load balancing. Because the first producer node performs load balancing according to the actual pressure of each message consumer node, the effect of load balancing can be improved. In addition, since each consumer node carries in the feedback message for the message to be consumed The pressure-related information of the message consumer node can reduce the network resource overhead of pressure-related information feedback. It should also be noted that since the consumer node directly reports the above pressure-related information to the producer node, that is, there is no interaction with other devices except the consumer node and the producer node, which can reduce the pressure-related information reported by the consumer node time delay, which can ensure that the pressure-related information of consumer nodes acquired by producer nodes can more accurately reflect the current pressure situation of consumer nodes, thereby improving the effect of load balancing based on the pressure-related information of consumer nodes.

可选地,所述至少两个消费者节点中的每个消费者节点均与至少两个生产者节点之间建立有通信连接,所述第一生产者节点为所述至少两个生产者节点中的任意生产者节点;Optionally, each of the at least two consumer nodes has a communication connection with at least two producer nodes, and the first producer node is the at least two producer nodes Any producer node in ;

所述分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息之后,所述方法还包括:After respectively receiving the feedback message sent by each consumer node in the at least one consumer node for the message to be consumed, the method further includes:

将所述至少一个消费者节点中每个消费者节点的压力相关信息存储于共享缓存,其中,所述共享缓存支持在所述至少两个生产者节点之间共享;storing pressure-related information for each of the at least one consumer node in a shared cache, wherein the shared cache supports sharing between the at least two producer nodes;

所述根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡,包括:The load balancing according to the pressure-related information of some or all of the consumer nodes in the at least two consumer nodes includes:

每隔第一预设时长从所述共享缓存获取所述至少两个消费者节点中每个消费者节点的压力相关信息;Acquiring pressure-related information of each of the at least two consumer nodes from the shared cache at intervals of a first preset duration;

根据所述至少两个消费者节点中每个消费者节点的压力相关信息进行负载均衡。Load balancing is performed according to the pressure-related information of each consumer node in the at least two consumer nodes.

上述第一预设时长可以根据实际情况进行合理设置,例如,1分钟、5分钟或10分钟等。在一些可选的实施例中,可以根据业务类型设置上述第一预设时长,例如,对于消息量较大的业务,上述第一预设时长可以设置的小些,对于消息量较少的业务,上述第一预设时长可以设置的大些。The above-mentioned first preset duration can be reasonably set according to the actual situation, for example, 1 minute, 5 minutes or 10 minutes. In some optional embodiments, the above-mentioned first preset duration can be set according to the business type. For example, for a business with a large amount of messages, the above-mentioned first preset duration can be set smaller, and for a business with a small amount of messages , the above-mentioned first preset duration can be set larger.

示例性的,如图5所示,每个生产者节点在接收到消费者节点返回的消费者节点的压力相关信息的情况下,将消费者节点的压力相关信息存储于共享缓存。此外,上述每个生产者节点均可以每隔第一预设时长从共享缓存读取各个消费者节点最新的压力相关信息,并基于各个消费者节点最新的压力相关信息进行负载均衡。Exemplarily, as shown in FIG. 5 , each producer node stores the pressure-related information of the consumer node in the shared cache after receiving the pressure-related information of the consumer node returned by the consumer node. In addition, each of the above-mentioned 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.

本实施例中各个生产者节点可以将接收的消费者节点的压力相关信息存储于共享缓存,这样共享缓存中可以存储有各个消费者节点最新的压力相关信息,进而各个生产者节点均可以基于共享缓存获取各个消费者节点最新的压力相关信息进行负载均衡,可以提高各个消费者节点进行负载均衡的效果,此外,本实施例中生产者节点之间相互等同,没有中心节点或者主节点,故而不存在集群的选举动作,也就不会存在选举过程中集群不可用的现象,也规避了拥有中心节点或者主节点产生“脑裂”并蜕变为两个不同且不相干的集群的可能,进而规避了数据的不一致性,提升了集群的稳定性。In this embodiment, each producer node can store the pressure-related information received by the consumer node in the shared cache, so that the latest pressure-related information of each consumer node can be stored in the shared cache, and each producer node can be based on the shared Cache to obtain the latest pressure-related information of each consumer node for load balancing, which can improve the load balancing effect of each consumer node. In addition, in this embodiment, the producer nodes are equal to each other, and there is no central node or master node, so no There is a cluster election action, so there will be no cluster unavailability during the election process, and it also avoids the possibility of having a central node or a master node resulting in a "split brain" and degenerating into two different and irrelevant clusters, thereby avoiding It eliminates data inconsistency and improves the stability of the cluster.

在一些可选的实施例中,所述方法还包括:In some optional embodiments, the method also includes:

在第二预设时长内未向第一消费者节点发送待消费消息的情况下,接收所述第一消费者节点发送的所述第一消费者节点的压力相关信息,其中,所述第一消费者节点为所述至少两个消费者节点中的任意消费者节点。In the case that no message to be consumed is sent to the first consumer node within the second preset time period, receiving the pressure-related information of the first consumer node sent by the first consumer node, wherein the first The consumer node is any consumer node in the at least two consumer nodes.

本实施例中,上述第二预设时长可以根据实际情况进行合理设置,例如,15分钟、30分钟、1小时等。In this embodiment, the above-mentioned second preset duration can be reasonably set according to the actual situation, for example, 15 minutes, 30 minutes, 1 hour and so on.

本实施例中,消费者节点可以在较长时间内未接收到待消费消息的情况下,主动向生产者节点反馈其压力相关信息,这样生产者节点可以基于消费者节点主动反馈的压力相关信息更新所存储的该消费者节点的压力相关信息,便于生产者节点基于各个消费者节点最新的压力相关信息进行负载均衡,以提高负载均衡的效果。In this embodiment, the consumer node can actively feed back its pressure-related information to the producer node when it has not received the message to be consumed for a long time, so that the producer node can actively feed back the pressure-related information based on the consumer node Updating the stored pressure-related information of the consumer node is convenient for the producer node to perform load balancing based on the latest pressure-related information of each consumer node, so as to improve the effect of load balancing.

在一些可选的实施例中,所述消费者节点的压力相关信息包括如下至少一项:所述消费者节点的压力指标值,压力评估值;In some optional embodiments, the pressure-related information of the consumer node includes at least one of the following: a pressure index value of the consumer node, and a stress evaluation value;

其中,所述压力评估值根据所述消费者节点的压力指标值确定。Wherein, the pressure evaluation value is determined according to the pressure index value of the consumer node.

在一些可选的实施例中,所述压力指标值可以包括但不限于如下至少一种:磁盘占用率,CPU占用率,内存占用率,下游调用响应时间。In some optional embodiments, the pressure indicator value may include but not limited to at least one of the following: disk usage, CPU usage, memory usage, and downstream call response time.

上述压力评估值可以直接用于评估上述消费者节点的压力大小,例如,上述压力评估值可以是根据至少一种压力指标值计算得到的压力分数值,其中,消费者节点的压力分数值越大,表示该消费者节点的负载压力越大,消费者节点的压力分数值越小,表示该消费者节点的负载压力越小。The above-mentioned pressure evaluation value can be directly used to evaluate the pressure of the above-mentioned consumer node. For example, the above-mentioned pressure evaluation value can be a pressure score value calculated according to at least one pressure index value, wherein the greater the pressure score value of the consumer node , indicating that the greater the load pressure of the consumer node, the smaller the pressure score value of the consumer node, indicating that the lower the load pressure of the consumer node.

在一实施方式中,各个消费者节点可以向生产者节点上报至少一种压力指标值,例如,磁盘占用率,CPU占用率,内存占用率,下游调用响应时间等,这样生产者节点可以分别依据各个消费者节点上报的至少一种压力指标值计算各个消费者节点对应的负载均衡权重值或者负载均衡分数等,进而可以基于各个消费者节点对应的负载均衡权重值或者负载均衡分数等进行负载均衡。这种方式有利于保证各个消费者节点对应的负载均衡权重值或者负载均衡分数的计算方式的一致性,进而提高负载均衡的准确性。In one embodiment, each consumer node can report at least one pressure indicator value to the producer node, for example, disk occupancy rate, CPU occupancy rate, memory occupancy rate, downstream call response time, etc., so that the producer nodes can respectively according to At least one pressure index value reported by each consumer node calculates the load balancing weight value or load balancing score corresponding to each consumer node, and then load balancing can be performed based on the load balancing weight value or load balancing score corresponding to each consumer node . This method is beneficial to ensure the consistency of the calculation method of the load balancing weight value or the load balancing score corresponding to each consumer node, thereby improving the accuracy of the load balancing.

在另一实施方式中,各个消费者节点可以向生产者节点上报基于至少一种压力指标值计算得到的压力评估值,这样生产者节点可以直接依据各个消费者节点的压力评估值进行负载均衡,而无需进行额外的计算,这样不仅可以减少消费者节点进行压力相关信息上报的资源开销,还可以节省生产者节点的计算资源。In another embodiment, each consumer node can report to the producer node the pressure evaluation value calculated based on at least one pressure index value, so that the producer node can directly perform load balancing based on the pressure evaluation value of each consumer node, No additional calculation is required, which 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.

在一些可选的实施例中,所述根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡,包括:In some optional embodiments, performing load balancing according to pressure-related information of some or all of the at least two consumer nodes includes:

根据所述至少两个消费者节点中每个消费者节点的压力相关信息和每个所述消费者节点对应的消息响应时间进行负载均衡,其中,所述消息响应时间为所述第一生产者节点发送待消费消息至所述第一生产者节点接收到针对所述待消费消息的反馈消息的时间。Perform load balancing according to the pressure-related information of each of 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 first producer The node sends the message to be consumed to the time when the first producer node receives a feedback message for the message to be consumed.

实际应用中,生产者节点与各个消费者节点之间的网络状态可能存在差异,对于网络状态较好的消费者节点,其消息响应时间往往较短,此时生产者节点往往希望向该消费者节点发送较多的待消费消息;而对于网络状态较差的消费者节点,其消息响应时间往往较长,此时生产者节点往往希望向该消费者节点发送较少的待消费消息,这样有利益于提高消息推送效率。In practical 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 the consumer node Nodes send more messages to be consumed; and for consumer nodes with poor network status, their message response time is often longer, at this time, producer nodes often want to send fewer messages to be consumed to the consumer node, so that It is beneficial to improve the efficiency of message push.

本实施例通过综合各个消费者节点的压力相关信息以及消息响应时间进行负载均衡,例如,生产者节点可以对消费者节点的压力评估值和消息响应时间进行加权计算,得到负载均衡分数,并基于负载均衡分数进行负载均衡,这样可以在保证消费者节点之间的负载均衡效果的同时,兼顾消息推送效率。In this embodiment, load balancing is carried out by synthesizing the pressure-related information and message response time of each consumer node. For example, the producer node can perform weighted calculation on the pressure evaluation value and message response time of the consumer node to obtain a load balancing score, and based on The load balancing score is used for load balancing, so that the efficiency of message push can be taken into account while ensuring the load balancing effect between consumer nodes.

图6是本发明又一实施例提供的消息处理方法的流程图,该消息处理方法应用于第一消费者节点,如图6所示,包括以下步骤:Fig. 6 is a flowchart of a message processing method provided by another embodiment of the present invention, the message processing method is applied to the first consumer node, as shown in Fig. 6 , including the following steps:

步骤601、接收第一生产者节点发送的待消费消息。Step 601. Receive a message to be consumed sent by a first producer node.

本实施例中,上述第一生产者节点可以是任意的生产者节点,其中,该第一生产者节点与至少两个消费者节点之间建立有通信连接,也就是说,上述至少两个消费者节点中的每个消费者节点均可以接收上述第一生产者节点发送的待消费消息。上述第一消费者节点可以是上述至少两个消费者节点中的任意消费者节点。In this embodiment, the above-mentioned first producer node may be any producer node, wherein communication connections are established between the first producer node and at least two consumer nodes, that is, the above-mentioned at least two consumer nodes Each consumer node among the producer nodes can receive the to-be-consumed message sent by the above-mentioned first producer node. The above-mentioned first consumer node may be any consumer node among the above-mentioned at least two consumer nodes.

步骤602、对所述待消费消息进行消息消费。Step 602, perform message consumption on the message to be consumed.

上述第一消费者节点可以对待消费消息进行消费可以理解为上述第一消费者节点对待消费消息进行相关处理,例如,若上述待消费消息为账户查询请求消息,则第一消费者节点可以基于该账户查询请求消息查询对应账户的相关信息。It can be understood that the above-mentioned first consumer node can consume the message to be consumed, which means that the above-mentioned first consumer node performs related processing on the message to be consumed. For example, if the above-mentioned message to be consumed is an account query request message, the first consumer node can The account query request message queries the relevant information of the corresponding account.

步骤603、向所述第一生产者节点发送针对所述待消费消息的反馈消息,其中,所述反馈消息携带有第一消费者节点的压力相关信息,所述第一消费者节点的压力相关信息用于表征所述第一消费者节点的负载压力状况。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 The information is used to characterize the load pressure condition of the first consumer node.

上述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况,也就是说通过消费者节点的压力相关信息可以获知该消费者节点的负载压力情况,例如,负载压力较大或负载压力较小等。示例性的,上述消费者节点的压力相关信息可以包括但不限于压力指标值、压力评估值等中的至少一项。其中,上述压力指标值可以包括磁盘占用率、CPU占用率、内存占用率、下游调用响应时间、磁盘写入速度、线程池大小等中的一种或多种。上述压力评估值可以是基于一种或多种压力指标值计算得到,例如,可以基于CPU占用率和内存占用率计算得到一个压力评估分值,并将该压力评估分值反馈给生产者节点。The above-mentioned pressure-related information of the consumer node is used to characterize the load pressure condition of the consumer node, that is to say, the load pressure condition of the consumer node can be known through the pressure-related information of the consumer node, for example, the load pressure is high or Load pressure is small, etc. Exemplarily, the above-mentioned stress-related information of the consumer node may include but not limited to at least one of a stress index value, a stress evaluation value, and the like. Wherein, the above-mentioned pressure index value may include one or more of disk usage rate, CPU usage rate, memory usage rate, downstream call response time, disk writing speed, thread pool size, and the like. The above pressure assessment value may be calculated based on one or more pressure index values, for example, a pressure assessment score may be calculated based on CPU occupancy rate and memory occupancy rate, and the pressure assessment score value may be fed back to the producer node.

示例性的,若待消费消息为账户查询请求消息,则该待消费消息的反馈消息可以包括对应账户的相关信息,此外,该反馈消息还可以携带有第一消费者节点的压力相关信息。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.

在一些可选的实施例中,第一消费者节点可以在每接收一条待消费消息的情况下,均在该待消费消息的反馈消息中携带第一消费者节点的压力相关信息;或者,第一消费者节点可以仅在压力相关信息发生变化的情况下,在最近一次接收的待消费消息的反馈消息中携带第一消费者节点的压力相关信息。In some optional embodiments, the first consumer node may carry pressure-related information of the first consumer node in the feedback message of the message to be consumed each time it receives a message to be consumed; or, the first consumer node A consumer node may carry the pressure-related information of the first consumer node in the feedback message of the latest received message to be consumed only when the pressure-related information changes.

实际应用中,第一生产者节点可以向多个消费者节点发送待消费消息,示例性的,如图4所示,各个消费者节点接收待消费消息并完成待消费消息处理后,可以向第一生产者节点发送针对该待消费消息的反馈消息,该反馈消息中携带有该消费者节点的压力相关信息。例如,消费者节点A完成待消费消息A的处理后,可以向第一消费者节点发送针对待消费消息A的反馈消息,该反馈消息携带有消费者节点A的压力相关信息;消费者节点B完成待消费消息B的处理后,可以向第一消费者节点发送针对待消费消息B的反馈消息,该反馈消息携带有消费者节点B的压力相关信息,以此类推。这样第一生产者节点可以基于各个消费者节点的压力相关信息进行负载均衡,例如,对负载压力较大的消费者节点少分配一些待消费消息,对负载压力较小的消费者节点多分配一些待消费消息。In practical applications, the first producer node can send messages to be consumed to multiple consumer nodes. Exemplarily, as shown in FIG. A producer node sends a feedback message for the message to be consumed, and the feedback message carries pressure-related information of the consumer node. For example, after the consumer node A completes the processing of the message A to be consumed, it can send a feedback message for the message A to be consumed to the first consumer node, the feedback message carries the pressure-related information of the consumer node A; the consumer node B After completing the processing of the message B to be consumed, a feedback message for the message B to be consumed may be sent to the first consumer node, the feedback message carrying the pressure-related information of the 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 less messages to be consumed to consumer nodes with high load pressure, and allocate more to consumer nodes with low load pressure. Messages to be consumed.

本发明实施例提供的消息处理方法,第一消费者节点接收第一生产者节点发送的待消费消息,对所述待消费消息进行消息消费,并在向所述第一生产者节点发送的针对所述待消费消息的反馈消息中携带第一消费者节点的压力相关信息,由于消费者节点在针对待消费消息的反馈消息中携带该消息消费者节点的压力相关信息,这样可以减少压力相关信息反馈的网络资源开销,此外,由于消费者节点直接向生产者节点上报上述压力相关信息,也即除消费者节点和生产者节点以外,不存在与其他设备的交互,这样可以减少消费者节点压力相关信息上报的时延,这样可以保证生产者节点获取的消费者节点的压力相关信息可以更为准确的反应消费者节点当前的压力情况,进而可以提高基于消费者节点的压力相关信息进行负载均衡的效果。In the message processing method provided by the embodiment of the present invention, the first consumer node receives the message to be consumed sent by the first producer node, consumes the message to be consumed, and sends the message to the first producer node for The feedback message of the message to be consumed carries the pressure-related information of the first consumer node, since the consumer node carries the pressure-related information of the message consumer node in the feedback message for the message to be consumed, this can reduce the pressure-related information Feedback network resource overhead, in addition, because the consumer node directly reports the above pressure-related information to the producer node, that is, there is no interaction with other devices except the consumer node and the producer node, which can reduce the pressure on the consumer node The delay in reporting relevant information can ensure that the pressure-related information of consumer nodes obtained by producer nodes can more accurately reflect the current pressure situation of consumer nodes, which in turn can improve load balancing based on the pressure-related information of consumer nodes Effect.

在一些可选的实施例中,所述方法还包括:In some optional embodiments, the method also includes:

在第二预设时长内未接收到所述第一生产者节点发送的待消费消息的情况下,向所述第一生产者节点发送所述第一消费者节点的压力相关信息;Sending the pressure-related information of the first consumer node to the first producer node if the message to be consumed sent by the first producer node is not received within the second preset time period;

或者or

在第二预设时长内未接收到至少两个生产者节点中任意生产者节点发送的待消费消息的情况下,向所述至少两个生产者节点中的生产者节点发送所述第一消费者节点的压力相关信息,其中,所述第一消费者节点与所述至少两个生产者节点之间建立有通信连接,所述至少两个生产者节点包括所述第一生产者节点。In the case that no message to be consumed sent by any producer node among the at least two producer nodes is received within the second preset time period, the first consumption message is sent to the producer node among the at least two producer nodes pressure-related information of a producer node, 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.

本实施例中,上述第二预设时长可以根据实际情况进行合理设置,例如,15分钟、30分钟、1小时等。In this embodiment, the above-mentioned second preset duration can be reasonably set according to the actual situation, for example, 15 minutes, 30 minutes, 1 hour and so on.

在一实施方式中,第一消费者节点可以在第二预设时长内未接收到某一生产者节点发送的待消费消息的情况下,向该生产者节点主动上报第一消费者节点的压力相关信息,这样可以保证各个生产者节点均可以直接获取到第一消费者节点最新的压力相关信息。In one embodiment, the first consumer node can actively report the pressure of the first consumer node to the producer node if it does not receive the message to be consumed sent by the producer node within the second preset time period In this way, each producer node can directly obtain the latest pressure-related information of the first consumer node.

在另一实施方式中,第一消费者节点可以在第二预设时长内未接收到任一生产者节点发送的待消费消息的情况下,向上述至少两个生产者节点中的任意一个或多个生产者节点主动上报第一消费者节点的压力相关信息,或者可以向上述至少两个生产者节点中特定的某一个生产者节点主动上报第一消费者节点的压力相关信息,例如,可以向上述至少两个生产者节点中的目标生产者节点主动上报第一消费者节点的压力相关信息,其中,第一消费者节点最近一次接收的待消费消息为上述目标生产者节点发送的待消费消息,这样在第一消费者节点与至少两个生产者节点交互的情况下,可以节省第一消费者节点上报压力相关消息的网络资源开销。In another embodiment, if the first consumer node does not receive any message to be consumed sent by any producer node within the second preset time period, it may send a message to any one of the at least two producer nodes or Multiple producer nodes actively report the pressure-related information of the first consumer node, or may actively report the pressure-related information of the first consumer node to a specific producer node among the above-mentioned at least two producer nodes, for example, may Actively report the pressure-related information of the first consumer node to the target producer node among the at least two producer nodes, wherein the message to be consumed last received by the first consumer node is the message to be consumed sent by the above-mentioned 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 reporting pressure-related messages can be saved.

在一些可选的实施例中,所述消费者节点的压力相关信息包括如下至少一项:所述消费者节点的压力指标值,压力评估值;In some optional embodiments, the pressure-related information of the consumer node includes at least one of the following: a pressure index value of the consumer node, and a stress evaluation value;

其中,所述压力评估值根据所述消费者节点的压力指标值确定。Wherein, the pressure evaluation value is determined according to the pressure index value of the consumer node.

在一些可选的实施例中,所述压力指标值包括如下至少一种:磁盘占用率,CPU占用率,内存占用率,下游调用响应时间。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.

上述压力评估值可以直接用于评估上述消费者节点的压力大小,例如,上述压力评估值可以是根据至少一种压力指标值计算得到的压力分数值,其中,消费者节点的压力分数值越大,表示该消费者节点的负载压力越大,消费者节点的压力分数值越小,表示该消费者节点的负载压力越小。The above-mentioned pressure evaluation value can be directly used to evaluate the pressure of the above-mentioned consumer node. For example, the above-mentioned pressure evaluation value can be a pressure score value calculated according to at least one pressure index value, wherein the greater the pressure score value of the consumer node , indicating that the greater the load pressure of the consumer node, the smaller the pressure score value of the consumer node, indicating that the lower the load pressure of the consumer node.

在一实施方式中,各个消费者节点可以向生产者节点上报至少一种压力指标值,例如,磁盘占用率,CPU占用率,内存占用率,下游调用响应时间等,这样生产者节点可以分别依据各个消费者节点上报的至少一种压力指标值计算各个消费者节点对应的负载均衡权重值或者负载均衡分数等,进而可以基于各个消费者节点对应的负载均衡权重值或者负载均衡分数等进行负载均衡。这种方式有利于保证各个消费者节点对应的负载均衡权重值或者负载均衡分数的计算方式的一致性,进而提高负载均衡的准确性。In one embodiment, each consumer node can report at least one pressure indicator value to the producer node, for example, disk occupancy rate, CPU occupancy rate, memory occupancy rate, downstream call response time, etc., so that the producer nodes can respectively according to At least one pressure index value reported by each consumer node calculates the load balancing weight value or load balancing score corresponding to each consumer node, and then load balancing can be performed based on the load balancing weight value or load balancing score corresponding to each consumer node . This method is beneficial to ensure the consistency of the calculation method of the load balancing weight value or the load balancing score corresponding to each consumer node, thereby improving the accuracy of the load balancing.

在另一实施方式中,各个消费者节点可以向生产者节点上报基于至少一种压力指标值计算得到的压力评估值,这样生产者节点可以直接依据各个消费者节点的压力评估值进行负载均衡,而无需进行额外的计算,这样不仅可以减少消费者节点进行压力相关信息上报的资源开销,还可以节省生产者节点的计算资源。In another embodiment, each consumer node can report to the producer node the pressure evaluation value calculated based on at least one pressure index value, so that the producer node can directly perform load balancing based on the pressure evaluation value of each consumer node, No additional calculation is required, which 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.

在一些可选的实施例中,所述压力评估值根据所述消费者节点的至少两种压力指标值和目标权重组计算得到,其中,所述目标权重组包括所述至少两种压力指标值中每种压力指标值的权重。In some optional embodiments, the stress evaluation value is calculated according to at least two stress index values of the consumer node and a target weight group, wherein the target weight group includes the at least two stress index values The weight of each pressure indicator value in .

本实施例中,上述目标权重组可以是预设的一个权重组,也可以是从多个权重组中选择的一个权重组。In this embodiment, the aforementioned target weight group may be a preset weight group, or may be a weight group selected from multiple weight groups.

示例性的,上述至少两种压力指标值包括CPU占用率和内存占用率,上述目标权重组包括第一权重和第二权重,其中,第一权重为CPU占用率的权重,第二权重为内存占用率的权重,则第一消费者节点可以分别将CPU占用率和第一权重相乘,得到第一值,将内存占用率与第二权重相乘得到第二值,将第一值与第二值相加得到上述压力评估值。Exemplarily, the above-mentioned at least two stress index values include CPU occupancy rate and memory occupancy rate, and the above-mentioned target weight group includes a first weight and a second weight, wherein the first weight is the weight of the CPU occupancy rate, and the second weight is the memory occupancy rate. occupancy rate, the first consumer node can multiply the CPU occupancy rate by the first weight to obtain the first value, multiply the memory occupancy rate by the second weight to obtain the second value, and multiply the first value by the second weight The two values are added to obtain the above pressure estimate.

在一些可选的实施例中,所述目标权重组为目标计算周期对应的权重组,所述目标计算周期为N个计算周期中对应的方差值最小的计算周期,N为大于1的整数,所述N个计算周期分别对应N个不同的权重组,每个所述权重组包括所述至少两种压力指标值中每种压力指标值的权重;In some optional embodiments, the target weight group is the weight group corresponding to the target calculation period, and the target calculation period is the calculation period with the smallest variance value corresponding to the N calculation periods, where N is an integer greater than 1 , the N calculation cycles respectively correspond to N different weight groups, each of which includes the weight of each pressure index value in the at least two pressure index values;

其中,所述N个计算周期中的第i个计算周期对应的方差值通过如下方式确定:Wherein, the variance value corresponding to the i-th calculation period in the N calculation periods is determined in the following manner:

在所述第i个计算周期内根据所述消费者节点的至少两种压力指标值和第i个权重组计算第i个压力评估值;i的取值范围为[1,N];In the i-th calculation period, calculate the i-th pressure evaluation value according to at least two pressure index values and the i-th weight group of the consumer node; the value range of i is [1, N];

向所述第一生产者节点发送所述第i个压力评估值,以使所述第一生产者节点根据所述第i个压力评估值进行负载均衡;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;

统计在所述第i个计算周期内的M个时间单元中每个时间单元对应的请求响应数,M为大于1的整数;Count the number of request responses corresponding to each time unit in the M time units in the i-th calculation cycle, where M is an integer greater than 1;

分别计算所述M个时间单元中每个时间单元对应的请求响应数和所述第i个压力评估值的比值,得到M个比值;Calculate the ratio of the number of request responses corresponding to each time unit in the M time units and the i-th pressure evaluation value to obtain M ratios;

计算所述M个比值的方差值,得到所述第i个计算周期对应的方差值。Calculate the variance values of the M ratios to obtain the variance values corresponding to the i-th calculation period.

本实施例中,上述计算周期的长度可以根据实际情况进行合理设置,例如,1分钟或5分钟等。上述时间单元可以根据实际情况进行合理设置,例如,1秒钟、10秒钟、30秒或1分钟等。需要说明的是,一个计算周期包括M个或M个以上的时间单元。上述N个计算周期可以是历史N个计算周期。上述时间单元对应的请求响应数可以包括在该时间单元内处理的待消费消息的数量,或者在该时间单元内接收的待消费消息的数量等。In this embodiment, the length of the above calculation period may be reasonably set according to actual conditions, for example, 1 minute or 5 minutes. The above time unit can be reasonably set according to the actual situation, 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 aforementioned N calculation cycles may be historical N calculation cycles. The number of request responses corresponding to the above 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, and the like.

上述N个计算周期中每个计算周期对应的权重组可以是预先设置的;也可以是根据预先设置的权重取值范围确定的,例如,预先分别设置每种压力指标值对应的权重取值范围,针对每个计算周期,依次按照预设步长从每种压力指标值对应的权重取值范围获取每种压力指标值对应的权重,得到该计算周期对应的权重组。The weight group corresponding to each calculation period in the above N calculation periods can be preset; it can also be determined according to the preset weight value range, for example, the weight value range corresponding to each pressure index value is set in advance , 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 sequence according to the preset step size, and the weight group corresponding to the calculation cycle is obtained.

具体的,各个消费者节点在每个计算周期内分别基于对应的权重组计算该计算周期对应的压力评估值并上报给第一生产者节点,第一生产者节点可以基于各个消费者节点上报的压力评估值进行负载均衡,这样各个消费者节点可以分别统计在各个计算周期内的每个时间单元对应的请求响应数和该计算周期对应的压力评估值的比值,并可以计算M个时间单元对应的比值的方差值作为该计算周期对应的方差值,在得到N个计算周期中每个计算周期对应的方差值之后,可以将方差值最小的计算周期对应的权重组作为目标权重组。Specifically, each consumer node calculates the pressure evaluation 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 be based on the The pressure evaluation value is used for load balancing, so that each consumer node can count the ratio of the number of request responses corresponding to each time unit in each calculation cycle to the pressure evaluation value corresponding to the calculation cycle, and can calculate the corresponding The variance value of the ratio of is used as the variance value corresponding to the calculation period. After obtaining the variance value corresponding to each calculation period in the N calculation periods, the weight group corresponding to the calculation period with the smallest variance value can be used as the target weight reorganization.

本实施例中,通过第一消费者节点分别在每个计算周期基于对应的权重组计算压力评估值并发送给第一生产者节点,以使第一生产者节点基于上报的压力评估值进行负载均衡,这样第一消费者节点可以统计在基于各个压力评估值进行负载均衡后在对应计算周期内的多个时间单元对应的请求响应数,以计算各个计算周期对应的方差值,并选择方差值最小的计算周期对应的权重组作为目标权重组,由于基于各个压力评估值进行负载均衡后在对应计算周期内的多个时间单元对应的请求响应数可以较为准确的反应基于各个权重组计算的压力评估值进行负载均衡后的效果,因此基于各个计算周期内的多个时间单元对应的请求响应数计算得到的方差值选择目标权重组可以保证选择的目标权重组较为合理,进而可以提高基于目标权重组计算的压力评估值进行负载均衡的效果。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 calculation based on the reported pressure evaluation value. balance, so that the first consumer node can count the number of request responses corresponding to multiple time units in the corresponding calculation period after load balancing based on each pressure evaluation value, to calculate the variance value corresponding to each calculation period, and choose the method The weight group corresponding to the calculation period with the smallest difference is used as the target weight group, because the number of request responses corresponding to multiple time units in the corresponding calculation period after load balancing based on each pressure evaluation value can be more accurately reflected based on the calculation of each weight group Therefore, the selection of the target weight group based on the variance value calculated by 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, which in turn can improve The effect of load balancing based on the pressure evaluation value calculated by the target weight group.

在一些可选的实施例中,第一消费者节点还可以提供重构功能,例如,可以提供用于更改压力评估值计算相关的接口,通过该接口可更改压力评估值计算方式,例如,更改参与压力评估值计算的压力指标值、权重等,允许消费者节点以自身的特点实现压力评估值的计算,提供满足自身需求的压力评估值计算。In some optional embodiments, the first consumer node can also provide a reconstruction function, for example, an interface for changing the calculation of the pressure evaluation value can be provided, through which the calculation method of the pressure evaluation value can be changed, for example, changing The pressure index value, weight, etc. that participate in the calculation of the pressure assessment value allow the consumer node to realize the calculation of the pressure assessment value with its own characteristics, and provide the calculation of the pressure assessment value that meets its own needs.

综上可知,通过本实施例提供的消息处理方法,可以使得消费者节点整体资源压力相对均衡,可以更精细化计算资源的管理和使用,可以加强集群健壮性,避免因为单节点故障导致的集群“雪崩”;不需要中心协调节点;可以实现在较频繁的网络业务交互中,不需要额外的针对负载均衡数据的网络开销,也可以实现在教少业务,或因为某个节点因为暂时压力较大,被请求数据较少的时候,主动上报的频次。与传统负载均衡相比,可以减少负载均衡设备的成本,减少负载均衡信息传输的成本,提升日常负载均衡的效果。To sum up, the message processing method provided by this embodiment can make the overall resource pressure of the consumer node relatively balanced, can refine the management and use of computing resources, can strengthen the robustness of the cluster, and avoid cluster failures caused by single node failures. "Avalanche"; no central coordination node is required; it can be implemented in more frequent network business interactions without additional network overhead for load balancing data, and can also be implemented when teaching less business, or because a node is temporarily under pressure Large, when the requested data is small, the frequency of active reporting. 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.

参见图7,图7是本发明实施例提供的消息处理装置的结构图,该消息处理装置应用于第一生产者节点,所述第一生产者节点与至少两个消费者节点之间建立有通信连接,如图7所示,消息处理装置700包括:Referring to FIG. 7, FIG. 7 is a structural diagram of a message processing device provided by an embodiment of the present invention. The message processing device is applied to a first producer node, and a network is established between the first producer node and at least two consumer nodes. Communication connection, as shown in Figure 7, the message processing device 700 includes:

第一发送模块701,用于向所述至少两个消费者节点中的至少一个消费者节点发送待消费消息;The first sending module 701 is configured to send a message to be consumed to at least one consumer node among the at least two consumer nodes;

第一接收模块702,用于分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息,所述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况;The first receiving module 702 is configured to respectively receive a feedback message sent by each consumer node in the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries the corresponding consumer node Pressure-related information, the pressure-related information of the consumer node is used to characterize the load pressure status of the consumer node;

负载均衡模块703,用于根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡。A load balancing module 703, configured to perform load balancing according to pressure-related information of some or all of the consumer nodes in the at least two consumer nodes.

可选地,所述至少两个消费者节点中的每个消费者节点均与至少两个生产者节点之间建立有通信连接,所述第一生产者节点为所述至少两个生产者节点中的任意生产者节点;Optionally, each of the at least two consumer nodes has a communication connection with at least two producer nodes, and the first producer node is the at least two producer nodes Any producer node in ;

所述装置还包括:The device also includes:

存储模块,用于所述分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息之后,将所述至少一个消费者节点中每个消费者节点的压力相关信息存储于共享缓存,其中,所述共享缓存支持在所述至少两个生产者节点之间共享;The storage module is configured to, after respectively receiving the feedback message sent by each consumer node in the at least one consumer node for the message to be consumed, store the information of each consumer node in the at least one consumer node Stress-related information is stored in a shared cache, wherein the shared cache supports sharing between the at least two producer nodes;

所述负载均衡模块具体用于:The load balancing module is specifically used for:

每隔第一预设时长从所述共享缓存获取所述至少两个消费者节点中每个消费者节点的压力相关信息;Acquiring pressure-related information of each of the at least two consumer nodes from the shared cache at intervals of a first preset duration;

根据所述至少两个消费者节点中每个消费者节点的压力相关信息进行负载均衡。Load balancing is performed according to the pressure-related information of each consumer node in the at least two consumer nodes.

可选地,所述装置还包括:Optionally, the device also includes:

第二接收模块,用于在第二预设时长内未向第一消费者节点发送待消费消息的情况下,接收所述第一消费者节点发送的所述第一消费者节点的压力相关信息,其中,所述第一消费者节点为所述至少两个消费者节点中的任意消费者节点。The second receiving module is configured to receive the 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 in the at least two consumer nodes.

可选地,所述消费者节点的压力相关信息包括如下至少一项:所述消费者节点的压力指标值,压力评估值;Optionally, the pressure-related information of the consumer node includes at least one of the following: a pressure index value of the consumer node, and a pressure evaluation value;

其中,所述压力评估值根据所述消费者节点的压力指标值确定。Wherein, the pressure evaluation value is determined according to the pressure index value of the consumer node.

可选地,所述压力指标值包括如下至少一种:磁盘占用率,CPU占用率,内存占用率,下游调用响应时间。Optionally, the pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.

可选地,所述负载均衡模块具体用于:Optionally, the load balancing module is specifically used for:

根据所述至少两个消费者节点中每个消费者节点的压力相关信息和每个所述消费者节点对应的消息响应时间进行负载均衡,其中,所述消息响应时间为所述第一生产者节点发送待消费消息至所述第一生产者节点接收到针对所述待消费消息的反馈消息的时间。Perform load balancing according to the pressure-related information of each of 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 first producer The node sends the message to be consumed to the time when the first producer node receives a feedback message for the message to be consumed.

本发明实施例提供的消息处理装置700能够实现上述第一生产者节点侧方法实施例中的各个过程,为避免重复,这里不再赘述。The message processing device 700 provided by the embodiment of the present invention can realize each process in the above-mentioned first producer node side method embodiment, and to avoid repetition, details are not repeated here.

参见图8,图8是本发明实施例提供的消息处理装置的结构图,该消息处理装置,应用于第一消费者节点。如图8所示,消息处理装置800包括:Referring to FIG. 8 , FIG. 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. As shown in Figure 8, the message processing device 800 includes:

第一接收模块801,用于接收第一生产者节点发送的待消费消息;The first receiving module 801 is configured to receive the message to be consumed sent by the first producer node;

消息消费模块802,用于对所述待消费消息进行消息消费;A message consumption module 802, configured to consume the message to be consumed;

第一发送模块803,用于向所述第一生产者节点发送针对所述待消费消息的反馈消息,其中,所述反馈消息携带有所述第一消费者节点的压力相关信息,所述第一消费者节点的压力相关信息用于表征所述第一消费者节点的负载压力状况。The first sending module 803 is configured to send a feedback message for the message to be consumed to the first producer node, where the feedback message carries pressure-related information of the first consumer node, and the second The pressure related information of a consumer node is used to characterize the load pressure condition of the first consumer node.

可选地,所述装置还包括第二发送模块,所述第二发送模块具体用于:Optionally, the device further includes a second sending module, and the second sending module is specifically configured to:

在第二预设时长内未接收到所述第一生产者节点发送的待消费消息的情况下,向所述第一生产者节点发送所述第一消费者节点的压力相关信息;Sending the pressure-related information of the first consumer node to the first producer node if the message to be consumed sent by the first producer node is not received within the second preset time period;

或者or

在第二预设时长内未接收到至少两个生产者节点中任意生产者节点发送的待消费消息的情况下,向所述至少两个生产者节点中的生产者节点发送所述第一消费者节点的压力相关信息,其中,所述第一消费者节点与所述至少两个生产者节点之间建立有通信连接,所述至少两个生产者节点包括所述第一生产者节点。In the case that no message to be consumed sent by any producer node among the at least two producer nodes is received within the second preset time period, the first consumption message is sent to the producer node among the at least two producer nodes pressure-related information of a producer node, 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.

可选地,所述消费者节点的压力相关信息包括如下至少一项:所述消费者节点的压力指标值,压力评估值;Optionally, the pressure-related information of the consumer node includes at least one of the following: a pressure index value of the consumer node, and a pressure evaluation value;

其中,所述压力评估值根据所述消费者节点的压力指标值确定。Wherein, the pressure evaluation value is determined according to the pressure index value of the consumer node.

可选地,所述压力指标值包括如下至少一种:磁盘占用率,CPU占用率,内存占用率,下游调用响应时间。Optionally, the pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time.

可选地,所述压力评估值根据所述消费者节点的至少两种压力指标值和目标权重组计算得到,其中,所述目标权重组包括所述至少两种压力指标值中每种压力指标值的权重。Optionally, the pressure evaluation value is calculated according to at least two pressure index values and a target weight group of the consumer node, wherein the target weight group includes each pressure index in the at least two pressure index values The weight of the value.

可选地,所述目标权重组为目标计算周期对应的权重组,所述目标计算周期为N个计算周期中对应的方差值最小的计算周期,N为大于1的整数,所述N个计算周期分别对应N个不同的权重组,每个所述权重组包括所述至少两种压力指标值中每种压力指标值的权重;Optionally, the target weight group is a weight group corresponding to a target calculation period, and the target calculation period is a calculation period corresponding to the smallest variance value among N calculation periods, N is an integer greater than 1, and the N The calculation periods respectively correspond to N different weight groups, each of which includes the weight of each pressure index value in the at least two pressure index values;

其中,所述N个计算周期中的第i个计算周期对应的方差值通过如下方式确定:Wherein, the variance value corresponding to the i-th calculation period in the N calculation periods is determined in the following manner:

在所述第i个计算周期内根据所述消费者节点的至少两种压力指标值和第i个权重组计算第i个压力评估值;i的取值范围为[1,N];In the i-th calculation period, calculate the i-th pressure evaluation value according to at least two pressure index values and the i-th weight group of the consumer node; the value range of i is [1, N];

向所述第一生产者节点发送所述第i个压力评估值,以使所述第一生产者节点根据所述第i个压力评估值进行负载均衡;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;

统计在所述第i个计算周期内的M个时间单元中每个时间单元对应的请求响应数,M为大于1的整数;Count the number of request responses corresponding to each time unit in the M time units in the i-th calculation cycle, where M is an integer greater than 1;

分别计算所述M个时间单元中每个时间单元对应的请求响应数和所述第i个压力评估值的比值,得到M个比值;Calculate the ratio of the number of request responses corresponding to each time unit in the M time units and the i-th pressure evaluation value to obtain M ratios;

计算所述M个比值的方差值,得到所述第i个计算周期对应的方差值。Calculate the variance values of the M ratios to obtain the variance values corresponding to the i-th calculation period.

本发明实施例提供的消息处理装置800能够实现上述第一消费者节点侧方法实施例中的各个过程,为避免重复,这里不再赘述。The message processing apparatus 800 provided by the embodiment of the present invention can realize each process in the above-mentioned first consumer node side method embodiment, and to avoid repetition, details are not repeated here.

参见图9,图9是本发明又一实施提供的消息处理装置的结构图,如图9所示,消息处理装置900包括:处理器901、存储器902及存储在所述存储器902上并可在所述处理器上运行的计算机程序,消息处理装置900中的各个组件通过总线接口903耦合在一起,所述计算机程序被所述处理器901执行时实现如下步骤:Referring to FIG. 9, FIG. 9 is a structural diagram of a message processing device provided by another embodiment of the present invention. As shown in FIG. 9, the message processing device 900 includes: a processor 901, a memory 902, and a The computer program running on the processor, the various components in the message processing device 900 are coupled together through the bus interface 903, and the computer program is executed by the processor 901 to implement the following steps:

向所述至少两个消费者节点中的至少一个消费者节点发送待消费消息;sending a message to be consumed to at least one of the at least two consumer nodes;

分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息,所述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况;Respectively receive a feedback message sent by each consumer node in 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 consumer The pressure related information of the node is used to characterize the load pressure condition of the consumer node;

根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡;performing load balancing according to pressure-related information of some or all of the at least two consumer nodes;

或者or

接收第一生产者节点发送的待消费消息;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 It is used to characterize the load pressure condition of the first consumer node.

应理解的是,本发明实施例中,所述计算机程序被处理器901执行时能够实现上述消息处理方法实施例中的各个过程,为避免重复,这里不再赘述。It should be understood that, in this embodiment of the present invention, when the computer program is executed by the processor 901, each process in the above embodiment of the message processing method can be implemented, and details are not repeated here to avoid repetition.

本发明实施例还提供一种电子设备,包括处理器,存储器,存储在存储器上并可在所述处理器上运行的计算机程序,该计算机程序被处理器执行时实现上述消息处理方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。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 operable on the processor. When the computer program is executed by the processor, the above message processing method embodiment is implemented. Each process can achieve the same technical effect, so in order to avoid repetition, it will not be repeated here.

本发明实施例还提供一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序,该计算机程序被处理器执行时实现上述消息处理方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。其中,所述的计算机可读存储介质,如只读存储器(Read-Only Memory,简称ROM)、随机存取存储器(Random Access Memory,简称RAM)、磁碟或者光盘等。The embodiment of the present invention also provides a computer-readable storage medium. A computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, each process of the above message processing method embodiment is realized, and the same technology can be achieved. Effect, in order to avoid repetition, will not repeat them here. Wherein, the computer-readable storage medium is, for example, a read-only memory (Read-Only Memory, ROM for short), a random access memory (Random Access Memory, RAM for short), a magnetic disk or an optical disk, and the like.

需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。It should be noted that, in this document, the term "comprising", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or apparatus comprising a set of elements includes not only those elements, It also includes other elements not expressly listed, or elements inherent in the process, method, article, or device. Without further limitations, an element defined by the phrase "comprising a ..." does not preclude the presence of additional identical elements in the process, method, article, or apparatus comprising that element.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本发明各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general-purpose hardware platform, and of course also by hardware, but in many cases the former is better implementation. Based on this understanding, the technical solution of the present invention can be embodied in the form of a software product in essence or the part that contributes to the prior art, and the computer software product is stored in a storage medium (such as ROM/RAM, disk, CD) contains several instructions to make a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute the methods described in various embodiments of the present invention.

上面结合附图对本发明的实施例进行了描述,但是本发明并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本发明的启示下,在不脱离本发明宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本发明的保护之内。Embodiments of the present invention have been described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementations, and the above-mentioned specific implementations are only illustrative, rather than restrictive, and those of ordinary skill in the art will Under the enlightenment of the present invention, without departing from the gist of the present invention and the protection scope of the claims, many forms can also be made, all of which belong to the protection of the present invention.

Claims (16)

1.一种消息处理方法,其特征在于,应用于第一生产者节点,所述第一生产者节点与至少两个消费者节点之间建立有通信连接,所述方法包括:1. A message processing method, characterized in that it is applied to a first producer node, and a communication connection is established between the first producer node and at least two consumer nodes, the method comprising: 向所述至少两个消费者节点中的至少一个消费者节点发送待消费消息;sending a message to be consumed to at least one of the at least two consumer nodes; 分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息,其中,每个所述反馈消息携带有对应消费者节点的压力相关信息,所述消费者节点的压力相关信息用于表征所述消费者节点的负载压力状况;Respectively receive a feedback message sent by each consumer node in 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 consumer The pressure related information of the node is used to characterize the load pressure condition of the consumer node; 根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡。Load balancing is performed according to the pressure-related information of some or all of the consumer nodes in the at least two consumer nodes. 2.根据权利要求1所述的方法,其特征在于,所述至少两个消费者节点中的每个消费者节点均与至少两个生产者节点之间建立有通信连接,所述第一生产者节点为所述至少两个生产者节点中的任意生产者节点;2. The method according to claim 1, wherein a communication connection is established between each consumer node in the at least two consumer nodes and at least two producer nodes, and the first producer node The producer node is any producer node in the at least two producer nodes; 所述分别接收所述至少一个消费者节点中的每个消费者节点针对所述待消费消息发送的反馈消息之后,所述方法还包括:After respectively receiving the feedback message sent by each consumer node in the at least one consumer node for the message to be consumed, the method further includes: 将所述至少一个消费者节点中每个消费者节点的压力相关信息存储于共享缓存,其中,所述共享缓存支持在所述至少两个生产者节点之间共享;storing pressure-related information for each of the at least one consumer node in a shared cache, wherein the shared cache supports sharing between the at least two producer nodes; 所述根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡,包括:The load balancing according to the pressure-related information of some or all of the consumer nodes in the at least two consumer nodes includes: 每隔第一预设时长从所述共享缓存获取所述至少两个消费者节点中每个消费者节点的压力相关信息;Acquiring pressure-related information of each of the at least two consumer nodes from the shared cache at intervals of a first preset duration; 根据所述至少两个消费者节点中每个消费者节点的压力相关信息进行负载均衡。Load balancing is performed according to the pressure-related information of each consumer node in the at least two consumer nodes. 3.根据权利要求1所述的方法,其特征在于,所述方法还包括:3. The method according to claim 1, wherein the method further comprises: 在第二预设时长内未向第一消费者节点发送待消费消息的情况下,接收所述第一消费者节点发送的所述第一消费者节点的压力相关信息,其中,所述第一消费者节点为所述至少两个消费者节点中的任意消费者节点。In the case that no message to be consumed is sent to the first consumer node within the second preset time period, receiving the pressure-related information of the first consumer node sent by the first consumer node, wherein the first The consumer node is any consumer node in the at least two consumer nodes. 4.根据权利要求1所述的方法,其特征在于,所述消费者节点的压力相关信息包括如下至少一项:所述消费者节点的压力指标值,压力评估值;4. The method according to claim 1, wherein the pressure-related information of the consumer node includes at least one of the following: a pressure index value of the consumer node, a pressure evaluation value; 其中,所述压力评估值根据所述消费者节点的压力指标值确定。Wherein, the pressure evaluation value is determined according to the pressure index value of the consumer node. 5.根据权利要求4所述的方法,其特征在于,所述压力指标值包括如下至少一种:磁盘占用率,CPU占用率,内存占用率,下游调用响应时间。5. The method according to claim 4, wherein the pressure indicator value includes at least one of the following: disk occupancy, CPU occupancy, memory occupancy, and downstream call response time. 6.根据权利要求1所述的方法,其特征在于,所述根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡,包括:6. The method according to claim 1, wherein the load balancing according to the pressure-related information of some or all of the consumer nodes in the at least two consumer nodes comprises: 根据所述至少两个消费者节点中每个消费者节点的压力相关信息和每个所述消费者节点对应的消息响应时间进行负载均衡,其中,所述消息响应时间为所述第一生产者节点发送待消费消息至所述第一生产者节点接收到针对所述待消费消息的反馈消息的时间。Perform load balancing according to the pressure-related information of each of 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 first producer The node sends the message to be consumed to the time when the first producer node receives a feedback message for the message to be consumed. 7.一种消息处理方法,其特征在于,应用于第一消费者节点,所述方法包括:7. A message processing method, characterized in that it is applied to the first consumer node, and the method comprises: 接收第一生产者节点发送的待消费消息;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 It is used to characterize the load pressure condition of the first consumer node. 8.根据权利要求7所述的方法,其特征在于,所述方法还包括:8. The method according to claim 7, further comprising: 在第二预设时长内未接收到所述第一生产者节点发送的待消费消息的情况下,向所述第一生产者节点发送所述第一消费者节点的压力相关信息;或者If the message to be consumed sent by the first producer node is not received within the second preset time period, sending pressure-related information of the first consumer node to the first producer node; or 在第二预设时长内未接收到至少两个生产者节点中任意生产者节点发送的待消费消息的情况下,向所述至少两个生产者节点中的生产者节点发送所述第一消费者节点的压力相关信息,其中,所述第一消费者节点与所述至少两个生产者节点之间建立有通信连接,所述至少两个生产者节点包括所述第一生产者节点。In the case that no message to be consumed sent by any producer node among the at least two producer nodes is received within the second preset time period, the first consumption message is sent to the producer node among the at least two producer nodes pressure-related information of a producer node, 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. 9.根据权利要求7所述的方法,其特征在于,所述消费者节点的压力相关信息包括如下至少一项:所述消费者节点的压力指标值,压力评估值;9. The method according to claim 7, wherein the pressure-related information of the consumer node includes at least one of the following: a pressure index value of the consumer node, a pressure evaluation value; 其中,所述压力评估值根据所述消费者节点的压力指标值确定。Wherein, the pressure evaluation value is determined according to the pressure index value of the consumer node. 10.根据权利要求9所述的方法,其特征在于,所述压力指标值包括如下至少一种:磁盘占用率,CPU占用率,内存占用率,下游调用响应时间。10. The method according to claim 9, wherein the pressure indicator value includes at least one of the following: disk usage, CPU usage, memory usage, and downstream call response time. 11.根据权利要求9所述的方法,其特征在于,所述压力评估值根据所述消费者节点的至少两种压力指标值和目标权重组计算得到,其中,所述目标权重组包括所述至少两种压力指标值中每种压力指标值的权重。11. The method according to claim 9, wherein the pressure assessment value is calculated according to at least two stress index values and a target weight group of the consumer node, wherein the target weight group includes the A weight for each of the at least two stress indicator values. 12.根据权利要求11所述的方法,其特征在于,所述目标权重组为目标计算周期对应的权重组,所述目标计算周期为N个计算周期中对应的方差值最小的计算周期,N为大于1的整数,所述N个计算周期分别对应N个不同的权重组,每个所述权重组包括所述至少两种压力指标值中每种压力指标值的权重;12. The method according to claim 11, wherein the target weight group is a weight group corresponding to a target calculation period, and the target calculation period is a calculation period corresponding to the smallest variance value among N calculation periods, N is an integer greater than 1, and the N calculation periods correspond to N different weight groups, each of which includes the weight of each pressure index value in the at least two pressure index values; 其中,所述N个计算周期中的第i个计算周期对应的方差值通过如下方式确定:Wherein, the variance value corresponding to the i-th calculation period in the N calculation periods is determined in the following manner: 在所述第i个计算周期内根据所述消费者节点的至少两种压力指标值和第i个权重组计算第i个压力评估值;i的取值范围为[1,N];In the i-th calculation period, calculate the i-th pressure evaluation value according to at least two pressure index values and the i-th weight group of the consumer node; the value range of i is [1, N]; 向所述第一生产者节点发送所述第i个压力评估值,以使所述第一生产者节点根据所述第i个压力评估值进行负载均衡;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; 统计在所述第i个计算周期内的M个时间单元中每个时间单元对应的请求响应数,M为大于1的整数;Count the number of request responses corresponding to each time unit in the M time units in the i-th calculation cycle, where M is an integer greater than 1; 分别计算所述M个时间单元中每个时间单元对应的请求响应数和所述第i个压力评估值的比值,得到M个比值;Calculate the ratio of the number of request responses corresponding to each time unit in the M time units and the i-th pressure evaluation value to obtain M ratios; 计算所述M个比值的方差值,得到所述第i个计算周期对应的方差值。Calculate the variance values of the M ratios to obtain the variance values corresponding to the i-th calculation period. 13.一种消息处理装置,其特征在于,应用于第一生产者节点,所述第一生产者节点与至少两个消费者节点之间建立有通信连接,所述装置包括:13. A message processing device, characterized in that it is applied to a first producer node, and a communication connection is established between the first producer node and at least two consumer nodes, and the device comprises: 第一发送模块,用于向所述至少两个消费者节点中的至少一个消费者节点发送待消费消息;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 in the at least one consumer node for the message to be consumed, wherein each of the feedback messages carries the pressure of the corresponding consumer node Related Information; 负载均衡模块,用于根据所述至少两个消费者节点中的部分或全部消费者节点的压力相关信息进行负载均衡。A load balancing module, configured to perform load balancing according to pressure-related information of some or all of the consumer nodes among the at least two consumer nodes. 14.一种消息处理装置,其特征在于,应用于第一消费者节点,所述装置包括:14. A message processing device, characterized in that it is applied to a first consumer node, said device comprising: 第一接收模块,用于接收第一生产者节点发送的待消费消息;The first receiving module is configured to receive the message to be consumed sent by the first producer node; 消息消费模块,用于对所述待消费消息进行消息消费;A message consumption module, configured to consume 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, where the feedback message carries pressure-related information of the first consumer node. 15.一种电子设备,其特征在于,包括处理器、存储器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述计算机程序被所述处理器执行时实现如权利要求1至6中任一项所述的消息处理方法的步骤,或者实现如权利要求7至12中任一项所述的消息处理方法的步骤。15. An electronic device, characterized by comprising a processor, a memory, and a computer program stored on the memory and operable on the processor, when the computer program is executed by the processor, the The steps of the message processing method described in any one of claims 1 to 6, or the steps of the message processing method described in any one of claims 7 to 12. 16.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至6中任一项所述的消息处理方法的步骤,或者实现如权利要求7至12中任一项所述的消息处理方法的步骤。16. A computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is realized. The steps of the message processing method, or the steps of implementing the message processing method according to any one of claims 7 to 12.
CN202210986802.9A 2022-08-17 2022-08-17 Message processing method, device and electronic device Active CN116132367B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210986802.9A CN116132367B (en) 2022-08-17 2022-08-17 Message processing method, device and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210986802.9A CN116132367B (en) 2022-08-17 2022-08-17 Message processing method, device and electronic device

Publications (2)

Publication Number Publication Date
CN116132367A true CN116132367A (en) 2023-05-16
CN116132367B CN116132367B (en) 2024-11-22

Family

ID=86301477

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210986802.9A Active CN116132367B (en) 2022-08-17 2022-08-17 Message processing method, device and electronic device

Country Status (1)

Country Link
CN (1) CN116132367B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130275402A1 (en) * 2012-04-17 2013-10-17 Oracle International Corporation Redistributing Computation Work Between Data Producers And Data Consumers
CN105430028A (en) * 2014-09-09 2016-03-23 阿里巴巴集团控股有限公司 Service calling method, service providing method, and node
CN105450784A (en) * 2016-01-20 2016-03-30 北京京东尚科信息技术有限公司 An apparatus and method for distributing consumption nodes to messages in an MQ
US20160103714A1 (en) * 2014-10-10 2016-04-14 Fujitsu Limited System, method of controlling a system including a load balancer and a plurality of apparatuses, and apparatus
CN105912412A (en) * 2016-03-31 2016-08-31 北京奇虎科技有限公司 Message distribution method, message distribution device and message distribution system
CN110062038A (en) * 2019-04-09 2019-07-26 网宿科技股份有限公司 A kind of data transmission scheduling method and system
CN113055480A (en) * 2021-03-17 2021-06-29 网宿科技股份有限公司 Scheduling method and device
CN113687928A (en) * 2021-08-03 2021-11-23 广州华多网络科技有限公司 Message scheduling control method and corresponding device, equipment and medium thereof

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130275402A1 (en) * 2012-04-17 2013-10-17 Oracle International Corporation Redistributing Computation Work Between Data Producers And Data Consumers
CN105430028A (en) * 2014-09-09 2016-03-23 阿里巴巴集团控股有限公司 Service calling method, service providing method, and node
US20160103714A1 (en) * 2014-10-10 2016-04-14 Fujitsu Limited System, method of controlling a system including a load balancer and a plurality of apparatuses, and apparatus
CN105450784A (en) * 2016-01-20 2016-03-30 北京京东尚科信息技术有限公司 An apparatus and method for distributing consumption nodes to messages in an MQ
CN105912412A (en) * 2016-03-31 2016-08-31 北京奇虎科技有限公司 Message distribution method, message distribution device and message distribution system
CN110062038A (en) * 2019-04-09 2019-07-26 网宿科技股份有限公司 A kind of data transmission scheduling method and system
CN113055480A (en) * 2021-03-17 2021-06-29 网宿科技股份有限公司 Scheduling method and device
CN113687928A (en) * 2021-08-03 2021-11-23 广州华多网络科技有限公司 Message scheduling control method and corresponding device, equipment and medium thereof

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
CHIN-FENG LAI;YING-XUN LAI: "An Adaptive Energy-Efficient Stream Decoding System for Cloud Multimedia Network on Multicore Architectures", IEEE SYSTEMS JOURNAL, vol. 8, no. 1, 3 October 2013 (2013-10-03) *
周聪: "基于改进的ActiveMQ的通信模型的设计与实现", 中国优秀硕士学位论文数据库, 16 August 2017 (2017-08-16) *

Also Published As

Publication number Publication date
CN116132367B (en) 2024-11-22

Similar Documents

Publication Publication Date Title
CN107590001B (en) Load balancing method and device, storage medium and electronic equipment
Lu et al. Join-idle-queue: A novel load balancing algorithm for dynamically scalable web services
CN103309946B (en) Multimedia file processing method, Apparatus and system
WO2021151312A1 (en) Method for determining inter-service dependency, and related apparatus
CN101764746B (en) Method and device for sending data
CN110300067A (en) Queue regulation method, device, equipment and computer readable storage medium
CN114356587B (en) Calculation power task cross-region scheduling method, system and equipment
CN113515545A (en) Data query method, device, system, electronic equipment and storage medium
CN102339233A (en) Cloud computing centralized management platform
CN109032511A (en) Data storage method, server and storage medium
CN113760640A (en) Monitoring log processing method, device, device and storage medium
CN114500546A (en) Communication message sending method, device and equipment based on load balancing cluster
CN113934525A (en) Hadoop cluster task scheduling method based on positive and negative feedback load scheduling algorithm
CN119254780A (en) Large model processing method, device, equipment and medium based on distributed cache
CN116132367A (en) A message processing method, device and electronic equipment
CN117827480A (en) A method and device for extending Kafka consumption mode
CN117729247A (en) Method, device and equipment for persistence of distributed data stream based on Flink
DeMara et al. Tiered algorithm for distributed process quiescence and termination detection
CN112965796B (en) Task scheduling system, method and device
CN115965411A (en) An event processing method, device and system applicable to welfare activities
CN115712524A (en) Data recovery method and device
CN115314500A (en) Dynamic load balancing method based on improved TOPSIS model
CN114363988A (en) Clustering method and device and electronic equipment
CN114237858A (en) Task scheduling method and system based on multi-cluster network
CN114398224A (en) A method and device for monitoring the running state of a Kafka cluster

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant