Method for keeping heartbeat connection between servers

By using UDP services and timing tasks in the server cluster, the problems of inconsistent heartbeat connection standards, insufficient security, limited scalability and limited failure recovery capabilities are solved, and automatic monitoring and management of server connection status is realized to improve the improvement of the System stability and availability, and enhance security and flexibility.

CN119182818APending Publication Date: 2024-12-24HANGZHOU ARCVIDEO TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411371634.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2024-12-24

AI Technical Summary

Technical Problem

The prior art has problems such as inconsistent standards, insufficient security, limited scalability and flexibility, and limited failure recovery capabilities in server cluster center hopping, which has affected system stability and availability.

Method used

UDP services and timing tasks are adopted to automatically monitor and manage the server connection status through the heartbeat connection collection module and the heartbeat packet loss collection module, provide encrypted transmission and dynamic adjustment of heartbeat connection parameters to ensure the stability and availability of the system.

Benefits of technology

It realizes automatic monitoring and management of server connection status, improves the system's self-restoration ability and scalability, enhances security, and reduces the need for administrator intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119182818A_ABST
    Figure CN119182818A_ABST
Patent Text Reader

Abstract

The invention discloses a method for keeping heartbeat connection between servers, which is applied to a system for keeping heartbeat connection between servers comprising a client, a main server and a sub-server. Wherein the main server comprises a service starting module, a newly added service module, a deleted service module, a heartbeat connection set module, a heartbeat packet loss set module, a heartbeat connection timed task module, a heartbeat packet loss timed task module, an offline judgment module, a UDP (User Datagram Protocol) server module, an online callback module and an offline callback module; the sub-server comprises a heartbeat creating module, a UDP client module and a heartbeat stopping module, and the heartbeat connection timing task is used for monitoring a heartbeat connection set and processing the server needing to create the heartbeat; the heartbeat packet loss timing task is used for monitoring a heartbeat packet loss set and counting the packet loss number of the server; the self-recovery capability of the system and the working efficiency of an administrator are improved by intelligently managing a heartbeat connection set and a heartbeat packet loss set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of computer technology, and in particular relates to a method for maintaining a heartbeat connection between servers. Background Art

[0002] With the rapid development of cloud computing and big data technologies, server clusters have become a key infrastructure for processing massive amounts of data and providing efficient services. In a server cluster, collaboration and communication between servers are crucial. The failure of any node or interruption of connection may have a serious impact on the stability and availability of the entire system. Therefore, how to maintain a stable connection between servers and ensure the reliable operation of the system has become an important technical challenge. The following deficiencies exist in the existing technology: (1) Inconsistent technical standards and protocols: There are many different heartbeat connection technologies and protocols on the market. There is a lack of unified standards between these technologies and protocols, resulting in limited compatibility and interoperability between different servers. This increases the complexity of deployment and maintenance and may limit the scale and flexibility of server clusters. (2) Insufficient security and privacy protection: Some existing technologies may lack sufficient security and privacy protection measures during the heartbeat connection process. For example, heartbeat packets may be transmitted without encryption or authentication, making data vulnerable to attacks and tampering. In addition, heartbeat connections between servers may expose sensitive information, such as server status, load conditions, etc., which increases the risk of privacy leakage. (3) Limited scalability and flexibility: As the scale of server clusters expands and the network structure becomes more complex, existing technologies may face challenges in scalability and flexibility. Some technologies may not be able to support heartbeat connections for large-scale server clusters, or may not be able to dynamically adjust the parameters and policies of heartbeat connections according to business needs. This limits the adaptability and flexibility of the system, making it difficult for the system to meet changing business needs. (4) Limited fault recovery and fault tolerance capabilities: Existing technologies may lack efficient fault recovery and fault tolerance capabilities. When a server or network fails, the system may not be able to detect and restore the heartbeat connection in a timely manner, resulting in service interruption or data loss. In addition, some technologies may lack fault tolerance mechanisms and cannot maintain a stable heartbeat connection when the network is congested or the server is busy. Summary of the invention

[0003] In view of the above problems, the present invention provides a method for maintaining a heartbeat connection between servers, which is used to ensure the stability and availability of a server cluster by using UDP services and scheduled tasks.

