Trunking communication method and device based on multicast network
By broadcasting the center node information in a multicast network, determining the master control node and establishing an exclusive message monitoring relationship, the problem of low processing performance and stability of traditional cluster communication solutions in high concurrency scenarios is solved, and efficient cluster control is achieved and message processing.
Patent Information
- Application Number
- CN202411782600.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-02-18
AI Technical Summary
Traditional cluster communication solutions cannot meet the message processing requirements in high concurrency scenarios, resulting in low cluster processing performance and stability.
By broadcasting the node information of N central nodes in the target communication cluster in a multicast network, the master control node is determined, and based on this, the exclusive message listening relationship between the master control node and the service node is established, the control message is generated and distributed, and the response is processed. information.
It realizes effective cluster control and message processing under high concurrency, improves the performance and stability of the cluster, and solves the problem of insufficient message processing capabilities in traditional solutions.
Smart Images

Figure CN119485812A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a cluster communication method and device based on a multicast network. Background Art
[0002] In the current air transport industry, the international freight rate calculation system plays a vital role. It needs to handle complex flight information, route combinations, fare rules and real-time market changes around the world. In order to cope with massive data and high concurrent requests, existing systems usually adopt a distributed cluster architecture to distribute computing tasks to multiple server nodes to improve processing capabilities and system stability. However, the complexity and diversity of this architecture brings many challenges, especially in terms of inter-node communication, role management, master-slave switching, fault recovery, etc., requiring an efficient and stable cluster communication mechanism to coordinate the activities of each node to ensure high availability and data consistency of the system.
[0003] Multicast network technology is widely used in service discovery and node election because it can efficiently broadcast information within a local area network. However, it is difficult to achieve point-to-point communication and more advanced cluster management functions by relying solely on multicast networks. Although TCP communication can provide stable point-to-point connections, in large-scale clusters, each node needs to establish connections with multiple other nodes, which will lead to a large consumption of network resources and increased management complexity. In summary, traditional cluster communication solutions cannot meet the needs of large-scale message processing in high-concurrency scenarios, resulting in low cluster processing performance, stability, and accuracy.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present invention provide a cluster communication method and device based on a multicast network, so as to at least solve the technical problem in the related art that the traditional cluster solution cannot meet the message processing requirements in high concurrency scenarios, resulting in low cluster processing performance and stability.
[0006] According to one aspect of an embodiment of the present invention, a cluster communication method based on a multicast network is provided, comprising: broadcasting node information of N central nodes in a target communication cluster to the multicast network, and determining a master control node among the N central nodes through the broadcast information in the multicast network, wherein N is a positive integer; establishing an exclusive message listening relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network; generating a control message based on the master control node and a specified service process, and sending the control message to the service node based on the exclusive message listening relationship; receiving the control message through the service node, executing the service process indicated by the control message, and generating a response message to the control message based on the execution result, and returning the response message to the master control node.
[0007] Furthermore, the step of broadcasting the node information of N central nodes in the target communication cluster to the multicast network includes: for each of the central nodes, starting the communication service component in the central node, wherein the communication service component includes: a multicast listening component and a TCP listening component; controlling all the central nodes to load a first configuration file, wherein the first configuration file includes at least: the multicast port address of the multicast network, and the TCP listening port address applied to the TCP listening component; integrating the node role information of the central node and the TCP listening port address to generate the node information of the central node; and sending the node information to the multicast port address through the multicast listening component.
[0008] Furthermore, the step of determining the master control node among the N central nodes through the broadcast information in the multicast network includes: obtaining all the broadcast information in the multicast network to obtain the node role information of the N central nodes; when the node role information indicates that there is a unique central node with a primary role, determining the central node as the master control node, wherein the primary role refers to the node responsible for communication services under normal circumstances; when the node role information indicates that there are R central nodes that are all primary roles, obtaining the role declaration timestamps of the R central nodes, and determining that the central node corresponding to the role declaration timestamp closest to the current time point is the master control node, wherein R is a positive integer greater than or equal to 2 and less than or equal to N; when the node role information indicates that N central nodes are all backup roles, determining one master control node among the N central nodes through a node election mechanism, and updating the node role information of the master control node to the primary role, and updating the role declaration timestamp of the master control node based on the current time point, wherein the backup role refers to the node responsible for taking over the communication service of the primary role when an abnormality occurs in the primary role.
[0009] Furthermore, before establishing an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster, it also includes: for each of the service nodes, starting the multicast monitoring component and the TCP client component in the service node; controlling all the service nodes to load a second configuration file, wherein the second configuration file includes at least: the multicast port address of the multicast network, and the TCP client address applied to the TCP client component.
[0010] Furthermore, based on the node information of the master control node in the multicast network, the step of establishing an exclusive message listening relationship between the master control node and each service node in the target communication cluster includes: for each service node, obtaining the TCP listening port address indicated by the node information of the master control node through the multicast listening component and the multicast port address; based on the TCP listening port address and the TCP client address, establishing the exclusive message listening relationship between the TCP listening component in the master control node and the TCP client component in the service node.
[0011] Furthermore, the communication service component of the master control node also includes: a node registrar, which, after establishing an exclusive message monitoring relationship between the master control node and each business node in the target communication cluster, also includes: for the master control node, receiving heartbeat information transmitted by each of the business nodes through the exclusive message monitoring relationship, wherein the heartbeat information is the node information of the business node sent periodically according to a specified period; updating the node registration information of the business node in the node registrar according to the heartbeat information and the heartbeat time point; for each node registration information in the node registrar, calculating the time interval between the current time point and the most recent heartbeat time point in the node registration information, and when the time interval is greater than a preset time interval, deleting the business node corresponding to the node registration information in the node registrar.
[0012] Furthermore, before generating a control message based on the main control node and the specified business process, it also includes: determining the business steps that each of the business nodes is responsible for executing in the specified business process, and controlling the main control node to transmit the message processing function corresponding to the business step to the business node based on the exclusive message listening relationship.
[0013] Furthermore, the steps of receiving the control message through the business node and executing the business process indicated by the control message include: determining the processing time limit requirement of the control message, wherein the processing time limit requirement includes: real-time processing and asynchronous processing; for each of the business nodes, determining the function type of all the message processing functions in the business node, wherein the function type includes: real-time processing function and asynchronous processing function; if the function type of the message processing function does not match the processing time limit requirement of the control message, discarding the control message; otherwise, calling the message processing function to process the control message to obtain the execution result of the business process indicated by the control message.
[0014] Furthermore, the step of calling the message processing function to process the control message to obtain the execution result of the business process indicated by the control message includes: when the processing time limit requirement of the control message is real-time processing, calling the real-time processing function to process the control message to obtain the execution result; when the processing time limit requirement of the control message is asynchronous processing, obtaining the asynchronous processing time point, and adding the control message to the message queue of the business node based on the asynchronous processing time point; when reaching the asynchronous processing time point, controlling the message queue to call the asynchronous processing function, and processing the control message based on the asynchronous processing function to obtain the execution result.
[0015] According to another aspect of an embodiment of the present invention, a cluster communication device based on a multicast network is also provided, including: a determination unit, used to broadcast the node information of N central nodes in the target communication cluster to the multicast network, and determine the master control node among the N central nodes through the broadcast information in the multicast network, wherein N is a positive integer; an establishment unit, used to establish an exclusive message listening relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network; a sending unit, used to generate a control message based on the master control node and a specified service process, and send the control message to the service node based on the exclusive message listening relationship; an execution unit, used to receive the control message through the service node, execute the service process indicated by the control message, and generate a response message to the control message based on the execution result, and return the response message to the master control node.
[0016] Further, the determination unit includes: a first startup module, used to start the communication service component in the central node for each of the central nodes, wherein the communication service component includes: a multicast listening component and a TCP listening component; a first control module, used to control all the central nodes to load a first configuration file, wherein the first configuration file includes at least: the multicast port address of the multicast network, and the TCP listening port address applied to the TCP listening component; a generation module, used to integrate the node role information of the central node and the TCP listening port address to generate the node information of the central node; a sending module, used to send the node information to the multicast port address through the multicast listening component.
[0017] Furthermore, the determination unit also includes: a first acquisition module, which is used to acquire all broadcast information in the multicast network and obtain the node role information of the N central nodes; a first determination module, which is used to determine the central node as the master control node when the node role information indicates that there is a unique central node that plays the master role, wherein the master role refers to the node that is responsible for communication services under normal circumstances; a second determination module, which is used to acquire the role declaration timestamps of the R central nodes when the node role information indicates that there are R central nodes that are all master roles, and determine that the central node corresponding to the role declaration timestamp closest to the current time point is the master control node, wherein R is a positive integer greater than or equal to 2 and less than or equal to N; a third determination module, which is used to determine one of the N central nodes through a node election mechanism when the node role information indicates that the N central nodes are all backup roles, and update the node role information of the master control node to the master role, and update the role declaration timestamp of the master control node based on the current time point, wherein the backup role refers to the node that is responsible for taking over the communication service of the primary role when an abnormality occurs in the primary role.
[0018] Furthermore, the cluster communication device based on the multicast network also includes: a second startup module, used to start the multicast listening component and the TCP client component in the business node for each of the business nodes; a second control module, used to control all the business nodes to load a second configuration file, wherein the second configuration file includes at least: the multicast port address of the multicast network, and the TCP client address applied to the TCP client component.
[0019] Furthermore, the establishment unit includes: a second acquisition module, used to obtain the TCP listening port address indicated by the node information of the master control node for each of the business nodes through the multicast listening component and the multicast port address; an establishment module, used to establish the exclusive message listening relationship between the TCP listening component in the master control node and the TCP client component in the business node based on the TCP listening port address and the TCP client address.
[0020] Furthermore, the communication service component of the master control node also includes: a node registrar.
[0021] Furthermore, the cluster communication device based on the multicast network also includes: a receiving module, which is used to receive the heartbeat information transmitted by each of the business nodes for the master control node through the exclusive message monitoring relationship, wherein the heartbeat information is the node information of the business node sent regularly according to a specified period; an updating module, which is used to update the node registration information of the business node in the node registrar according to the heartbeat information and the heartbeat time point; and a deleting module, which is used to calculate the time interval between the current time point and the most recent heartbeat time point in the node registration information for each node registration information in the node registrar, and delete the business node corresponding to the node registration information in the node registrar when the time interval is greater than a preset time interval.
[0022] Furthermore, the multicast network-based cluster communication device also includes: a third control module, used to determine the business steps that each of the business nodes is responsible for executing in the specified business process, and control the main control node to transmit the message processing function corresponding to the business step to the business node based on the exclusive message monitoring relationship.
[0023] Furthermore, the execution unit includes: a fourth determination module, used to determine the processing time limit requirement of the control message, wherein the processing time limit requirement includes: real-time processing and asynchronous processing; a fifth determination module, used to determine the function type of all the message processing functions in the business node for each of the business nodes, wherein the function types include: real-time processing function and asynchronous processing function; a discarding module, used to discard the control message if the function type of the message processing function does not match the processing time limit requirement of the control message; and a calling module, used to call the message processing function to process the control message if the function type of the message processing function matches the processing time limit requirement of the control message, so as to obtain the execution result of the business process indicated by the control message.
[0024] Furthermore, the calling module includes: a first calling sub-module, which is used to call the real-time processing function to process the control message when the processing time limit requirement of the control message is real-time processing, and obtain the execution result; an adding sub-module, which is used to obtain the asynchronous processing time point when the processing time limit requirement of the control message is asynchronous processing, and add the control message to the message queue of the business node based on the asynchronous processing time point; a second calling sub-module, which is used to control the message queue to call the asynchronous processing function when the asynchronous processing time point is reached, and process the control message based on the asynchronous processing function to obtain the execution result.
[0025] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned multicast network-based cluster communication methods.
[0026] According to another aspect of an embodiment of the present invention, an electronic device is also provided, comprising one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any one of the above-mentioned cluster communication methods based on a multicast network.
[0027] In the present invention, a cluster communication method based on a multicast network is proposed, which first broadcasts the node information of N central nodes in the target communication cluster to the multicast network, and determines the master node among the N central nodes through the broadcast information in the multicast network, wherein N is a positive integer, and then establishes an exclusive message monitoring relationship between the master node and each service node in the target communication cluster based on the node information of the master node in the multicast network, and then generates a control message based on the master node and the specified service process, and sends the control message to the service node based on the exclusive message monitoring relationship, and finally receives the control message through the service node, executes the service process indicated by the control message, and generates a response message to the control message based on the execution result, and returns the response message to the master node.
[0028] The present invention realizes efficient information transmission through a multicast network, carries the node information of N central nodes to reduce the communication burden of single point to single point, and enables each node in the cluster to receive relevant information to quickly and synchronously determine the master node, ensuring that the cluster control center is effectively selected to centrally manage and process communication tasks under high concurrency. The present invention also establishes an exclusive message monitoring relationship between the master node and each service node based on the master node information in the multicast network, which helps to ensure that each service node can stably receive and process messages from the master node, reduce the problem of message loss or duplication, and improve the reliability of message processing. In addition, the master node generates a control message for each service node and sends it through an exclusive message monitoring relationship, which can more accurately meet the needs of each service node and improve communication efficiency. Finally, the service node executes the service process and returns a response message. This response feedback mechanism enables the master node to obtain service feedback in a timely manner, thereby improving the responsiveness and adaptability of the communication cluster system.
[0029] The above method comprehensively optimizes the message processing mechanism of the cluster by utilizing the multicast network to broadcast information, determine the master control node, establish an exclusive listening relationship, generate and distribute control messages, and process response messages, effectively improving the performance and stability of the cluster in high concurrency scenarios, overcoming the problem of insufficient message processing capabilities in traditional cluster solutions, ensuring the efficient and stable operation of the system, and not only improving the efficiency and reliability of message transmission, but also enhancing the adaptability of the system in complex environments, thereby solving the technical problem in related technologies that traditional cluster solutions cannot meet the message processing requirements in high concurrency scenarios, resulting in low cluster processing performance and stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0031] Figure 1 is a flow chart of an optional cluster communication method based on a multicast network according to an embodiment of the present invention;
[0032] Figure 2 is a communication connection logic diagram of an optional distributed cluster according to an embodiment of the present invention;
[0033] Figure 3 is a schematic diagram of an optional data structure of a message according to an embodiment of the present invention;
[0034] Figure 4 is a schematic diagram of an optional cluster communication device based on a multicast network according to an embodiment of the present invention;
[0035] Figure 5 The present invention is a hardware structure block diagram of an electronic device (or mobile device) for a cluster communication method based on a multicast network according to an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0037] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0038] To facilitate those skilled in the art to understand the present invention, some terms or nouns involved in the embodiments of the present invention are explained below:
[0039] TCP, Transmission Control Protocol, the communication connection established through TCP is a communication method that realizes a one-to-one stable communication connection through point-to-point messages. In the embodiment of the present invention, one node starts listening to an address, and another node can connect to this address, supporting stable information exchange between the two parties.
[0040] The following embodiments of the present invention can be applied to various systems / applications / devices that require high-concurrency message transmission and rapid response to network traffic, and can realize efficient transmission of high-concurrency messages based on multicast networks and TCP monitoring mechanisms. The present invention broadcasts the information of N central nodes to the multicast network, determines the master control node among the N central nodes through the broadcast information, establishes an exclusive message monitoring relationship between the master control node and each service node, the master control node generates a control message and sends it to the service node through the exclusive monitoring relationship, and after the service node executes the process indicated by the control message, it generates a response message and returns it to the master control node.
[0041] The present invention is described in detail below in conjunction with various embodiments.
[0042] Embodiment 1
[0043] According to an embodiment of the present invention, an embodiment of a cluster communication method based on a multicast network is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a group of computer executable fingers controlled, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0044] The implementation subject of the embodiment of the present invention may be a cluster communication management system, wherein the target communication cluster to which the system is connected includes a central node and a service node.
[0045] The central node is responsible for coordinating the communication tasks of each business node to ensure that the system tasks are carried out according to the predetermined process. Often, a central node is designated as the main control node responsible for command and dispatch, and the remaining central nodes serve as backup nodes for the main control node, taking over its command and dispatch rights when the main control node cannot work normally. The central node is also responsible for distributing control messages and task data to each business node and processing the returned responses. It is also responsible for monitoring the health status of all nodes in the cluster to ensure the healthy operation of the system. It is also responsible for regular fault detection and fault handling, and performing failover or recovery operations. In general, the central node is responsible for the overall management, coordination, control, message distribution and monitoring of the system to ensure the normal operation and optimized performance of the system.
[0046] The business node is responsible for receiving messages from the master node through a dedicated message listening relationship, executing the specific business logic indicated in the control message from the master node, including data processing, calculation, operation, etc. After completing the task, it generates a response message and returns it to the master node, waiting for the next decision instruction. Some business nodes may be responsible for local data storage and management, processing data operations related to local business, and providing data required by the system for use by the master node or other nodes. In general, business nodes focus on executing specific business tasks, processing data and generating responses, and are directly involved in business processes and data operations.
[0047] As an implementation entity, the cluster communication management system usually includes the following components:
[0048] The multicast monitoring component is deployed in each central node and each business node for service discovery and identity election. In the identity election process, the multicast monitoring component broadcasts the node information of each central node through the multicast network, and each central node jointly determines the master node based on the broadcast information.
[0049] The TCP listening component is deployed in each central node and works with the multicast listening component to ensure stable message transmission. After determining the master control node, the TCP listening component uses the TCP protocol to work with the TCP client component deployed in each service node to establish a TCP communication connection between each service node and the master control node.
[0050] The TCP client component is deployed in each service node and is used to cooperate with the TCP listening component in the central node and actively connect to the listening port of the TCP listening component through the TCP protocol to establish a TCP communication connection between the service node and the master control node;
[0051] The message queue is deployed in each service node and is used to store received control messages. The message queue is connected to the TCP listening component to receive and temporarily store messages received through the TCP communication connection.
[0052] The node driver component is connected to the message queue to obtain messages in the message queue and execute corresponding processing logic according to the message type;
[0053] The node registrar is used to monitor the status of each node in real time. The node registrar is connected to the multicast listening component and the TCP listening component respectively to receive and update the node status information. When it is detected that a node has timed out and has not been updated, the node information is automatically cleaned up to achieve dynamic management of the node status.
[0054] Furthermore, the cluster communication management system can also implement a dynamic decision-making mechanism of the central control node based on the above components, wherein the central control node (i.e. the above-mentioned master control node) generates a control message based on the communication information summarized by the node registrar, and sends the control message to the business node through the TCP listening component. After the business node completes the corresponding communication task, it returns a response message to the central control node.
[0055] Furthermore, each functional component of the above cluster communication management system can execute each process step of the cluster communication method based on a multicast network proposed in the embodiment of the present invention.
[0056] Figure 1 is a flow chart of an optional cluster communication method based on a multicast network according to an embodiment of the present invention, such as Figure 1 As shown, the method comprises the following steps:
[0057] Step S101, broadcasting node information of N central nodes in a target communication cluster to a multicast network, and determining a master control node among the N central nodes through the broadcast information in the multicast network, wherein N is a positive integer.
[0058] Specifically, the target communication cluster contains N central nodes and M service nodes, where M is a positive integer. One central node is determined as the master node among the N central nodes, and the remaining N-1 nodes automatically become the backup nodes of the master node. When the master node is abnormal and cannot assume the command and dispatch function, the backup node takes over its command and dispatch rights.
[0059] Another thing that needs to be explained is that the node information broadcast to the central node of the multicast network includes at least: the port address of the TCP listening component deployed in the central node, so that each business node can obtain the port address from the multicast network and use its own deployed TCP client component to connect to the port address to establish a dedicated message listening relationship.
[0060] Furthermore, the node information of the central node broadcast to the multicast network also includes: the node role information of each central node, wherein the node role information includes at least: role declaration information and role declaration timestamp. The role declaration information refers to the type of role played by the central node in a specified time period (especially in the most recent communication task), specifically including its status as a primary role or a backup role, which is used to identify the functional role assumed by the central node in past tasks, thereby providing the necessary context in the system management and coordination process; the role declaration timestamp refers to the specific time point when the role declaration information is recorded or registered in the node registrar after the central node is determined to be a specific role type (such as a primary role or a backup role), which is used to identify the exact moment of the role declaration, and provides a time basis for the system's role management and historical tracking.
[0061] In order to achieve efficient broadcasting and management of cluster node information, optionally, the step of broadcasting the node information of N central nodes in the target communication cluster to the multicast network in step S101 includes: for each central node, starting the communication service component in the central node, wherein the communication service component includes: a multicast listening component and a TCP listening component; controlling all central nodes to load a first configuration file, wherein the first configuration file includes at least: a multicast port address of the multicast network, and a TCP listening port address applied to the TCP listening component; integrating the node role information and the TCP listening port address of the central node to generate the node information of the central node; and sending the node information to the multicast port address through the multicast listening component.
[0062] It should be noted that multicast is a network communication method that allows the sender to transmit information to multiple receivers at the same time. The multicast port is the network port used for multicast communication. The multicast listening component is responsible for receiving messages / data in the multicast network through the multicast port. The TCP listening component is responsible for receiving and processing connection requests and data from other nodes at the TCP level. The TCP listening port is the port used by the central node to receive TCP connection requests.
[0063] Through the above steps, the central node broadcasts its role information and TCP port address in the network, so that other nodes can understand the role of each central node and how to communicate on the network, and the multicast communication method allows information to be sent to multiple receivers at the same time, reducing the network burden and achieving efficient communication. All central nodes can achieve unified configuration and cluster coordination by receiving these broadcast information, improving the overall consistency and stability of the system. The above process makes it easier and more efficient to add new nodes to the communication cluster or adjust the roles of existing nodes, which is conducive to the expansion and dynamic adjustment of the system.
[0064] In order to ensure the correct election of the master control node and the stability of the system, it is necessary to use the broadcast information, timestamp and election mechanism in combination. Optionally, the step of determining the master control node among N central nodes through the broadcast information in the multicast network in step S101 includes: obtaining all broadcast information in the multicast network to obtain the node role information of the N central nodes; when the node role information indicates that there is a unique central node with a master role, determining the central node as the master control node, wherein the master role refers to the node responsible for communication services under normal circumstances; when the node role information indicates that there are R central nodes that are all master roles, Obtain the role declaration timestamps of R central nodes, and determine the central node corresponding to the role declaration timestamp closest to the current time point as the master node, where R is a positive integer greater than or equal to 2 and less than or equal to N; when the node role information indicates that the N central nodes are all backup roles, determine a master node among the N central nodes through a node election mechanism, and update the node role information of the master node to the primary role, and update the role declaration timestamp of the master node based on the current time point, where the backup role refers to the node that is responsible for taking over the communication service of the primary role in the event of an abnormality in the primary role.
[0065] It should be noted that broadcast information refers to all messages sent to the multicast network, including the role information, node status, and communication address of all central nodes. The only central node means that there is only one central node identified as the master role among all the current node role information. This node is responsible for managing all communication services under normal circumstances, so it is selected as the master node.
[0066] In addition, the backup role is used to take over the functions of the active role when the active role fails or the active role is temporarily missing in the cluster. The node election mechanism is an algorithm or protocol used to select a central node as the master node from all backup nodes. Common election mechanisms include leader election algorithms such as Paxos or Raft.
[0067] The above steps can ensure that the system selects the most suitable master node in the case of multiple master roles by analyzing the broadcast information and comparing the timestamps, avoiding frequent changes or conflicts in the master node and ensuring the stability of the master node election. Specifically, when there are multiple master roles, the node that has recently declared the role can be selected by comparing the timestamps, which can reduce the system instability caused by inconsistent role information. When all nodes are backup roles, the election mechanism is used to ensure a reliable master node, and the system can smoothly transition when the master node fails.
[0068] The embodiment of the present invention can dynamically select and update the master node according to real-time node role information, ensuring the high availability and continuity of the system under different node role configurations, while the combination of role declaration timestamp and election mechanism improves the robustness of the system in the face of node failures or role changes.
[0069] Step S102: establishing an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network.
[0070] Specifically, the exclusive message monitoring relationship is a one-to-one TCP communication connection established based on the TCP protocol, which is used to ensure the reliability and sequentiality of communication data transmission.
[0071] Alternatively, the same effect can be achieved by allocating a unique identifier to each service node in a multicast network, thereby ensuring that communication data can be accurately delivered to a target service node during transmission.
[0072] Optionally, before executing step S102, it also includes: for each business node, starting the multicast listening component and the TCP client component in the business node; controlling all business nodes to load the second configuration file, wherein the second configuration file includes at least: the multicast port address of the multicast network, and the TCP client address applied to the TCP client component.
[0073] It should be noted that the multicast listening component deployed in the business node is used to receive control messages from the multicast network, and to obtain the TCP listening port address of the TCP listening component sent by the master control node in the multicast network. The TCP client component initiates a connection to the TCP listening component in the master control node based on the TCP listening port address and the TCP protocol to provide a reliable data transmission channel.
[0074] In the embodiment of the present invention, by establishing a dedicated message listening relationship in the multicast network and the TCP network, efficient communication and data transmission can be achieved, wherein the multicast network can effectively broadcast messages to multiple nodes, and the TCP protocol provides a reliable data transmission guarantee. In addition, the master control node can achieve effective control of the target communication cluster by managing and coordinating multicast and TCP communications, thereby improving the overall network stability and data transmission reliability.
[0075] Optionally, step S102 includes: for each business node, obtaining the TCP listening port address indicated by the node information of the master control node through the multicast listening component and the multicast port address; based on the TCP listening port address and the TCP client address, establishing an exclusive message listening relationship between the TCP listening component in the master control node and the TCP client component in the business node.
[0076] In order to improve the system self-healing capability and health management efficiency, a node registrar and a heartbeat mechanism may be introduced. Optionally, the communication service component of the master control node also includes: a node registrar. After executing step S102, it also includes: for the master control node, receiving heartbeat information transmitted by each business node through an exclusive message monitoring relationship, wherein the heartbeat information is the node information of the business node sent regularly according to a specified period; updating the node registration information of the business node in the node registrar according to the heartbeat information and the heartbeat time point; for each node registration information in the node registrar, calculating the time interval between the current time point and the most recent heartbeat time point in the node registration information, and deleting the business node corresponding to the node registration information in the node registrar when the time interval is greater than the preset time interval.
[0077] It should be noted that the node registrar is used to track and update the status information of each business node. The master node receives heartbeat information through a dedicated message listening relationship, which includes the status and timestamp of the business node. The heartbeat mechanism can help the master node detect the health status of the business node and update the registration information based on the heartbeat information.
[0078] During the heartbeat information processing, the node registrar calculates the time interval between the current time and the most recent heartbeat time point. If the time interval exceeds the preset value, the registration information of the node is deleted. This ensures that the system automatically clears business nodes that are no longer active. It should be noted that a reasonable preset time interval should be set to avoid accidental deletion or omission of node information.
[0079] Step S103: Generate a control message based on the master control node and the specified business process, and send the control message to the business node based on the exclusive message monitoring relationship.
[0080] Specifically, the master control node generates a control message according to a specified business process. The control message is a message that instructs a business node to perform a specific operation or task.
[0081] It should be noted that the content of the control message depends on the specific requirements of the business process, including but not limited to instructions, data or configuration parameters, and the process of generating the control message needs to ensure the correctness and integrity of the message so that the business node can process it correctly.
[0082] The master control node sends the control message to the business node through the previously established exclusive message monitoring relationship. The exclusive message monitoring relationship ensures that the control message can be accurately and timely delivered to the target business node. The establishment of an exclusive message monitoring relationship is the basis for ensuring the reliability of message delivery. The system also needs to deal with network delays, data packet loss and other issues to maintain communication stability.
[0083] The embodiment of the present invention can realize automation and optimization of business processes by generating control messages through the main control node and transmitting them to the business nodes. Each business node performs specific operations according to the control messages, thereby making the entire business process more efficient and consistent.
[0084] Optionally, before executing step S103 to generate a control message, the process further includes: determining the business steps that each business node is responsible for executing in a specified business process, and controlling the main control node to transmit a message processing function corresponding to the business step to the business node based on a dedicated message monitoring relationship.
[0085] It should be noted that the allocation of business steps may be based on factors such as node capabilities and load balancing strategies. Message processing functions usually include business logic codes, which define the operations that the node should perform after receiving the control message. Therefore, the transmission of message processing functions may involve the transmission and dynamic loading of codes. It is necessary to ensure the security and integrity of the transmission process to prevent code tampering or transmission errors.
[0086] The embodiment of the present invention makes task allocation clearer and more orderly by clarifying the business steps and corresponding message processing functions that each business node is responsible for, which helps to coordinate the work of each business node and avoid duplicate or omitted task execution. The main control node dynamically generates and transmits control messages according to the business process and can adapt to changes in the business process in real time. The dynamic transmission of the message processing function allows the business node to update its processing logic as needed during operation, thereby improving the flexibility and adaptability of the system.
[0087] Step S104: receiving the control message through the service node, executing the service process indicated by the control message, generating a response message to the control message based on the execution result, and returning the response message to the main control node.
[0088] Optionally, the response message may contain detailed information about the execution result, which may include success or failure status, processing result data, etc., for further processing or decision-making by the master control node.
[0089] In order to meet the real-time or asynchronous communication time limit requirements, optionally, step S104 includes: determining the processing time limit requirements of the control message, wherein the processing time limit requirements include: real-time processing and asynchronous processing; for each business node, determining the function type of all message processing functions in the business node, wherein the function types include: real-time processing function and asynchronous processing function; if the function type of the message processing function does not match the processing time limit requirements of the control message, discarding the control message; otherwise, calling the message processing function to process the control message to obtain the execution result of the business process indicated by the control message.
[0090] It should be noted that control messages can have time limit requirements for real-time processing or asynchronous processing. Real-time processing requires the business node to respond immediately, while asynchronous processing allows the business node to process within a certain period of time. The time limit requirement affects the urgency and method of message processing. Real-time processing usually requires a low-latency response, while asynchronous processing allows the business node to process later if resources permit.
[0091] Corresponding to the time limit requirements of control messages, the message processing function in each service node can include a real-time processing function or an asynchronous processing function, where the real-time processing function is used to meet the requirements of real-time processing, while the asynchronous processing function is suitable for asynchronous processing. The matching of function types ensures that the message processing meets the time limit requirements of the control message. If the processing function type does not match, the control message needs to be discarded to avoid waste of system resources, delayed processing or erroneous processing.
[0092] In the embodiment of the present invention, the business node can accurately execute tasks and return responses according to the requirements of the control message, thereby improving the feedback accuracy and reliability of the system. By matching the time limit requirements of the message processing function and the control message, it ensures that the business process can be completed within the specified time to meet the real-time or asynchronous processing requirements. Unmatched control messages are discarded, avoiding resource waste and unnecessary processing, and optimizing the use of system resources. In summary, the system can flexibly respond to different processing time limit requirements and function types, enhancing the adaptability and processing efficiency of the business nodes.
[0093] Optionally, the step of calling a message processing function to process the control message to obtain the execution result of the business process indicated by the control message includes: when the processing time limit requirement of the control message is real-time processing, calling the real-time processing function to process the control message to obtain the execution result; when the processing time limit requirement of the control message is asynchronous processing, obtaining the asynchronous processing time point, and adding the control message to the message queue of the business node based on the asynchronous processing time point; when the asynchronous processing time point is reached, the control message queue calls the asynchronous processing function, and processes the control message based on the asynchronous processing function to obtain the execution result.
[0094] It should be noted that when a control message requires real-time processing, the task needs to be completed within a specified time. Usually, low latency and high response speed are required to ensure timely feedback. The system directly calls the real-time processing function for processing. For control messages that require asynchronous processing, the asynchronous processing time point can be determined by the system policy, such as a fixed time interval or dynamic adjustment according to the system load. The system can determine an asynchronous processing time point by itself, that is, the specific time to process the message.
[0095] In the case of asynchronous processing, the control message is added to the message queue of the business node, waiting for the arrival of the asynchronous processing time point. The message queue is used to temporarily store messages to ensure the sequential processing and load balancing of messages. The management strategy of the processing queue needs to be implemented to avoid excessive backlog.
[0096] When the asynchronous processing time point arrives, the system takes the message from the message queue and calls the asynchronous processing function. The asynchronous processing function usually has higher fault tolerance and lower real-time requirements when processing messages, and can handle more complex or computationally intensive tasks.
[0097] In the embodiment of the present invention, through the use of asynchronous processing time points and message queues, the system can efficiently schedule and manage message processing, avoiding excessive load of real-time processing. The use of message queues balances processing tasks during peak loads and improves the stability and scalability of the system.
[0098] Through the above steps S101 to S104, the node information of the N central nodes in the target communication cluster can be broadcast to the multicast network first, and the master node can be determined among the N central nodes through the broadcast information in the multicast network, where N is a positive integer, and then based on the node information of the master node in the multicast network, an exclusive message listening relationship is established between the master node and each business node in the target communication cluster, and then a control message is generated based on the master node and the specified business process, and the control message is sent to the business node based on the exclusive message listening relationship, and finally the control message is received by the business node, the business process indicated by the control message is executed, and a response message to the control message is generated based on the execution result, and the response message is returned to the master node.
[0099] In the embodiment of the present invention, efficient information transmission is achieved through a multicast network, and the node information of N central nodes is carried to reduce the point-to-point communication burden, and each node in the cluster receives relevant information to quickly and synchronously determine the master node, ensuring that the cluster control center is effectively selected to centrally manage and process communication tasks under high concurrency conditions. The present invention also establishes an exclusive message monitoring relationship between the master node and each service node based on the master node information in the multicast network, which helps to ensure that each service node can stably receive and process messages from the master node, reduce the problem of message loss or duplication, and improve the reliability of message processing. In addition, the master node generates a control message for each service node and sends it through an exclusive message monitoring relationship, which can more accurately meet the needs of each service node and improve communication efficiency. Finally, the service node executes the service process and returns a response message. This response feedback mechanism enables the master node to obtain service feedback in a timely manner, thereby improving the responsiveness and adaptability of the communication cluster system.
[0100] The above method comprehensively optimizes the message processing mechanism of the cluster by utilizing the multicast network to broadcast information, determine the master control node, establish an exclusive listening relationship, generate and distribute control messages, and process response messages, effectively improving the performance and stability of the cluster in high concurrency scenarios, overcoming the problem of insufficient message processing capabilities in traditional cluster solutions, ensuring the efficient and stable operation of the system, and not only improving the efficiency and reliability of message transmission, but also enhancing the adaptability of the system in complex environments, thereby solving the technical problem in related technologies that traditional cluster solutions cannot meet the message processing requirements in high concurrency scenarios, resulting in low cluster processing performance and stability.
[0101] The present invention is described below in conjunction with another specific implementation manner.
[0102] The implementation method of the present invention first provides a specific implementation scenario, namely, cluster management supporting international freight rate calculation, and proposes a cluster communication method based on a multicast network for this scenario, so that each node in the cluster can jointly complete complex functions such as source data preprocessing, memory database construction, memory database distribution, computing service startup, and load balancing node switching services. The overall process control of the method mainly depends on the cluster communication program. It can be said that the distributed cluster is composed of upper-level business logic + underlying basic communication.
[0103] Optionally, the physical basis of the cluster can usually use a set of servers located in the same local area network and use a multicast network for communication. If the same network segment wants to be divided into multiple clusters, it needs to be divided into multiple VLANs (Virtual Local Area Network) to ensure that even if the same multicast port is used, there will be no message interference.
[0104] Furthermore, the underlying basic communication components of the distributed cluster include the following:
[0105] 1. MulticastServer (multicast listening component), supports binding and listening to a group of multicast port addresses, and supports sending and receiving.
[0106] 2. TCPServer (TCP listening component), supports binding and listening to a set of TCP port addresses, and supports sending and receiving.
[0107] 3. TCPClient (TCP client component), supports connecting to TCPServer and supports sending and receiving. The relationship between TCPServer and TCPClient is one-to-many, in which TCPClient actively connects to the listening port of TCPServer.
[0108] 4. Message: A specially defined message structure, including a message header (message type, timestamp, etc.), a message body (specific message content), and a response message type (the response message type can also be empty, indicating that no reply is required upon receipt). The message definition will be registered in the MessageRegistry.
[0109] 5. MessageRegistry supports the registration of messages, including message and response message types.
[0110] 6. MessageHandler (message processor), a class that processes messages, contains one or more processing functions named "cmd_{message type}". The above three communication components can add multiple message processors, thus having the ability to process multiple messages. After receiving a message, the communication component will check whether it has a pre-stored message processing function corresponding to the message time limit. If it exists, it will be called, otherwise the message will be discarded.
[0111] 7. NodeRegistry (node registrar), collects the node information of each node (an extended message, in addition to the content of the regular Message, its message content contains the node type and other node business information, etc.), and completes the node registration. It also has a timeout cleanup function. When the node information is received, it registers / updates the node information. If the current time has timed out from the timestamp in the node information, the node is cleaned up (it can realize automatic master selection for some functions that require master-slave configuration. For example, if the master node of a business node is down, after the node registrar of the central node times out, it is considered that the business node lacks a master node, and the master node can be re-selected according to the selection rules, and a command is sent to switch it from the backup machine to the host).
[0112] Figure 2 is an optional communication connection logic diagram of a distributed cluster according to an embodiment of the present invention, such as Figure 2 As shown, the cluster contains N central nodes and M business nodes ( Figure 2 Taking N=2 and M=3 as an example, it includes a main central node and a backup central node, as well as business nodes A, B, and C. Each central node is deployed with: a multicast listening component, a TCP listening component, a TCP client component, and a node driver component, and each business node is only deployed with: a multicast listening component, a TCP client component, and a node driver component.
[0113] like Figure 2 As shown, a message queue is pre-established in each central node and each business node for temporarily storing business messages that require asynchronous processing. The node driver component is used to obtain messages from the message queue and execute tasks according to the asynchronous processing time point; and the multicast listening components in the nodes must actively connect to the same set of multicast addresses for uniformly obtaining broadcast messages in the multicast network; in addition, it is also necessary to establish a one-to-one TCP communication connection through the TCP listening component in the main central node and the TCP client component in the business node according to the TCP protocol to obtain point-to-point messages.
[0114] Figure 3 is a schematic diagram of an optional message data structure according to an embodiment of the present invention, such as Figure 3 As shown in the figure, the structure of the message is roughly divided into: message header and message body. The message header includes: magic number (starting with a special number, used for message verification), version (message version, also used for message verification), message type (message type, which can be used to deserialize into a message instance) and time stamp (timestamp, used to identify the message time, which can be used to calculate network delay). The message body is used to record the specific content of the message, generally in json format. Different fields correspond to different message types and can be used to deserialize into different objects.
[0115] It should be noted that a message is a data structure that exists in the form of an object in a program. It can be serialized into binary data and sent over the network, and can also be deserialized back into an object. It is the information carrier for cluster interaction.
[0116] Based on the above underlying basic communication components, the target communication cluster is established. The workflow is as follows:
[0117] S1, control each service node and the central node to start, and load the configuration file, wherein the configuration file at least contains information such as the multicast port address and the TCP listening port.
[0118] S2, each central node publishes a "service discovery message" in a regular cycle through a multicast listening component, which includes: the listening address and local information of its own TCP listening component, and at least the node role declaration information (master or backup).
[0119] S3, each central node obtains the "service discovery message" of other central nodes through the multicast monitoring component, and selects the master node according to the election algorithm, and the remaining nodes are set as backup nodes.
[0120] S4, each business node obtains the "service discovery message" of all central nodes through the multicast monitoring component, finds the message of the master node from the service discovery message, connects to the monitoring address of the TCP monitoring component of the "master node" in this message, and uses its own TCP client component to connect to this address.
[0121] S5, the TCP listening component of the master control node accepts the connection request of the TCP client component of each business node and establishes a stable TCP connection.
[0122] S6, each central node sends node information to the master control node in a regular cycle.
[0123] S7, the master node receives the node information and completes the node registration / information update.
[0124] S8, the master control node summarizes the cluster status according to the information of each node, generates a control message according to the specified business process, and sends it to each business node through the TCP listening component.
[0125] S9, the TCP client component of each service node receives the control message and searches whether it has a corresponding message processing function pre-stored in itself. If so, the function is called; otherwise, the message is discarded.
[0126] It should be noted that there are generally two types of message processing functions, real-time and asynchronous. Real-time refers to direct execution of logic, which is suitable for non-blocking logic, while asynchronous needs to be saved in the message queue, waiting for the node driver component to take the message out of the message queue and then call the asynchronous function for processing.
[0127] S10, each service node calls a (real-time / asynchronous) message processing function and replies a response message (if necessary) to the master control node through a TCP client component.
[0128] S11, the master control node receives the response message, makes further decisions based on the node information and the response message, and generates a new control message.
[0129] Taking the data service switching scenario of freight rate calculation mentioned above as an example, the communication process of cluster management is described. The following scenarios involve the following nodes:
[0130] Central control node: active-standby structure, responsible for controlling business processes;
[0131] Data construction node (business node): used to build the database and distribute data to computing nodes.
[0132] Computing node (business node): used to receive data constructed by the data construction node and provide computing services based on the data.
[0133] Load balancing node (business node): provides reverse proxy for computing services of computing nodes, has load balancing function, and is the entrance for external traffic.
[0134] Based on the above nodes, the data service switching process for freight rate calculation includes the following steps:
[0135] T1, start node related services, including its communication related components and business logic driver related components.
[0136] T2, the central control node (i.e., the master node) sends its own node information to the multicast port in a regular cycle according to the service discovery related configuration in the configuration file, which includes the listening address of its own TCPServer component.
[0137] T3, each node (including the central control node and the service node) reads information from the multicast port and obtains the central node information.
[0138] T4, each central control node aggregates all central control node information, selects a master central control node according to the election algorithm, and then updates the master / backup identity to its own central control node information, and continues to send it regularly through multicast.
[0139] T5, each service node receives the information of the main central control node from the multicast network, obtains the TCP listening address, and connects to the TCPServer of the main control node through its own TCPClient. After the connection is successful, it sends its own node information (such as data construction node information, computing node information, and load balancing node information) in a regular loop.
[0140] T6, the central control node receives the node information of each business node, stores it in the node register (NodeRegistry) according to the category, and updates it every time it receives the node information. When the timestamp of a node information in the node register exceeds the current "node information cleanup time", the node is deleted from the node register.
[0141] T7, the main control node obtains the latest database information based on the data construction node information, and sends a data check command (sending messages to all TCPClient components connected to itself through the TCPServer component).
[0142] T8, the computing node and the data construction node reply with a "data check response" message (including whether an update is required and their own database version information) based on the comparison between their own database status and the database status in the "data check command" message. However, since the load balancing node does not have a related message processor set, it will directly discard the "data check command".
[0143] T9, the "data check response" message processor of the main control node will automatically store and classify, thereby analyzing the data situation of the entire cluster. If there is a node that needs to be updated, a "database distribution instruction" message will be sent to all business nodes.
[0144] T10, the "database distribution instruction" message processor of the data construction node starts the sending program, and the "database distribution instruction" message processor of the computing node / data construction node starts the receiving program, thereby completing the database synchronization between the node and the master data construction node.
[0145] T11, the main center control node continues to use the "data check command" to determine the database status of the cluster. If there are nodes whose "data check response" needs to be updated, it continues to update the database through the "database distribution instruction". This step is repeated until the content of the "data check response" message of all computing nodes / data building nodes does not need to be updated, and then proceeds to the next step.
[0146] At T12, the master control node sends a "service loading command" message to all computing nodes. The computing nodes start the computing services and automatically update their computing node information to synchronize it with the node registrar of the master control node.
[0147] T13, the main control node selects all computing nodes from the node registrar, and determines in turn whether the information of each computing node already contains the required computing service (the computing service information includes the service interface address, service load capacity, database version, etc.). If the number of nodes that meet the requirements does not meet the minimum switching requirements, it continues to wait for the unfinished computing nodes to complete data loading and computing service startup. If the switching threshold is met, proceed to the next step.
[0148] T14, the main control node sends a "service switching command" message (including the computing service information list of each computing node) to all load balancing nodes. After receiving this command, the load balancing node executes the relevant switching instructions (switches to the port specified in the "service switching command") and replies to the node registrar of the main control node through automatic update of the load balancing node information after the switching is completed.
[0149] T15, the main control node selects all the load balancing nodes from the node registrar and determines whether the load balancing node has completed the switch. If not, continue to wait. If completed, proceed to the next step.
[0150] T16, the main control node sends a "service shutdown command" to each computing node / data construction node. The "service shutdown command" message processor of each computing node will shut down the relevant computing services and complete data cleanup; and the "service shutdown command" message processor of the data node will only complete data cleanup because there is no computing service. Finally, the new node information will be replied to the node registrar of the main control node through the automatic update of the node information.
[0151] At T17, the data service switch has taken effect and the process returns to T7 to determine whether the new database is executed in sequence (the data construction node will update the data regularly according to its own schedule).
[0152] The following is another scenario involving node exception handling: the data construction node itself has a high-availability architecture, generally one master and N backups (N>=1). Only the master data construction node will build the database (to ensure the data consistency of the cluster, that is, the data of all nodes is the same as that of this node), and the backup data construction node only collects the master data construction node as a backup by default.
[0153] R1, the main data construction node sends an exception, the service is terminated, and it is no longer possible to send its own node information to the main center control node on a regular basis.
[0154] R2, the node registrar of the main center control node determines that the timestamp in the original master data construction node information has exceeded the current node information cleanup time, and deletes it from the node registrar.
[0155] R3, the main center control node determines that the main data construction node is missing from the current data construction node, uses the selection algorithm to select one from all the backup machines as the main machine, and sends a "main node selection" (including the host name of the selected main node) message to all construction nodes.
[0156] R4, each backup data construction node receives the "master node selection" command, and its message processor compares the host name in the message with its own host name. If they are consistent, it switches its identity to the master and continues to update the data with the smallest database. If they are inconsistent, it maintains its backup identity and continues to wait for synchronization of master data. The latest identity information of each node will also be updated to the node registrar of the main center control node as the node information is automatically updated.
[0157] R5, the main control node searches for the data construction node from the node registrar to determine whether the main data construction node has been successfully generated. If it has been generated, continue with the daily data service update work; if it has not been generated, continue to wait until a master selection cycle times out, then return to this process R1 to reselect.
[0158] The implementation mode of the present invention provides a universal cluster communication and management method, which is suitable for complex cluster systems with multi-role distribution and collaborative work. The design of separating cluster communication related components and business driving components allows developers to focus on completing related message content design and business process design without having to pay attention to the transmission and sending of the messages themselves.
[0159] The implementation method of the present invention also relies on multicast addresses to complete service discovery and host election, thereby achieving decentralized service discovery (i.e., no external registration center is required), and allows all business nodes to automatically connect after the host election, completes the aggregation and continuous updating of the entire cluster information, and its node registrar is also convenient for information aggregation and control of specific business nodes, and also facilitates targeted processing of node anomalies.
[0160] Through a set of servers, the business can be vertically divided into multiple different business clusters. Logical cluster isolation can be achieved by using different multicast addresses. For example, if you want to build a monitoring system outside the business system, you can design the identities of the main monitoring center node and the ordinary monitoring nodes, and use another multicast port. Similarly, you can complete a monitoring cluster with the main monitoring node as the center and the ordinary monitoring nodes reporting to it, and you can start and stop operation and maintenance independently, which is decoupled from the business cluster.
[0161] The present invention is described below in conjunction with another optional embodiment.
[0162] Embodiment 2
[0163] A cluster communication device based on a multicast network provided in this embodiment includes a plurality of implementation units, each of which corresponds to each implementation step in the above-mentioned first embodiment.
[0164] Figure 4 is a schematic diagram of an optional cluster communication device based on a multicast network according to an embodiment of the present invention, such as Figure 4As shown, the device may include: a determining unit 41, an establishing unit 42, a sending unit 43, and an executing unit 44.
[0165] The determination unit 41 is used to broadcast the node information of N central nodes in the target communication cluster to the multicast network, and determine the master control node among the N central nodes through the broadcast information in the multicast network, wherein N is a positive integer.
[0166] The establishing unit 42 is used to establish an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network.
[0167] The sending unit 43 is used to generate a control message based on the master control node and the specified service process, and send the control message to the service node based on the dedicated message monitoring relationship.
[0168] The execution unit 44 is used to receive the control message through the service node, execute the service process indicated by the control message, generate a response message to the control message based on the execution result, and return the response message to the main control node.
[0169] The above-mentioned cluster communication device based on the multicast network can first broadcast the node information of N central nodes in the target communication cluster to the multicast network through the determination unit 41, and determine the main control node among the N central nodes through the broadcast information in the multicast network, where N is a positive integer, and then establish an exclusive message listening relationship between the main control node and each service node in the target communication cluster based on the node information of the main control node in the multicast network through the establishment unit 42, and then generate a control message based on the main control node and the specified business process through the sending unit 43, and send the control message to the business node based on the exclusive message listening relationship, and finally control the business node to receive the control message through the execution unit 44, execute the business process indicated by the control message, and generate a response message to the control message based on the execution result, and return the response message to the main control node.
[0170] In an embodiment of the present invention, efficient information transmission is achieved through a multicast network, and the node information of N central nodes is carried to reduce the point-to-point communication burden, and each node in the cluster receives relevant information to quickly and synchronously determine the master node, ensuring that the cluster control center is effectively selected to centrally manage and process communication tasks under high concurrency conditions. The present invention also establishes an exclusive message monitoring relationship between the master node and each service node based on the master node information in the multicast network, which helps to ensure that each service node can stably receive and process messages from the master node, reduce the problem of message loss or duplication, and improve the reliability of message processing. In addition, the master node generates a control message for each service node and sends it through an exclusive message monitoring relationship, which can more accurately meet the needs of each service node and improve communication efficiency. Finally, the service node executes the service process and returns a response message. This response feedback mechanism enables the master node to obtain service feedback in a timely manner, thereby improving the responsiveness and adaptability of the communication cluster system.
[0171] The above method comprehensively optimizes the message processing mechanism of the cluster by utilizing the multicast network to broadcast information, determine the master control node, establish an exclusive listening relationship, generate and distribute control messages, and process response messages, effectively improving the performance and stability of the cluster in high concurrency scenarios, overcoming the problem of insufficient message processing capabilities in traditional cluster solutions, ensuring the efficient and stable operation of the system, and not only improving the efficiency and reliability of message transmission, but also enhancing the adaptability of the system in complex environments, thereby solving the technical problem in related technologies that traditional cluster solutions cannot meet the message processing requirements in high concurrency scenarios, resulting in low cluster processing performance and stability.
[0172] Optionally, the determination unit includes: a first startup module, used to start the communication service component in the central node for each central node, wherein the communication service component includes: a multicast listening component and a TCP listening component; a first control module, used to control all central nodes to load a first configuration file, wherein the first configuration file includes at least: a multicast port address of the multicast network, and a TCP listening port address applied to the TCP listening component; a generation module, used to integrate the node role information and the TCP listening port address of the central node to generate the node information of the central node; a sending module, used to send the node information to the multicast port address through the multicast listening component.
[0173] Optionally, the determination unit also includes: a first acquisition module, used to acquire all broadcast information in the multicast network and obtain node role information of N central nodes; a first determination module, used to determine the central node as the master node when the node role information indicates that there is a unique central node in the master role, wherein the master role refers to the node responsible for communication services under normal circumstances; a second determination module, used to acquire the role declaration timestamps of the R central nodes when the node role information indicates that there are R central nodes that are all in the master role, and determine that the central node corresponding to the role declaration timestamp closest to the current time point is the master node, wherein R is a positive integer greater than or equal to 2 and less than or equal to N; a third determination module, used to determine a master node among the N central nodes through a node election mechanism when the node role information indicates that the N central nodes are all in the backup role, and update the node role information of the master node to the master role, and update the role declaration timestamp of the master node based on the current time point, wherein the backup role refers to the node responsible for taking over the communication service of the master role when an abnormality occurs in the master role.
[0174] Optionally, the cluster communication device based on the multicast network also includes: a second startup module, used to start the multicast listening component and the TCP client component in the business node for each business node; a second control module, used to control all business nodes to load a second configuration file, wherein the second configuration file includes at least: the multicast port address of the multicast network, and the TCP client address applied to the TCP client component.
[0175] Optionally, the establishing unit includes: a second acquisition module, used to obtain the TCP listening port address indicated by the node information of the master control node for each business node through the multicast listening component and the multicast port address; an establishing module, used to establish an exclusive message listening relationship between the TCP listening component in the master control node and the TCP client component in the business node based on the TCP listening port address and the TCP client address.
[0176] Optionally, the communication service component of the master control node also includes: a node registrar.
[0177] Optionally, the cluster communication device based on the multicast network also includes: a receiving module, which is used to receive heartbeat information transmitted by each business node for the master control node through an exclusive message monitoring relationship, wherein the heartbeat information is the node information of the business node sent regularly according to a specified period; an updating module, which is used to update the node registration information of the business node in the node registrar according to the heartbeat information and the heartbeat time point; and a deleting module, which is used to calculate the time interval between the current time point and the most recent heartbeat time point in the node registration information for each node registration information in the node registrar, and delete the business node corresponding to the node registration information in the node registrar when the time interval is greater than a preset time interval.
[0178] Optionally, the cluster communication device based on the multicast network also includes: a third control module, which is used to determine the business steps that each business node is responsible for executing in a specified business process, and control the main control node to transmit the message processing function corresponding to the business step to the business node based on the exclusive message monitoring relationship.
[0179] Optionally, the execution unit includes: a fourth determination module, used to determine the processing time limit requirement of the control message, wherein the processing time limit requirement includes: real-time processing and asynchronous processing; a fifth determination module, used to determine, for each business node, the function type of all message processing functions in the business node, wherein the function type includes: real-time processing function and asynchronous processing function; a discarding module, used to discard the control message when the function type of the message processing function does not match the processing time limit requirement of the control message; and a calling module, used to call the message processing function to process the control message when the function type of the message processing function matches the processing time limit requirement of the control message, so as to obtain the execution result of the business process indicated by the control message.
[0180] Optionally, the calling module includes: a first calling sub-module, which is used to call the real-time processing function to process the control message and obtain an execution result when the processing time limit requirement of the control message is real-time processing; an adding sub-module, which is used to obtain the asynchronous processing time point when the processing time limit requirement of the control message is asynchronous processing, and add the control message to the message queue of the business node based on the asynchronous processing time point; a second calling sub-module, which is used to control the message queue to call the asynchronous processing function when the asynchronous processing time point is reached, and process the control message based on the asynchronous processing function to obtain an execution result.
[0181] The above-mentioned cluster communication device based on multicast network may also include a processor and a memory. The above-mentioned determination unit 41, establishment unit 42, sending unit 43, execution unit 44, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0182] The above processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the kernel parameters are adjusted to generate control messages based on the master control node and the specified business process, and the control messages are sent to the business nodes based on the exclusive message monitoring relationship, and the control messages are received by the business nodes, and the business process indicated by the control messages is executed, and a response message of the control message is generated based on the execution result, and the response message is returned to the master control node.
[0183] The above-mentioned memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one storage chip.
[0184] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that is initialized with the following method steps: broadcasting the node information of N central nodes in the target communication cluster to the multicast network, and determining the master control node among the N central nodes through the broadcast information in the multicast network, where N is a positive integer; establishing an exclusive message listening relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network; generating a control message based on the master control node and a specified service process, and sending the control message to the service node based on the exclusive message listening relationship; receiving the control message through the service node, executing the service process indicated by the control message, and generating a response message to the control message based on the execution result, and returning the response message to the master control node.
[0185] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, the computer-readable storage medium including a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the multicast network-based cluster communication methods in the above-mentioned embodiment 1.
[0186] According to another aspect of an embodiment of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement the cluster communication method based on a multicast network of any one of the above-mentioned embodiments one.
[0187] Figure 5 1 is a hardware structure block diagram of an electronic device (or mobile device) for a cluster communication method based on a multicast network according to an embodiment of the present invention. Figure 5 As shown, the electronic device may include one or more ( Figure 5The processor 502a, processor 502b, ..., processor 502n are used to illustrate) processor 502 (processor 502 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 504 for storing data. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 5 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 5 More or fewer components as shown, or with Figure 5 Different configurations shown.
[0188] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0189] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0190] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0191] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0192] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0193] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several finger controls to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0194] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A cluster communication method based on a multicast network, characterized in that: include: Broadcasting node information of N central nodes in the target communication cluster to a multicast network, and determining a master control node among the N central nodes through the broadcast information in the multicast network, where N is a positive integer; Based on the node information of the master control node in the multicast network, establishing an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster; Generate a control message based on the master control node and the specified business process, and send the control message to the business node based on the exclusive message monitoring relationship; The control message is received by the service node, the service process indicated by the control message is executed, and a response message of the control message is generated based on the execution result, and the response message is returned to the main control node.
2. The cluster communication method according to claim 1, characterized in that: The step of broadcasting node information of N central nodes in the target communication cluster to the multicast network includes: For each of the central nodes, starting a communication service component in the central node, wherein the communication service component includes: a multicast listening component and a TCP listening component; Controlling all the central nodes to load a first configuration file, wherein the first configuration file at least includes: a multicast port address of the multicast network, and a TCP listening port address applied to the TCP listening component; Integrate the node role information of the central node and the TCP listening port address to generate the node information of the central node; The node information is sent to the multicast port address through the multicast monitoring component.
3. The cluster communication method according to claim 2, characterized in that: The step of determining a master control node among the N central nodes through broadcast information in the multicast network comprises: Acquire all broadcast information in the multicast network to obtain the node role information of N central nodes; In the case where the node role information indicates that there is only one central node with a master role, determining the central node as the master control node, wherein the master role refers to a node responsible for communication services under normal circumstances; When the node role information indicates that there are R central nodes all playing the master role, obtain the role declaration timestamps of the R central nodes, and determine that the central node corresponding to the role declaration timestamp closest to the current time point is the master control node, where R is a positive integer greater than or equal to 2 and less than or equal to N; In the case where the node role information indicates that N of the central nodes are all backup roles, a master node is determined among the N central nodes through a node election mechanism, and the node role information of the master node is updated to the primary role, and the role declaration timestamp of the master node is updated based on the current time point, wherein the backup role refers to the node that is responsible for taking over the communication service of the primary role in the event of an abnormality in the primary role.
4. The cluster communication method according to claim 1, characterized in that: Before establishing an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster, the method further includes: For each of the service nodes, starting a multicast listening component and a TCP client component in the service node; Control all the service nodes to load a second configuration file, wherein the second configuration file at least includes: a multicast port address of the multicast network, and a TCP client address applied to the TCP client component.
5. The cluster communication method according to claim 4, characterized in that: The step of establishing an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network includes: For each of the service nodes, obtaining the TCP listening port address indicated by the node information of the master control node through the multicast listening component and the multicast port address; Based on the TCP listening port address and the TCP client address, the exclusive message listening relationship is established between the TCP listening component in the master control node and the TCP client component in the service node.
6. The cluster communication method according to claim 2, characterized in that: The communication service component of the master control node further includes: a node registrar, which, after establishing an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster, further includes: For the master control node, receiving the heartbeat information transmitted by each of the service nodes through the dedicated message monitoring relationship, wherein the heartbeat information is the node information of the service node sent regularly according to a specified period; Updating the node registration information of the service node in the node registrar according to the heartbeat information and the heartbeat time point; For each node registration information in the node registrar, calculate the time interval between the current time point and the most recent heartbeat time point in the node registration information, and if the time interval is greater than a preset time interval, delete the service node corresponding to the node registration information in the node registrar.
7. The cluster communication method according to claim 1, characterized in that: Before generating a control message based on the master control node and the specified business process, the method further includes: Determine the business steps that each of the business nodes is responsible for executing in the specified business process, and control the main control node to transmit the message processing function corresponding to the business step to the business node based on the exclusive message monitoring relationship.
8. The cluster communication method according to claim 7, characterized in that: The step of receiving the control message through the service node and executing the service process indicated by the control message includes: Determining a processing time limit requirement for the control message, wherein the processing time limit requirement includes: real-time processing and asynchronous processing; For each of the service nodes, determining the function types of all the message processing functions in the service node, wherein the function types include: real-time processing functions and asynchronous processing functions; If the function type of the message processing function does not match the processing time limit requirement of the control message, discard the control message; Otherwise, the message processing function is called to process the control message to obtain the execution result of the business process indicated by the control message.
9. The cluster communication method according to claim 8, characterized in that: The step of calling the message processing function to process the control message to obtain the execution result of the business process indicated by the control message includes: In the case where the processing time limit requirement of the control message is real-time processing, calling a real-time processing function to process the control message to obtain the execution result; When the processing time limit requirement of the control message is asynchronous processing, obtaining an asynchronous processing time point, and adding the control message to the message queue of the service node based on the asynchronous processing time point; When the asynchronous processing time point is reached, the message queue is controlled to call the asynchronous processing function, and the control message is processed based on the asynchronous processing function to obtain the execution result.
10. A cluster communication device based on a multicast network, characterized in that: include: A determination unit, configured to broadcast node information of N central nodes in a target communication cluster to a multicast network, and determine a master control node among the N central nodes through the broadcast information in the multicast network, wherein N is a positive integer; An establishing unit, configured to establish an exclusive message monitoring relationship between the master control node and each service node in the target communication cluster based on the node information of the master control node in the multicast network; A sending unit, configured to generate a control message based on the master control node and a specified service process, and send the control message to the service node based on the dedicated message monitoring relationship; The execution unit is used to receive the control message through the service node, execute the service process indicated by the control message, generate a response message to the control message based on the execution result, and return the response message to the main control node.