Asynchronous communication method and device, computer equipment and storage medium
By building a multi-level cluster in an asynchronous communication cluster and determining the node role based on processing performance parameters, the problem of high complexity of asynchronous communication is solved, and efficient message routing and system reliability are achieved.
Patent Information
- Application Number
- CN202411791321.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-12-06
AI Technical Summary
Under the microservice architecture, asynchronous communication has a high processing complexity, especially in scenarios where request results cannot be obtained synchronously, there are problems such as poor real-time performance, high resource consumption, and large impacts of network conditions.
By building a first-level cluster and a second-level cluster in an asynchronous communication cluster, the node roles of each level cluster are determined according to the processing performance parameters of each service node, multi-level distribution of service requests and reply messages is realized, and dependence on unified intermediate agents is reduced.
It reduces the processing complexity of asynchronous communication, improves message routing efficiency and system reliability, reduces the number of polling and obtaining reply requests, and improves the efficiency of asynchronous communication.
Smart Images

Figure CN119652977A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of asynchronous communication technology, and in particular to an asynchronous communication method, apparatus, computer equipment and storage medium. Background Art
[0002] With the development of software development technology, microservice architecture has become a standard event for modern software development due to its flexibility, scalability and fault tolerance. However, under the microservice architecture, the collaborative communication between services becomes more complicated, especially in asynchronous scenarios where the request results cannot be obtained synchronously. The caller needs to obtain the execution results through polling, callback and other methods, which has the disadvantages of poor real-time performance, high resource consumption and great influence by network conditions.
[0003] In traditional technology, message queue-based solutions are used to handle time-consuming tasks and implement event-driven architectures; event bus-based solutions are used to handle highly decoupled systems.
[0004] However, traditional asynchronous communication methods have the problem of high processing complexity. Summary of the invention
[0005] Based on this, it is necessary to provide an asynchronous communication method, apparatus, computer device and storage medium that can reduce the processing complexity of asynchronous communication in order to solve the above technical problems.
[0006] In a first aspect, the present application provides an asynchronous communication method, which is applied to any service node in an asynchronous communication cluster, and the method includes:
[0007] The target node in the asynchronous communication cluster constructs a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0008] The target node receives a service request sent by other service nodes in the asynchronous communication cluster, and sends a reply message corresponding to the service request to the other service node according to the service request.
[0009] In one embodiment, sending a reply message corresponding to the service request to the other service node according to the service request includes:
[0010] Determine a message delivery path according to an identifier in the service request; the identifier includes a first identifier of a primary cluster where the other service node is located and a second identifier of the other service node, or a second identifier of a primary cluster where the other service node is located and a third identifier of a secondary cluster where the other service node is located, and the second identifier of the other service node;
[0011] The reply message corresponding to the service request is delivered to the other service node according to the message delivery path.
[0012] In one of the embodiments, determining the message delivery path according to the identifier in the service request includes:
[0013] If the other service node is the first-level slave node, determining the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request;
[0014] If the other service node is the second-level slave node, the third identifier of the first-level cluster and the fourth identifier of the second-level cluster where the other service node is located, as well as the fifth identifier of the other service node are determined according to the identifier in the service request.
[0015] In one embodiment, the step of constructing a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster includes:
[0016] Determine a plurality of secondary master service nodes and a plurality of secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster, and construct a secondary cluster in the asynchronous communication cluster according to the secondary master service node and the secondary slave service node;
[0017] According to the processing performance parameters of each of the secondary main service nodes, a primary main service node and multiple primary slave service nodes in the asynchronous communication cluster are determined, and a primary cluster in the asynchronous communication cluster is constructed based on the primary main service node and the primary slave service node.
[0018] In one embodiment, the processing performance parameter includes a priority coefficient and a request response time of each historical processing request in each of the service nodes, and determining a plurality of secondary master service nodes and a plurality of secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameter of each service node in the asynchronous communication cluster includes:
[0019] Determining the waiting weight of each of the service nodes according to the priority coefficient of each historical processing request and the request response time in each of the service nodes;
[0020] Determining a forwarding weight of each of the service nodes according to the waiting weight of each of the service nodes;
[0021] The service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster is determined as the secondary master service node, and the service nodes other than the secondary master service node are determined as the secondary slave service nodes.
[0022] In one embodiment, determining the forwarding weight of each of the service nodes according to the waiting weight of each of the service nodes includes:
[0023] Determine, according to the preset grouping information, a forwarding service node corresponding to each of the service nodes;
[0024] The waiting weights of the forwarding service nodes corresponding to each of the service nodes are summed to determine the forwarding weight of each of the service nodes.
[0025] In one embodiment, determining the waiting weight of each service node according to the priority coefficient and request response time of each historical processing request in each service node includes:
[0026] Determining a weight identifier of each of the historical processing requests according to a request response time and a preset time range of each of the historical processing requests;
[0027] According to the weight identifier of each of the historical processing requests, a weighted sum is performed on the priority coefficients of each of the historical processing requests to determine the waiting weight of each of the service nodes.
[0028] In a second aspect, the present application further provides an asynchronous communication device, comprising:
[0029] A construction module, used to construct a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0030] The sending module is used to receive the service request sent by other service nodes in the asynchronous communication cluster, and send a reply message corresponding to the service request to the other service node according to the service request.
[0031] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0032] The target node in the asynchronous communication cluster constructs a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0033] The target node receives a service request sent by other service nodes in the asynchronous communication cluster, and sends a reply message corresponding to the service request to the other service node according to the service request.
[0034] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0035] The target node in the asynchronous communication cluster constructs a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0036] The target node receives a service request sent by other service nodes in the asynchronous communication cluster, and sends a reply message corresponding to the service request to the other service node according to the service request.
[0037] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0038] The target node in the asynchronous communication cluster constructs a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0039] The target node receives a service request sent by other service nodes in the asynchronous communication cluster, and sends a reply message corresponding to the service request to the other service node according to the service request.
[0040] The above-mentioned asynchronous communication method, device, computer equipment and storage medium, the target node in the asynchronous communication cluster builds a first-level cluster and a second-level cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the first-level cluster includes a first-level master node and a first-level slave node, and the second-level cluster includes a second-level master node and a second-level slave node; the target node receives the service request sent by other service nodes in the asynchronous communication cluster, and sends the reply message corresponding to the service request to other service nodes according to the service request. Through the cluster hierarchical service structure, the response message is distributed at multiple levels, and the dependence on the unified intermediate agent is removed. While improving the efficiency of message routing, the reliability of the system is greatly improved. After other service nodes initiate service requests, there is no need to repeatedly poll to obtain reply requests, which improves the efficiency of asynchronous communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 An application environment diagram of an asynchronous communication method in one embodiment;
[0043] Figure 2 A schematic diagram of a flow chart of an asynchronous communication method in one embodiment;
[0044] Figure 3 is a flow chart of an asynchronous communication method in another embodiment;
[0045] Figure 4 is a flow chart of an asynchronous communication method in another embodiment;
[0046] Figure 4A is a schematic diagram of an asynchronous communication cluster in one embodiment;
[0047] Figure 5 is a flow chart of an asynchronous communication method in another embodiment;
[0048] Figure 6 is a flow chart of an asynchronous communication method in another embodiment;
[0049] Figure 7 is a flow chart of an asynchronous communication method in another embodiment;
[0050] Figure 8 is a flow chart of an asynchronous communication method in another embodiment;
[0051] Fig. 9 is a flow chart of an asynchronous communication method in another embodiment;
[0052] Fig.10 is a structural block diagram of an asynchronous communication device in one embodiment;
[0053] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0055] The asynchronous communication method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the target service node 102 communicates with each service node 104 in the asynchronous communication cluster through the network. The processing performance parameters of each service node 104 are obtained, and the first-level cluster and the second-level cluster of the asynchronous communication cluster are constructed according to the processing performance parameters of each service node.
[0056] In one embodiment, Figure 2 As shown, an asynchronous communication method is provided, which is applied to Figure 1 The target service node in is used as an example to illustrate, including:
[0057] S201, the target node in the asynchronous communication cluster builds a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node.
[0058] In an embodiment of the present application, each service node generates a voting request based on its own processing performance parameters, and sends the voting request to the target service node. Optionally, each service node can read the processing performance parameters from a preset database; or, each service node can parse historical processing information to determine its own processing performance parameters. Further, the target service node parses each voting request to obtain the processing performance parameters of each service node, thereby constructing a primary cluster and a secondary cluster in the asynchronous communication cluster based on the processing performance parameters of each service node. Optionally, the asynchronous communication cluster includes multiple levels of clusters. In an embodiment of the present application, the asynchronous communication cluster includes at least a primary cluster and a secondary cluster. According to the processing requirements for the asynchronous communication cluster, the number of service nodes in the asynchronous communication cluster, etc., the asynchronous communication cluster can include a third-level cluster, a fourth-level cluster, etc.
[0059] Optionally, the target node can evaluate each service node according to the processing performance parameters of each server node to obtain an evaluation value of each service node, and can determine the service node with the highest evaluation value as a first-level master node, and determine the service node with an evaluation value within a preset range as a second-level master node, that is, a first-level slave node, and determine the service nodes other than the first-level master node and the second-level master node as second-level slave nodes.
[0060] Optionally, when a preset election requirement is met, a voting request sent by each service node in the asynchronous communication cluster is received, wherein the preset election condition may include: (1) the slave service node fails to receive a signal from the master service node within a preset timeout period; (2) ,in , Respectively represent the message waiting weights of the current service node and the main service node, is a constant, representing the node switching overhead coefficient.
[0061] S202, the target node receives a service request sent by other service nodes in the asynchronous communication cluster, and sends a reply message corresponding to the service request to the other service nodes according to the service request.
[0062] In an embodiment of the present application, after the target node receives a service request sent by other service nodes in the asynchronous communication cluster, it processes the service request. After completing the processing of the service request, it generates a reply message for the service request, and determines the initiating node that initiated the service request and the position of the initiating node in the asynchronous communication cluster based on the service request, thereby sending the reply message corresponding to the service request to the initiating node.
[0063] In the above asynchronous communication method, the target node in the asynchronous communication cluster builds a first-level cluster and a second-level cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the first-level cluster includes a first-level master node and a first-level slave node, and the second-level cluster includes a second-level master node and a second-level slave node; the target node receives the service request sent by other service nodes in the asynchronous communication cluster, and sends the reply message corresponding to the service request to other service nodes according to the service request. Through the cluster hierarchical service structure, the response message is distributed at multiple levels, and the dependence on the unified intermediate agent is removed. While improving the efficiency of message routing, the reliability of the system is greatly improved. After other service nodes initiate service requests, there is no need to repeatedly poll to obtain reply requests, which improves the efficiency of asynchronous communication.
[0064] In one embodiment, an implementation of the above S202 is provided, such as Figure 3 As shown, the above “sending a reply message corresponding to the service request to other service nodes according to the service request” includes:
[0065] S301, determining a message delivery path according to an identifier in a service request.
[0066] In an embodiment of the present application, the message delivery path can be directly determined based on the identifier in the service request; or, the path nodes in the delivery path can be determined based on the identifier in the service request, thereby determining the message delivery path based on the path nodes.
[0067] S302: Deliver a reply message corresponding to the service request to other service nodes according to the message delivery path.
[0068] In an embodiment of the present application, according to the message transmission path, the reply message corresponding to the service request is sent to the secondary master node corresponding to the target node, the secondary master node sends the reply message to the primary master node, and the master node transmits the reply message to other service nodes according to the message transmission path.
[0069] In the above application embodiment, the message transmission path is determined according to the service request, and then the reply message corresponding to the service request is transmitted to other service nodes according to the message transmission path, thereby improving the accuracy of message transmission.
[0070] In one embodiment, an implementation of the above S301 is provided, such as Figure 4 As shown, the above “determining the message delivery path according to the identifier in the service request” includes:
[0071] S401: If the other service node is a first-level slave node, determine the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request.
[0072] In an embodiment of the present application, if the other service node is a first-level slave node, since the second-level master node corresponding to the target node is a first-level master node or a first-level slave node of the first-level cluster, it is sufficient to determine the path from the second-level master node corresponding to the target node to the other service node, read the field of the target position in the identifier in the service request, and determine the first identifier of the other service node and the second identifier of the other service node.
[0073] S402: If the other service node is a secondary slave node, determine the third identifier of the primary cluster and the fourth identifier of the secondary cluster where the other service node is located, as well as the fifth identifier of the other service node according to the identifier in the service request.
[0074] In an embodiment of the present application, if the other service node is a secondary slave node, the path from the secondary master node corresponding to the target node to the secondary master node of the other service node, and the path from the secondary master node of the other service node to the other service node are determined, and the field of the target position in the identifier in the service request is read to determine the third identifier of the primary cluster where the other service node is located and the fourth identifier of the secondary cluster where it is located, as well as the fifth identifier of the other service node.
[0075] Optionally, a schematic diagram of the first cluster and the second cluster is as follows Figure 4AAs shown in the figure, the first-level master service node is responsible for consuming the response message queue and routing the message to the first-level slave service node; the second-level master service node is the same as the first-level slave service node, responsible for receiving and forwarding messages from the first-level master service node. The first-level slave service node and the second-level slave service node are both execution nodes. After receiving the request, the execution node starts asynchronous processing and synchronously returns the request success message. After the asynchronous task processing is completed, the execution result combined with the request unique identifier is pushed to the public response message queue. After the first-level master service node consumes the message, it first determines whether it is the current second-level cluster message. If so, it is forwarded within the second-level cluster, otherwise it is forwarded to the corresponding second-level cluster according to the request identifier.
[0076] In the embodiment of the present application, the asynchronous communication process of the asynchronous communication cluster may include:
[0077] (1) When the asynchronous communication cluster is started, the three service nodes of the same service name are regarded as a secondary cluster. First, an internal election is initiated to confirm the master service node. The master service node is initially set as the slave service node of the primary cluster by default. The primary cluster initiates an election to confirm the master service node of the primary cluster. In particular, during the first election period, if only one service node is started in the cluster, the service node automatically becomes the master service node until it receives a voting request from a service node with a higher election value;
[0078] (2) After completing the initialization of the network, the main service node starts to consume and forward the response message;
[0079] (3) After the networking is completed, service node 1 of microservice A becomes a slave service node and initiates an HTTP request in the business operation. The request generates a unique identifier for this request based on service identifier A and service node identifier 1 and is sent to the recipient in the form of a request header.
[0080] (4) After receiving the request, receiver B performs preprocessing operations and starts asynchronous task execution based on the request identifier, and then returns a successful request to inform the requester of asynchronous waiting. After receiving the response, service node 1 registers the current request to the listening queue and waits for the main service node to push the message result.
[0081] (5) After the asynchronous task is completed, microservice B combines the execution result with the request unique identifier and sends it to the asynchronous task response message queue, thus ending the request processing.
[0082] (6) After the primary cluster master service node consumes the response message, it pushes the message to the primary cluster slave service node A according to service identifier A. The primary cluster slave service node A is also the primary service node of the secondary cluster. At this time, the message is pushed to service node 1 according to node identifier 1.
[0083] (7) After receiving the response message, service node 1 ends the waiting state of the current request and removes the request identifier from the listening queue, completing the entire life cycle of this asynchronous request.
[0084] Optionally, within the secondary cluster, by identifying the status of the slave service node, the exception message can be processed. For example, if microservice B2, as a slave service node, is unexpectedly terminated during task execution, and microservice B1, as the master service node, discovers the exception in the heartbeat detection, the master service node can push the execution exception response to the exception interrupt request identifier held by microservice B2, thereby reducing the invalid waiting of the requester. For very large-scale systems, by adjusting the cluster hierarchy, the service cluster is partitioned for a second time according to specific rules, and the election process is repeated to control the number of messages forwarded by a single master service node. For scenarios with moderate service scale and a large number of messages that exceed the load range of a single primary cluster master service node, a multi-primary cluster master service node mode is adopted, consuming the response queue at the same time and exchanging messages with each other.
[0085] In the above application embodiment, the path from the target node to the initiating node is determined according to the unique identifier in the service request, so that the reply message of the service request is returned to the initiating node.
[0086] In one embodiment, an implementation of the above S201 is provided, such as Figure 5 As shown, the above “building a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster” includes:
[0087] S501, determine multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster, and construct a secondary cluster in the asynchronous communication cluster based on the secondary master service nodes and the secondary slave service nodes.
[0088] In an embodiment of the present application, an asynchronous communication cluster includes multiple service nodes, and the multiple service nodes in the asynchronous communication cluster are divided into multiple service node groups according to preset grouping information. Further, the target service node obtains the processing performance parameters of each service node in the asynchronous communication cluster. For each service node group, the performance of each service node is sorted according to the processing performance parameters of each service node in the service node group, and the service node with the best performance is determined as the secondary master server in the service node group. The other service nodes in the service node group except the secondary master service node are determined as secondary slave service nodes, so that the service node group is constructed into a secondary cluster. Optionally, the processing performance parameters can be hardware parameters of the service nodes, so that the hardware parameters are evaluated to obtain the evaluation values of each service node, and further, the performance of each service node is sorted according to the evaluation values of each service node.
[0089] Optionally, the service nodes in the service node group may be ranked according to their processing performance parameters, and each service node may be voted for, for example, voting in favor of the service node ranked first and voting against service nodes other than the service node ranked first.
[0090] S502, determine a primary master service node and multiple primary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each secondary master service node, and construct a primary cluster in the asynchronous communication cluster according to the primary master service node and the primary slave service node.
[0091] In the embodiment of the present application, multiple secondary main service nodes are formed into a primary cluster, and a primary main service node and a primary slave service node are determined from multiple secondary main services, and the performance of each secondary main service node is sorted according to the processing performance parameters of each secondary main service node in the primary cluster, and the secondary main service node with the best performance is determined as the primary main server in the primary cluster, and the other service nodes in the primary cluster except the primary main service node are determined as the primary slave service nodes. It should be noted that the method of constructing a primary cluster is the same as the method of constructing a secondary cluster.
[0092] In the above-mentioned application embodiment, asynchronous communication is centrally divided into a primary cluster and a secondary cluster, multi-level distribution is implemented for response messages, and the dependence on a unified intermediate agent is removed, thereby reducing the complexity of asynchronous processing. While improving the message routing efficiency, the reliability of the system is greatly improved. The primary master service node, the primary slave service node, the secondary master service node, and the secondary slave service node are determined according to the processing performance parameters of each service node, thereby improving the accuracy of the primary cluster and the secondary cluster.
[0093] In one embodiment, an implementation of the above S501 is provided, where the processing performance parameters include the priority coefficient and request response time of each historical processing request in each service node, such as Figure 6 As shown, the above “determining multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster” includes:
[0094] S601, determining the waiting weight of each service node according to the priority coefficient and request response time of each historical processing request in each service node.
[0095] As an optional implementation, for each service node, the waiting weight range of the service node can be determined based on the priority coefficient of each historical processing request in the service node. Further, the waiting weight of the service node can be determined from the waiting weight range based on the request response time of each historical processing request in the service node.
[0096] As another optional implementation, the waiting weight of each service node may be determined according to the priority coefficient and request response time of each historical processing request in each service node and a preset first relationship.
[0097] S602: Determine the forwarding weight of each service node according to the waiting weight of each service node.
[0098] In the embodiment of the present application, for each service node, the forwarding weight of each service node is determined according to the waiting weights of all service nodes in each service node group except the service node.
[0099] Optionally, a correspondence between waiting weight and forwarding weight can be established in advance, so as to determine the forwarding weight of each service node according to the waiting weight of each service node; or, the forwarding weight of each service node can be determined according to the waiting weight of each service node and a preset second relationship.
[0100] S603: Determine the service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster as a secondary master service node, and determine the service nodes other than the secondary master service node as secondary slave service nodes.
[0101] In the embodiment of the present application, the service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster is determined as the secondary master service node, and the service nodes other than the secondary master service node are determined as secondary slave service nodes. Optionally, the service node with the lowest forwarding weight can be removed from the secondary cluster.
[0102] In the above application embodiment, the waiting weight of the service node is determined based on the priority coefficient and the request response time, which improves the credibility of the waiting weight. Further, the forwarding weight is determined based on the waiting weight, which improves the credibility of the forwarding weight, thereby improving the accuracy of the secondary master service node and the secondary slave service node in the secondary cluster.
[0103] In one embodiment, an implementation of the above S602 is provided, such as Figure 7 As shown, the above “determining the forwarding weight of each service node according to the waiting weight of each service node” includes:
[0104] S701: Determine a forwarding service node corresponding to each service node according to preset grouping information.
[0105] S702, summing up the waiting weights of the forwarding service nodes corresponding to each service node to determine the forwarding weight of each service node.
[0106] In the embodiment of the present application, for each service node, other service nodes in the same group as the service node are determined according to the preset grouping information, and the other service nodes in the same group as the service node are determined as the forwarding service nodes corresponding to the service node. Further, the forwarding weight of the service node is determined according to the waiting weight of the forwarding service node. The message forwarding weight of a service node is shown in Formula 1:
[0107] (Formula 1)
[0108] in, is the waiting weight of the nth service node, and the message forwarding weight represents the number of slave nodes. The forwarding cost coefficient required to route all messages of the current cluster to other nodes. It should be noted that the greater the message forwarding weight, the smaller the election value of the current node.
[0109] In the above application embodiment, for each service node, the forwarding weight of the service node is determined according to the waiting weights of other service nodes, thereby improving the accuracy of the forwarding weight.
[0110] In one embodiment, an implementation of the above S301 is provided, such as Figure 8 As shown, the above “determining the waiting weight of each service node according to the priority coefficient of each historical processing request and the request response time in each service node” includes:
[0111] S801, determining a weight identifier of each historical processing request according to the request response time of each historical processing request and a preset time range.
[0112] In the embodiment of the present application, for each service node, the weight identifier of the jth historical request in the service node can be expressed as , the request response time of the jth historical request is ,when , ,when hour, , , Indicates The minimum and maximum expected response times for each request type.
[0113] S802: Perform weighted summation on the priority coefficients of each historical processing request according to the weight identifier of each historical processing request to determine the waiting weight of each service node.
[0114] In the embodiment of the present application, The waiting weight of each service node is:
[0115] (Formula 2)
[0116] in, Indicates The priority factor of the request.
[0117] In an embodiment of the present application, the waiting weight of each service node is determined based on the processing information of each historical request in each service node, that is, the waiting weight of each service node is determined by actual historical processing data, thereby improving the credibility and accuracy of the waiting weight.
[0118] In one embodiment, Fig. 9 As shown, a complete asynchronous communication method is provided, including:
[0119] S1, determining a weight identifier of each historical processing request according to the request response time of each historical processing request and a preset time range.
[0120] S2, according to the weight identifier of each historical processing request, weighted sum of the priority coefficients of each historical processing request is performed to determine the waiting weight of each service node.
[0121] S3, determining the forwarding service node corresponding to each service node according to the preset grouping information.
[0122] S4, summing up the waiting weights of the forwarding service nodes corresponding to each service node to determine the forwarding weight of each service node.
[0123] S5, determining the service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster as the secondary master service node, and determining the service nodes other than the secondary master service node as the secondary slave service nodes.
[0124] S6, constructing a secondary cluster in the asynchronous communication cluster according to the secondary master service node and the secondary slave service node.
[0125] S7, according to the processing performance parameters of each secondary main service node, determine the primary main service node and multiple primary slave service nodes in the asynchronous communication cluster, and construct a primary cluster in the asynchronous communication cluster based on the primary main service node and the primary slave service node.
[0126] S8, if the other service node is a first-level slave node, determine the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request; if the other service node is a second-level slave node, determine the third identifier of the first-level cluster where the other service node is located and the fourth identifier of the second-level cluster where the other service node is located, as well as the fifth identifier of the other service node according to the identifier in the service request.
[0127] S9, delivering the reply message corresponding to the service request to other service nodes according to the message delivery path.
[0128] In the above asynchronous communication method, the target node in the asynchronous communication cluster builds a first-level cluster and a second-level cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the first-level cluster includes a first-level master node and a first-level slave node, and the second-level cluster includes a second-level master node and a second-level slave node; the target node receives the service request sent by other service nodes in the asynchronous communication cluster, and sends the reply message corresponding to the service request to other service nodes according to the service request. Through the cluster hierarchical service structure, the response message is distributed at multiple levels, and the dependence on the unified intermediate agent is removed. While improving the efficiency of message routing, the reliability of the system is greatly improved. After other service nodes initiate service requests, there is no need to repeatedly poll to obtain reply requests, which improves the efficiency of asynchronous communication.
[0129] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0130] Based on the same inventive concept, the embodiment of the present application also provides an asynchronous communication device for implementing the asynchronous communication method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more asynchronous communication device embodiments provided below can refer to the limitations on the asynchronous communication method above, and will not be repeated here.
[0131] In one embodiment, Fig.10 As shown, an asynchronous communication device is provided, comprising: a building module 10 and a sending module 11, wherein:
[0132] The construction module 10 is used to construct a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0133] The sending module 11 is used to receive service requests sent by other service nodes in the asynchronous communication cluster, and send reply messages corresponding to the service requests to other service nodes according to the service requests.
[0134] In one embodiment, the sending module 11 includes: a first determining unit and a transmitting unit, wherein:
[0135] The first determining unit is used to determine a message delivery path according to an identifier in the service request.
[0136] The delivery unit is used to deliver the reply message corresponding to the service request to other service nodes according to the message delivery path.
[0137] In one embodiment, the above-mentioned transmission unit is specifically used to determine the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request if the other service node is a first-level slave node; if the other service node is a second-level slave node, determine the third identifier of the first-level cluster where the other service node is located and the fourth identifier of the second-level cluster where the other service node is located, as well as the fifth identifier of the other service node according to the identifier in the service request.
[0138] In one embodiment, the construction module 10 includes: a second determination unit and a third determination unit, wherein:
[0139] The second determination unit is used to determine multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster, and construct a secondary cluster in the asynchronous communication cluster based on the secondary master service nodes and the secondary slave service nodes.
[0140] The third determination unit is used to determine the first-level main service node and multiple first-level slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each second-level main service node, and construct a first-level cluster in the asynchronous communication cluster based on the first-level main service node and the first-level slave service node.
[0141] In one embodiment, the above-mentioned second determination unit is specifically used to determine the waiting weight of each service node based on the priority coefficient and request response time of each historical processing request in each service node; determine the forwarding weight of each service node based on the waiting weight of each service node; determine the service node with the highest forwarding weight in each group of service nodes in the asynchronous communication cluster as the secondary master service node, and determine the service nodes other than the secondary master service node as the secondary slave service nodes.
[0142] In one embodiment, the second determining unit is specifically configured to determine the forwarding service node corresponding to each service node according to preset grouping information; and to sum the waiting weights of the forwarding service nodes corresponding to each service node to determine the forwarding weight of each service node.
[0143] In one embodiment, the above-mentioned second determination unit is specifically used to determine the weight identifier of each historical processing request based on the request response time and the preset time range of each historical processing request; based on the weight identifier of each historical processing request, the priority coefficient of each historical processing request is weighted and summed to determine the waiting weight of each service node.
[0144] Each module in the above asynchronous communication device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0145] In an exemplary embodiment, a computer device is provided. The computer device may be a service node, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store asynchronous communication data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an asynchronous communication method is implemented.
[0146] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0147] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0148] The target node in the asynchronous communication cluster builds a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0149] The target node receives the service request sent by other service nodes in the asynchronous communication cluster, and sends the reply message corresponding to the service request to other service nodes according to the service request.
[0150] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0151] Determine the message delivery path according to the identifier in the service request;
[0152] The reply message corresponding to the service request is delivered to other service nodes according to the message delivery path.
[0153] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0154] If the other service node is a first-level slave node, determine the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request;
[0155] If the other service node is a secondary slave node, the third identifier of the primary cluster and the fourth identifier of the secondary cluster where the other service node is located, as well as the fifth identifier of the other service node are determined according to the identifier in the service request.
[0156] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0157] According to the processing performance parameters of each service node in the asynchronous communication cluster, multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster are determined, and a secondary cluster in the asynchronous communication cluster is constructed based on the secondary master service nodes and the secondary slave service nodes;
[0158] According to the processing performance parameters of each secondary master service node, a primary master service node and multiple primary slave service nodes in the asynchronous communication cluster are determined, and a primary cluster in the asynchronous communication cluster is constructed based on the primary master service node and the primary slave service node.
[0159] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0160] Determine the waiting weight of each service node based on the priority coefficient and request response time of each historical processing request in each service node;
[0161] Determine the forwarding weight of each service node according to the waiting weight of each service node;
[0162] The service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster is determined as the secondary master service node, and the service nodes other than the secondary master service node are determined as the secondary slave service nodes.
[0163] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0164] Determine the forwarding service node corresponding to each service node according to the preset grouping information;
[0165] The waiting weights of the forwarding service nodes corresponding to each service node are summed to determine the forwarding weight of each service node.
[0166] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0167] Determine a weight identifier for each historical processing request according to the request response time and a preset time range of each historical processing request;
[0168] According to the weight identifier of each historical processing request, the priority coefficients of each historical processing request are weighted and summed to determine the waiting weight of each service node.
[0169] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0170] The target node in the asynchronous communication cluster builds a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0171] The target node receives the service request sent by other service nodes in the asynchronous communication cluster, and sends the reply message corresponding to the service request to other service nodes according to the service request.
[0172] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0173] Determine the message delivery path according to the identifier in the service request;
[0174] The reply message corresponding to the service request is delivered to other service nodes according to the message delivery path.
[0175] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0176] If the other service node is a first-level slave node, determine the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request;
[0177] If the other service node is a secondary slave node, the third identifier of the primary cluster and the fourth identifier of the secondary cluster where the other service node is located, as well as the fifth identifier of the other service node are determined according to the identifier in the service request.
[0178] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0179] According to the processing performance parameters of each service node in the asynchronous communication cluster, multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster are determined, and a secondary cluster in the asynchronous communication cluster is constructed based on the secondary master service nodes and the secondary slave service nodes;
[0180] According to the processing performance parameters of each secondary master service node, a primary master service node and multiple primary slave service nodes in the asynchronous communication cluster are determined, and a primary cluster in the asynchronous communication cluster is constructed based on the primary master service node and the primary slave service node.
[0181] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0182] Determine the waiting weight of each service node based on the priority coefficient and request response time of each historical processing request in each service node;
[0183] Determine the forwarding weight of each service node according to the waiting weight of each service node;
[0184] The service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster is determined as the secondary master service node, and the service nodes other than the secondary master service node are determined as the secondary slave service nodes.
[0185] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0186] Determine the forwarding service node corresponding to each service node according to the preset grouping information;
[0187] The waiting weights of the forwarding service nodes corresponding to each service node are summed to determine the forwarding weight of each service node.
[0188] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0189] Determine a weight identifier for each historical processing request according to the request response time and a preset time range of each historical processing request;
[0190] According to the weight identifier of each historical processing request, the priority coefficients of each historical processing request are weighted and summed to determine the waiting weight of each service node.
[0191] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0192] The target node in the asynchronous communication cluster builds a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node;
[0193] The target node receives the service request sent by other service nodes in the asynchronous communication cluster, and sends the reply message corresponding to the service request to other service nodes according to the service request.
[0194] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0195] Determine the message delivery path according to the identifier in the service request;
[0196] The reply message corresponding to the service request is delivered to other service nodes according to the message delivery path.
[0197] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0198] If the other service node is a first-level slave node, determine the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request;
[0199] If the other service node is a secondary slave node, the third identifier of the primary cluster and the fourth identifier of the secondary cluster where the other service node is located, as well as the fifth identifier of the other service node are determined according to the identifier in the service request.
[0200] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0201] According to the processing performance parameters of each service node in the asynchronous communication cluster, multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster are determined, and a secondary cluster in the asynchronous communication cluster is constructed based on the secondary master service nodes and the secondary slave service nodes;
[0202] According to the processing performance parameters of each secondary master service node, a primary master service node and multiple primary slave service nodes in the asynchronous communication cluster are determined, and a primary cluster in the asynchronous communication cluster is constructed based on the primary master service node and the primary slave service node.
[0203] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0204] Determine the waiting weight of each service node based on the priority coefficient and request response time of each historical processing request in each service node;
[0205] Determine the forwarding weight of each service node according to the waiting weight of each service node;
[0206] The service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster is determined as the secondary master service node, and the service nodes other than the secondary master service node are determined as the secondary slave service nodes.
[0207] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0208] Determine the forwarding service node corresponding to each service node according to the preset grouping information;
[0209] The waiting weights of the forwarding service nodes corresponding to each service node are summed to determine the forwarding weight of each service node.
[0210] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0211] Determine a weight identifier for each historical processing request according to the request response time and a preset time range of each historical processing request;
[0212] According to the weight identifier of each historical processing request, the priority coefficients of each historical processing request are weighted and summed to determine the waiting weight of each service node.
[0213] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0214] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0215] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. An asynchronous communication method, characterized in that: Applied to any service node in an asynchronous communication cluster, the method comprises: The target node in the asynchronous communication cluster constructs a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node; The target node receives a service request sent by other service nodes in the asynchronous communication cluster, and sends a reply message corresponding to the service request to the other service node according to the service request.
2. The method according to claim 1, characterized in that: The sending a reply message corresponding to the service request to the other service node according to the service request includes: Determine a message delivery path according to the identifier in the service request; The reply message corresponding to the service request is delivered to the other service node according to the message delivery path.
3. The method according to claim 2, characterized in that The determining the message delivery path according to the identifier in the service request includes: If the other service node is the first-level slave node, determining the first identifier of the first-level cluster where the other service node is located and the second identifier of the other service node according to the identifier in the service request; If the other service node is the second-level slave node, the third identifier of the first-level cluster and the fourth identifier of the second-level cluster where the other service node is located, as well as the fifth identifier of the other service node are determined according to the identifier in the service request.
4. The method according to claim 1, characterized in that The step of constructing a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster includes: Determine a plurality of secondary master service nodes and a plurality of secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster, and construct a secondary cluster in the asynchronous communication cluster according to the secondary master service node and the secondary slave service node; According to the processing performance parameters of each of the secondary main service nodes, a primary main service node and multiple primary slave service nodes in the asynchronous communication cluster are determined, and a primary cluster in the asynchronous communication cluster is constructed based on the primary main service node and the primary slave service node.
5. The method according to claim 4, characterized in that The processing performance parameters include the priority coefficient and request response time of each historical processing request in each of the service nodes, and the determining of multiple secondary master service nodes and multiple secondary slave service nodes in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster includes: Determining the waiting weight of each of the service nodes according to the priority coefficient of each historical processing request and the request response time in each of the service nodes; Determining a forwarding weight of each of the service nodes according to the waiting weight of each of the service nodes; The service node with the highest forwarding weight in each group of service nodes of the asynchronous communication cluster is determined as the secondary master service node, and the service nodes other than the secondary master service node are determined as the secondary slave service nodes.
6. The method according to claim 5, characterized in that Determining the forwarding weight of each of the service nodes according to the waiting weight of each of the service nodes includes: Determine, according to the preset grouping information, a forwarding service node corresponding to each of the service nodes; The waiting weights of the forwarding service nodes corresponding to each of the service nodes are summed to determine the forwarding weight of each of the service nodes.
7. The method according to claim 5, characterized in that Determining the waiting weight of each service node according to the priority coefficient of each historical processing request and the request response time in each service node includes: Determining a weight identifier of each of the historical processing requests according to a request response time and a preset time range of each of the historical processing requests; According to the weight identifier of each of the historical processing requests, a weighted sum is performed on the priority coefficients of each of the historical processing requests to determine the waiting weight of each of the service nodes.
8. An asynchronous communication device, characterized in that: The device comprises: A construction module, used to construct a primary cluster and a secondary cluster in the asynchronous communication cluster according to the processing performance parameters of each service node in the asynchronous communication cluster; the primary cluster includes a primary master node and a primary slave node, and the secondary cluster includes a secondary master node and a secondary slave node; The sending module is used to receive the service request sent by other service nodes in the asynchronous communication cluster, and send a reply message corresponding to the service request to the other service node according to the service request.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Cluster node communication method and system
CN107124469A
Cross-cluster data request processing method and device and storage medium
CN113746887A
Cluster deployment method and device and computer storage medium
CN116800613A
Cluster deployment method and device, storage medium and electronic equipment
CN117950807A
Fragmented cluster backup recovery method, system and device, computer equipment and medium
CN118152185A