[0004] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0005] A method for maintaining a heartbeat connection between servers is applied to a system for maintaining a heartbeat connection between servers including a client, a main server and a sub-server, wherein the main server includes a service startup module, a new service module, a service deletion module, a heartbeat connection collection module, a heartbeat packet loss collection module, a heartbeat connection timing task module, a heartbeat packet loss timing task module, an offline determination module, a UDP server module, an online callback module and an offline callback module; the sub-server includes a heartbeat creation module, a UDP client module and a heartbeat stop module, including the following steps:

[0006] S10, set the heartbeat connection timing task to monitor the heartbeat connection set to set the service startup module when the main server starts, create a UDP server module, a heartbeat connection timing task module and a heartbeat packet loss timing task module;

[0007] S20, set the heartbeat connection timing task to monitor the heartbeat connection set to set the client to send a request for adding a new server to the main server; set the new service module to receive the sub-server information to be added transmitted by the client, the sub-server information includes the sub-server IP and the sub-server ID, add the sub-server information to the heartbeat connection set module, and hand it over to the heartbeat connection timing task module for unified monitoring and creation of heartbeats;

[0008] S30, setting a heartbeat connection scheduled task to monitor a heartbeat connection set. The heartbeat connection set module stores the subserver information to create a heartbeat connection in a key-value pair set, where the key is the subserver identifier and the value is the subserver information. The subservers in the current set include those to be added and those that are offline.

[0009] S40, set the heartbeat connection timing task module to monitor the data in the heartbeat connection collection module, cyclically obtain the sub-server information and call the corresponding sub-server creation heartbeat module, generate the corresponding key according to the sub-server identifier, if the response is successful, it means that the heartbeat is successfully established, remove the sub-server from the heartbeat connection collection module, add it to the heartbeat packet loss collection module, and call the online callback module to notify the online status;

[0010] S50, set the heartbeat connection timing task to listen to the heartbeat connection set; call the server's startup heartbeat interface, where the parameters include the UDP port and main server related information; the sub-server returns the startup result to the main server; if it fails, no operation is required, and the call is continued through the timing task; after successful startup, the main server removes the sub-server information from the heartbeat connection set, adds the sub-server information to the heartbeat packet loss set, and resets the number of packet losses to zero; triggers the server online notification; the sub-server sends UDP heartbeat packets to the main server at a regular interval; the main server resets the number of packet losses of the sub-server in the heartbeat packet loss set to zero; the heartbeat packet loss timing task scans the heartbeat packet loss set; the packet loss number of each server in the heartbeat packet loss set is increased by 1; the number of packet losses after increasing by 1 is handed over to the offline judgment module for processing. When the number of packet losses exceeds the set size, the sub-server information is removed from the heartbeat packet loss set or the sub-server information is removed from the heartbeat packet loss set after secondary confirmation; the server information is added to the heartbeat connection set; triggers the server offline notification; the offline callback module executes the corresponding callback operation.

[0011] In a possible implementation, the method further includes:

[0012] S60, set the client to send a request to the main server to delete the server; the deletion service module of the main server receives the sub-server identifier to be deleted passed by the client, and the main server calls the server's stop heartbeat interface to the sub-server, and the parameters include: main server related information; the sub-server returns the stop result to the main server; if it fails, no operation is required; if the stop is successful, the sub-server information is removed from the heartbeat packet loss set; at the same time, the sub-server's stop heartbeat module is called to clean up, triggering the server offline pass.

[0013] In one possible implementation, in S50, the heartbeat packet loss collection module stores the sub-server information for which a heartbeat connection has been established in the form of a key-value pair collection, where the key is the sub-server identifier and the value is the number of consecutive packet losses of the sub-server. All sub-servers in the current heartbeat packet loss collection have normal heartbeat connections.

[0014] In one possible implementation, in S50, the removing of the sub-server information from the heartbeat packet loss set after performing a secondary confirmation includes: when the offline determination module finds that the number of packet losses is greater than a threshold, the TCP protocol is used to request the corresponding sub-server to create a heartbeat module for a secondary confirmation: when the secondary confirmation is successful, the number of packet losses of the sub-server is reset to zero; when the secondary confirmation fails, it is considered to be offline, and the sub-server information is removed from the heartbeat packet loss set.

[0015] The present invention has the following beneficial effects:

[0016] (1) Automatically monitor and manage server connection status: By starting UDP services and scheduled tasks, the connection status between the main server and sub-servers can be automatically monitored and managed to ensure the stability and availability of the server cluster.

[0017] (2) Optimize server heartbeat management: By using "heartbeat connection set" and "heartbeat packet loss set", the server heartbeat connection can be managed more efficiently. Once the number of packet losses detected on a server exceeds the set threshold, the system will add it back to the "heartbeat connection set" and try to reestablish the connection, and notify the administrator when necessary, reducing the need for administrator intervention and improving the system's self-recovery capabilities.

[0018] (3) Improve system scalability and flexibility: By dynamically managing the "heartbeat connection set" and "heartbeat packet loss set", it can adapt to server clusters of different sizes and needs. Whether adding new servers or deleting old servers, the system can automatically adjust the heartbeat connection settings to ensure the stable operation of the entire cluster.

[0019] (4) Provide server status notification: When a new server comes online or an existing server goes offline, the system can send notifications to the administrator in a timely manner, which helps the administrator to understand the server's operating status in a timely manner and take corresponding management measures.

[0020] (5) Improved security: The encryption key is passed to the sub-server when creating the heartbeat, allowing the sub-server to symmetrically encrypt the content when sending UDP packets, ensuring security during transmission. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 A flowchart of the steps of a method for maintaining a heartbeat connection between servers according to an embodiment of the present invention;

[0022] Figure 2 The present invention is a schematic diagram of the structure of a system for maintaining a heartbeat connection between servers in a method for maintaining a heartbeat connection between servers according to an embodiment of the present invention. DETAILED DESCRIPTION

[0023] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0024] See also Figure 1 , which is a flowchart of a method for maintaining a heartbeat connection between servers according to an embodiment of the present invention, is applied to Figure 2The system shown includes a client, a main server and a sub-server for maintaining a heartbeat connection between servers, wherein the main server includes a service startup module, a new service module, a service deletion module, a heartbeat connection collection module, a heartbeat packet loss collection module, a heartbeat connection timing task module, a heartbeat packet loss timing task module, an offline determination module, a UDP server module, an online callback module and an offline callback module; the sub-server includes a heartbeat creation module, a UDP client module and a heartbeat stop module, including the following steps:

[0025] S10, setting the service startup module to create a UDP server module, a heartbeat connection timing task module and a heartbeat packet loss timing task module when the main server is started; the heartbeat connection timing task is used to monitor the heartbeat connection set and process the server that needs to create a heartbeat; the heartbeat packet loss timing task is used to monitor the heartbeat packet loss set and count the number of server packet losses;

[0026] S20, set the client to send a request for adding a new server to the main server; set the new service module to receive the sub-server information to be added transmitted by the client, the sub-server information includes the sub-server IP and the sub-server identifier, add the sub-server information to the heartbeat connection collection module, and hand it over to the heartbeat connection timing task module for unified monitoring and creation of heartbeats;

[0027] S30, setting the heartbeat connection collection module to store the sub-server information for creating the heartbeat connection in a key-value pair collection mode, wherein the key is the sub-server identifier, the value is the sub-server IP, and the sub-servers in the current collection include the sub-servers to be added and the sub-servers that are offline;

[0028] S40, set the heartbeat connection timing task module to monitor the data in the heartbeat connection collection module, loop to obtain the sub-server information and call the corresponding sub-server creation heartbeat module, generate the corresponding key according to the sub-server identifier, the encryption method is not limited here, if the heartbeat result response of the requested sub-server is successful, it means that the heartbeat is successfully established, remove the sub-server from the heartbeat connection collection module, add it to the heartbeat packet loss collection module, and call the online callback module to notify the online notification, and execute the corresponding callback operation, such as notifying the administrator;

[0029] S50, set the heartbeat connection timing task to listen to the heartbeat connection set; call the server's start heartbeat interface, where the parameters include the UDP port and main server related information; the sub-server returns the startup result to the main server; if it fails, no operation is required, and the heartbeat connection timing task continues to be called; after successful startup, the main server removes the sub-server information from the heartbeat connection set, adds the sub-server information to the heartbeat packet loss set, and resets the number of packet losses to zero; the sub-servers in the heartbeat packet loss set all have normal heartbeat connections. Trigger server online notification; the UDP client module of the sub-server sends UDP heartbeat packets to the main server regularly; the UDP server module decrypts the received UDP heartbeat packets; after successful decryption, the UDP heartbeat packet is considered valid, and the main server resets the number of packet losses of the sub-server in the heartbeat packet loss set to zero; the heartbeat packet loss timing task regularly monitors the data in the heartbeat packet loss set module; the number of packet losses of the sub-server is updated cyclically to the current number plus 1, and the number of packet losses after adding 1 is handed over to the offline judgment module for processing. When the number of packet losses exceeds the set size, the sub-server information is removed from the heartbeat packet loss set or the sub-server information is removed from the heartbeat packet loss set after a second confirmation; the server information is added to the heartbeat connection set; trigger server offline notification. When the server is offline, the offline callback module performs corresponding callback operations, such as cleaning up resources, notifying administrators, etc.

[0030] Continue to see Figure 1 , a method for maintaining a heartbeat connection between servers according to another embodiment of the present invention further comprises: S60, setting the client to send a request to delete the server to the main server; the deletion service module of the main server receives the sub-server identifier to be deleted transmitted by the client, and the main server calls the server's stop heartbeat interface to the sub-server, and the parameters include: main server related information; the sub-server returns the stop result to the main server; if it fails, no operation is required; if the stop is successful, the sub-server information is removed from the heartbeat packet loss set; at the same time, the stop heartbeat module of the sub-server is called to clean up, triggering the server offline notification. The stop heartbeat module receives the stop information sent by the deletion service module of the main server, and the received parameters include the main server information, and then queries the corresponding UDP client module according to the main server identifier to perform a destruction operation.

[0031] Furthermore, in another embodiment of the invention, a method S50 for maintaining a heartbeat connection between servers removes the sub-server information from the heartbeat packet loss set after a secondary confirmation, including: when the offline determination module finds that the number of packet losses is greater than a threshold, a TCP protocol is used to request the corresponding sub-server to create a heartbeat module for a secondary confirmation: when the secondary confirmation is successful, the number of packet losses of the sub-server is reset to zero; when the secondary confirmation fails, it is considered offline, and the sub-server information is removed from the heartbeat packet loss set. The secondary confirmation can solve the problem of false alarms caused by unstable UDP networks. The threshold for the number of packet losses can be specifically set according to actual needs, for example, 5 times.

[0032] By maintaining the heartbeat connection between servers as set above, the stability and availability of the server cluster are ensured by using UDP service and scheduled tasks. The server heartbeat management is optimized by intelligently managing the "heartbeat connection set" and "heartbeat packet loss set", that is, the data in the heartbeat connection set is monitored by the heartbeat connection scheduled task module, added by the new service module and the offline judgment module, and removed by the deletion service module and the heartbeat connection scheduled task module; the data in the heartbeat packet loss set is monitored by the heartbeat packet loss scheduled task, added by the heartbeat connection scheduled task module, removed by the deletion service module and the offline judgment module, and updated by the heartbeat packet loss scheduled task module and the UDP server module; the self-recovery ability of the system and the work efficiency of the administrator are improved. At the same time, it has excellent scalability and flexibility, can dynamically adapt to server clusters of different sizes, and promptly notify the administrator when the server status changes. In addition, it also enhances the security of data transmission through encrypted transmission technology.

[0033] It should be understood that the exemplary embodiments described herein are illustrative rather than restrictive. Although one or more embodiments of the present invention have been described in conjunction with the accompanying drawings, it should be understood by those skilled in the art that various changes in form and detail may be made without departing from the spirit and scope of the present invention as defined by the appended claims.

Claims

1. A method for maintaining a heartbeat connection between servers, characterized in that: The invention is applied to a system for maintaining heartbeat connection between servers including a client, a main server and a sub-server, wherein the main server includes a service startup module, a new service module, a service deletion module, a heartbeat connection collection module, a heartbeat packet loss collection module, a heartbeat connection timing task module, a heartbeat packet loss timing task module, an offline determination module, a UDP server module, an online callback module and an offline callback module; the sub-server includes a heartbeat creation module, a UDP client module and a heartbeat stop module, including the following steps: S10, setting the service startup module to create a UDP server module, a heartbeat connection timing task module and a heartbeat packet loss timing task module when the main server is started; S20, setting the client to send a request for adding a new server to the main server; setting the new service module to receive the sub-server information to be added transmitted by the client, the sub-server information includes the sub-server IP and the sub-server identifier, adding the sub-server information to the heartbeat connection collection module, and handing it over to the heartbeat connection timing task module for unified monitoring and creating heartbeats; S30, setting the heartbeat connection set module to store the sub-server information for creating the heartbeat connection in a key-value pair set, wherein the key is the sub-server identifier and the value is the sub-server information, and the sub-servers in the current set include the sub-servers to be added and the sub-servers that are offline; S40, set the heartbeat connection timing task module to monitor the data in the heartbeat connection collection module, cyclically obtain the sub-server information and call the corresponding sub-server creation heartbeat module, generate the corresponding key according to the sub-server identifier, if the response is successful, it means that the heartbeat is successfully established, remove the sub-server from the heartbeat connection collection module, add it to the heartbeat packet loss collection module, and call the online callback module to notify the online status; S50, set the heartbeat connection timing task to listen to the heartbeat connection set; call the server's startup heartbeat interface, where the parameters include the UDP port and main server related information; the sub-server returns the startup result to the main server; if it fails, no operation is required, and the call is continued through the timing task; after successful startup, the main server removes the sub-server information from the heartbeat connection set, adds the sub-server information to the heartbeat packet loss set module, and resets the number of packet losses to zero; triggers the server online notification; the sub-server sends UDP heartbeat packets to the main server at a regular interval; the main server resets the number of packet losses of the sub-server in the heartbeat packet loss set to zero; the heartbeat packet loss timing task scans the heartbeat packet loss set; the number of packet losses for each server in the heartbeat packet loss set is increased by 1; the number of packet losses after increasing by 1 is handed over to the offline judgment module for processing. When the number of packet losses exceeds the set size, the sub-server information is removed from the heartbeat packet loss set or the sub-server information is removed from the heartbeat packet loss set after secondary confirmation; the server information is added to the heartbeat connection set; triggers the server offline notification; the offline callback module executes the corresponding callback operation.

2. The method for maintaining a heartbeat connection between servers as claimed in claim 1, characterized in that: Further including: S60, setting the client to send a request to delete the server to the main server; The deletion service module of the main server receives the identifier of the sub-server to be deleted passed by the client, and the main server calls the server's stop heartbeat interface to the sub-server. The parameters include: information related to the main server; the sub-server returns the stop result to the main server; if it fails, no operation is required; if the stop is successful, the sub-server information is removed from the heartbeat packet loss set; at the same time, the stop heartbeat module of the sub-server is called for cleanup, triggering a server offline notification.

3. The method for maintaining a heartbeat connection between servers as claimed in claim 1 or 2, characterized in that: In S50, the heartbeat packet loss collection module stores the sub-server information for which heartbeat connections have been established in a key-value pair collection format, where the key is the sub-server identifier and the value is the number of consecutive packet losses of the sub-server. All sub-servers in the current heartbeat packet loss collection have normal heartbeat connections.

4. The method for maintaining a heartbeat connection between servers as claimed in claim 1 or 2, characterized in that: The method of removing the sub-server information from the heartbeat packet loss set after the secondary confirmation includes: when the offline determination module finds that the number of packet losses is greater than a threshold, the TCP protocol is used to request the corresponding sub-server to create a heartbeat module for secondary confirmation: when the secondary confirmation is successful, the number of packet losses of the sub-server is reset to zero; when the secondary confirmation fails, it is considered to be offline, and the sub-server information is removed from the heartbeat packet loss set.