Long connection task management method and device, computer equipment and storage medium
By switching the mapping objects of long-connected tasks to the backup node in the dual-main architecture, the problem of repeated tasks caused by node downtime or heartbeat reporting network problems is solved, and the stability of task management is improved.
Patent Information
- Application Number
- CN202310820934.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-05
- Publication Date
- 2025-01-07
AI Technical Summary
Under the dual-main architecture, node downtime or heartbeat reporting network problems lead to heartbeat request failure, which may cause repeated pull-up of tasks and affect the stability of service tasks.
By obtaining the status of the standby node and the primary node, determine that the primary node in the isolated state is the node to be switched, and switch the mapping object of the target long-connected task to the standby node to avoid repeated task pulling and ensuring the stability of task management.
It effectively avoids the problem of repeated tasks caused by changes in the state of the master node, ensures normal pulling and real-time monitoring of long-connected tasks, and improves the stability of task management.
Smart Images

Figure CN119276688A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, apparatus, computer equipment and storage medium for managing long connection tasks. Background Art
[0002] With the advancement of communication technology and the development of Internet applications, in order to ensure that the server can provide services more stably and continuously, a long connection state can be established between the server and the client to avoid frequent link establishment / disconnection of service links. Taking into account the stability of the service, task management is performed through a dual-master architecture, that is, there are two nodes in the dual-master architecture, both of which are master nodes, and then each service task process periodically reports heartbeats to the two nodes respectively, thereby ensuring that the two nodes can periodically record the current valid and available service task information.
[0003] At present, based on the dual-master architecture, when a problem occurs on one of the nodes, the service task can be re-started through the other node according to the service task information, and the heartbeat monitoring of the service task can be continuously provided to ensure the normal processing of the service task. However, since the situation that causes the node problem can be either node downtime or heartbeat reporting network problem, then in the case of node downtime, some heartbeat requests will fail, and in the case of heartbeat reporting network problem, it may cause problems such as repeated task starting, which will affect the normal starting and real-time monitoring of the service task, thereby reducing the stability of service task processing. Therefore, how to improve the stability of long connection task management is an urgent problem to be solved. Summary of the invention
[0004] Based on this, it is necessary to provide a method, apparatus, computer equipment and storage medium for long connection task management that can improve the stability of long connection task management in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for managing long connection tasks. The method comprises:
[0006] Obtain the backup node and multiple master nodes in the long connection task management scenario. The master node is used to manage the long connection tasks with mapping relationships, and the backup node is used to obtain the node status of each master node.
[0007] If the node status of at least one master node among the master nodes changes from the available state to the isolated state, the master node in the isolated state is determined as the node to be switched;
[0008] Determine a target persistent connection task that has a mapping relationship with the node to be switched, and switch the mapping object of the target persistent connection task from the node to be switched to the standby node;
[0009] The target long connection task is managed through the standby node.
[0010] In a second aspect, the present application also provides a long connection task management device. The device includes:
[0011] The node acquisition module is used to obtain the backup node and multiple master nodes in the long connection task management scenario. The master node is used to manage the long connection tasks with mapping relationships, and the backup node is used to obtain the node status of each master node.
[0012] A node determination module, configured to determine the master node in the isolated state as a node to be switched if the node state of at least one master node among the master nodes changes from the available state to the isolated state;
[0013] A node update module is used to determine a target long connection task that has a mapping relationship with the node to be switched, and update the mapping object of the target long connection task from the node to be switched to the standby node;
[0014] The task management module is used to manage the target long connection task through the backup node.
[0015] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0016] Obtain the backup node and multiple master nodes in the long connection task management scenario. The master node is used to manage the long connection tasks with mapping relationships, and the backup node is used to obtain the node status of each master node.
[0017] If the node status of at least one master node among the master nodes changes from the available state to the isolated state, the master node in the isolated state is determined as the node to be switched;
[0018] Determine a target persistent connection task that has a mapping relationship with the node to be switched, and switch the mapping object of the target persistent connection task from the node to be switched to the standby node;
[0019] The target long connection task is managed through the standby node.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0021] Obtain the backup node and multiple master nodes in the long connection task management scenario. The master node is used to manage the long connection tasks with mapping relationships, and the backup node is used to obtain the node status of each master node.
[0022] If the node status of at least one master node among the master nodes changes from the available state to the isolated state, the master node in the isolated state is determined as the node to be switched;
[0023] Determine a target persistent connection task that has a mapping relationship with the node to be switched, and switch the mapping object of the target persistent connection task from the node to be switched to the standby node;
[0024] The target long connection task is managed through the standby node.
[0025] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0026] Obtain the backup node and multiple master nodes in the long connection task management scenario. The master node is used to manage the long connection tasks with mapping relationships, and the backup node is used to obtain the node status of each master node.
[0027] If the node status of at least one master node among the master nodes changes from the available state to the isolated state, the master node in the isolated state is determined as the node to be switched;
[0028] Determine a target persistent connection task that has a mapping relationship with the node to be switched, and switch the mapping object of the target persistent connection task from the node to be switched to the standby node;
[0029] The target long connection task is managed through the standby node.
[0030] The above-mentioned method, apparatus, computer equipment, storage medium and computer program product for long connection task management obtain a backup node and multiple master nodes in a long connection task management scenario, wherein the master node is used to manage the long connection tasks with a mapping relationship, and the backup node is used to obtain the node status of each master node. Based on this, if the node status of at least one master node among the master nodes changes from an available state to an isolated state, the master node in the isolated state is determined as the node to be switched; then the target long connection task with a mapping relationship with the node to be switched is determined, and the mapping object of the target long connection task is switched from the node to be switched to the backup node, thereby managing the target long connection task through the backup node. Through the above-mentioned long connection task management method, since the node status of the main node that manages the long connection task can be obtained through the standby node, when the node status of the main node changes, causing the main node to be unable to normally manage the target long connection task with a mapping relationship, the standby node can take over the management of the target long connection task by modifying the mapping relationship, so as to avoid problems such as repeated task launch, ensure the normal launch and real-time monitoring of the long connection task, that is, ensure the normal management of the long connection task, thereby improving the stability of the management of the long connection task. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A system architecture diagram of a dual-main structure in an embodiment;
[0032] Figure 2 An application environment diagram of a method for managing long connection tasks in an embodiment;
[0033] Figure 3 A schematic diagram of the system architecture of a method for managing long connection tasks in an embodiment;
[0034] Figure 4 It is a schematic diagram of an application process in a live broadcast recording task management scenario in one embodiment;
[0035] Figure 5 A flowchart of a method for managing long connection tasks in one embodiment;
[0036] Figure 6 A schematic diagram of a process of switching a node to be switched to a standby node in an embodiment;
[0037] Figure 7 A schematic diagram of a process of registering a standby node to a target heartbeat instance in one embodiment;
[0038] Figure 8 A schematic diagram of a process for processing a request for a target persistent connection task in one embodiment;
[0039] Fig. 9A flowchart of a method for managing long connection tasks in another embodiment;
[0040] Fig.10 It is a flowchart of characterizing the abnormality of the master node through task management information in one embodiment;
[0041] Fig.11 It is a flowchart of another embodiment of representing the abnormality of the master node through task management information;
[0042] Fig.12 A schematic diagram of a process for characterizing the existence of an abnormality in a master node through a data receiving result in an embodiment;
[0043] Fig.13 It is a flowchart of another embodiment of characterizing the abnormality of the master node through the data receiving result;
[0044] Fig.14 A schematic diagram of a process for configuring a standby node and a master node in an embodiment;
[0045] Fig.15 A complete flowchart of a method for managing long connection tasks in one embodiment;
[0046] Fig.16 is a structural block diagram of a long connection task management device in an embodiment;
[0047] Fig.17 It is a structural block diagram of a long connection task management device in another embodiment;
[0048] Fig.18 It is a structural block diagram of a long connection task management device in another embodiment;
[0049] Fig.19 A structural block diagram of a long connection task management device in another embodiment;
[0050] Fig. 20 A structural block diagram of a long connection task management device in yet another embodiment;
[0051] Fig.21 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0053] With the advancement of communication technology and the development of Internet applications, in order to ensure that the server can provide services more stably and continuously, a long connection state can be established between the server and the client to avoid frequent link establishment / disconnection of service links. However, based on further consideration of service stability, the dual-active architecture can be used to manage tasks in the long connection state. Figure 1 The dual-active architecture shown in the figure has two nodes, namely Figure 1 The nodes 102 and 104 shown in the figure are both master nodes, and nodes 102 and 104 ensure that tasks are not started at the same time through the Compare And Swap (CAS) operation. Based on this, each service task process can periodically report heartbeats to nodes 102 and 104, respectively, so as to ensure that nodes 102 and 104 can periodically record the currently valid and available service task information.
[0054] Currently, if Figure 1 The dual-master architecture shown can re-start the service task through the other node according to the service task information when there is a problem with one of the nodes in node 102 and node 104, and continue to provide heartbeat monitoring of the service task to ensure the normal processing of the service task. However, since the situation that causes the problem of the node can also be node downtime or heartbeat reporting network problems, then in the case of node downtime, some heartbeat requests will fail, and in the case of heartbeat reporting network problems, it may cause problems such as repeated pulling up of tasks, which will affect the normal pulling up and real-time monitoring of the service task, thereby reducing the stability of the service task processing. Therefore, how to improve the stability of long connection task management is an urgent problem to be solved.
[0055] Based on this, the embodiment of the present application provides a method for managing long connection tasks that can improve the stability of long connection task management. Based on this, the method for managing long connection tasks provided by the embodiment of the present application can be applied to Figure 2 In the application environment shown, the terminal 202 communicates with the server 204 through a network. The data storage system can store data that the server 204 needs to process. The data storage system can be integrated on the server 204, or placed on the cloud or other servers.
[0056] Specifically, taking the application to server 204 as an example, the server can obtain the backup node and multiple master nodes in the long connection task management scenario, the master node is used to manage the long connection tasks with a mapping relationship, and the backup node is used to obtain the node status of each master node. Based on this, when the node status of at least one master node among the master nodes changes from an available state to an isolated state, the server can determine the master node in the isolated state as the node to be switched, and thereby determine the target long connection task that has a mapping relationship with the node to be switched, thereby switching the mapping object of the target long connection task from the node to be switched to the backup node, thereby managing the target long connection task through the backup node.
[0057] Among them, the server 204 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Terminal 202 can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.
[0058] Furthermore, since the method for managing long connection tasks provided in the embodiment of the present application also involves cloud technology, cloud technology will be briefly described below. Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and network in a wide area network or a local area network to realize data calculation, storage, processing, and sharing.
[0059] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of the technical network system require a large amount of computing and storage resources, such as video websites, image websites and more portal websites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark, which needs to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data need strong system backing support, which can only be achieved through cloud computing.
[0060] Among them, cloud computing refers to the delivery and use mode of IT infrastructure, which means obtaining required resources through the network in an on-demand and easily scalable manner; in a broad sense, cloud computing refers to the delivery and use mode of services, which means obtaining required services through the network in an on-demand and easily scalable manner. This service can be related to IT and software, the Internet, or other services. Cloud computing is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing. As the Internet, real-time data streams, and the diversification of connected devices develop, as well as the needs of search services, social networks, mobile commerce, and open collaboration, cloud computing has developed rapidly. Different from the previous parallel distributed computing, the emergence of cloud computing will promote revolutionary changes in the entire Internet model and enterprise management model in terms of concept.
[0061] To facilitate understanding of the long connection task management system architecture in the embodiment of the present application, the long connection task management system architecture will be introduced based on the dual-master architecture. Figure 3 As shown, the long connection task management system architecture includes a server 301 and a name server 302, and also includes at least two master nodes and at least one backup node, that is, Figure 3 The server 301 includes the master node 303, the master node 304 and the backup node 305. The server 301 manages the service task process through the master node 303 and the master node 304 by configuring the master node 303, the master node 304 and the backup node 305, and the name server 302 is used to realize the monitoring and acquisition of the master node status of the master node 303 and the master node 304 by the backup node 305, and provides the replacement capability of the backup node 305 to replace any master node, and the master node 303 and the master node 304 also need to obtain their current service status through the name server 302 so as to perceive the current service status in time and make corresponding processing. The name server 302 is essentially a routing system. The master node 303 and the master node 304 can register the corresponding network protocol information to the name server 302, so that the backup node can obtain the node status of other master nodes and each master node through the name server 302.
[0062] Understandably, Figure 3The example is only used to understand the present solution. In actual applications, the long connection task management system architecture of the embodiment of the present application may also include multiple master nodes and multiple backup nodes, which are not specifically limited here.
[0063] Secondly, the long connection task management method in the embodiment of the present application can be applied to any long connection task management scenario such as live recording task management and real-time chat task management. For ease of understanding, Figure 4 As shown, taking the application in the live recording task management scenario as an example, if the anchor 402 initiates a live streaming push to the live streaming service 404, the live recording task management service 406 can receive the notification of the live streaming service 406, and then the live recording task management service 406 pulls up the recording task to record. After the anchor 402 actively ends the live broadcast, that is, the anchor 402 initiates the live streaming interruption to the live streaming service 404, the live recording task management service 406 will generate a recording file and call back to the preset background service 408. At this time, the background service 408 can perform the next business processing according to the recording file callback, such as playback display, video editing, etc. However, in the live recording task management scenario, if the service process of the master node itself is normal but the heartbeat network is continuously abnormal, that is, the heartbeat data that the live recording task management service cannot receive normally, a new recording task may be pulled up again at this time, so repeated recording callbacks are unacceptable for some recording business scenarios.
[0064] Therefore, through the method of long connection task management provided by the embodiment of the present application, in the case of a main node service processing exception or a heartbeat network exception, the backup node can take over the management of the target long connection task by modifying the mapping relationship, thereby avoiding problems such as repeated task launches, ensuring the normal launch and real-time monitoring of long connection tasks, that is, ensuring the normal management of long connection tasks, thereby improving the stability of long connection task management. It can be understood that Figure 4 The examples are only used to understand the application scenarios of the present solution and should not be understood as specific limitations on the application scenarios.
[0065] In one embodiment, Figure 5 As shown, a method for managing long connection tasks is provided, and the method is applied to Figure 2 The method is described by taking the server 204 in the example as an example. It is understandable that the method can also be applied to the terminal 202, and can also be applied to a system including the terminal 202 and the server 204, and is implemented through the interaction between the terminal 202 and the server 204. In this embodiment, the method includes the following steps:
[0066] Step 502, obtaining a backup node and multiple master nodes in a long connection task management scenario, the master node is used to manage the long connection tasks with a mapping relationship, and the backup node is used to obtain the node status of each master node.
[0067] Among them, the long connection task management scenario is specifically: the scenario of managing tasks in the long connection state. The above-mentioned long connection state specifically represents: after two objects are connected for communication, the connection state is maintained regardless of whether there is data transmission and request response. And, managing the long connection task at least includes: receiving the heartbeat data of the long connection task, and processing the request of the long connection task.
[0068] For ease of understanding, take the application in the live broadcast recording task management scenario as an example, then the live broadcast recording task is the recording start data push stream until the end of the live broadcast, then the state in the live broadcast recording task management scenario is the state of the current live broadcast recording task recorded by the master node during the entire live broadcast recording process, such as: normal stream recording, stream interruption and restart, stream interruption waiting for new stream push notification, stream interruption and abandonment of retry, etc. Then the long connection state is: after the recording start data push stream, the live broadcast recording task is maintained until the live broadcast ends and the entire live broadcast recording task ends. During the live broadcast recording task, the master node has been recording whether the live broadcast recording task is normal, interrupted, retried, etc., and all the states are in the long connection state. Therefore, the long connection state also has corresponding long connection state data, which is all the state data of the task in the long connection state when the task process is in progress. Then in the live broadcast recording task management scenario, the long connection state data is the state data of the live broadcast recording task being normal, interrupted, retried, etc. It is understandable that the long connection task management scenario can also be other long connection task management scenarios such as long connection real-time chat task management, which is not specifically limited here. Secondly, managing the task at least includes: receiving the heartbeat data of the long connection task and processing the request of the long connection task.
[0069] Secondly, the master node is used to manage the long connection tasks with a mapping relationship. The aforementioned mapping relationship is specifically stored in the heartbeat instance to which the master node belongs, that is, there is a heartbeat data transmission relationship between the heartbeat instance and the long connection task, that is, the heartbeat instance can receive the heartbeat data transmitted by the long connection task with a heartbeat data transmission relationship, so the master node in an available state belonging to the heartbeat instance has a mapping relationship with the long connection task, and the specific mapping object of the master node is the heartbeat data transmitted by the long connection task, and the heartbeat data transmitted by the long connection task to different heartbeat instances are essentially the same data.
[0070] For example, there are master nodes A1 and A2, and master node A1 belongs to heartbeat instance B1, and master node A2 belongs to heartbeat instance B2. If there is heartbeat data transmission between heartbeat instance B1 and long connection task C1, that is, heartbeat instance B1 can receive heartbeat data D1 transmitted by long connection task C1. If there is heartbeat data transmission between heartbeat instance B2 and long connection task C1, then at this time, heartbeat instance B2 will be able to receive heartbeat data D2 transmitted by long connection task C1, and heartbeat data D1 and heartbeat data D2 are essentially the same data. It can be seen that there is a mapping relationship between master node A1 and long connection task C1, and the specific mapping object of master node A1 is heartbeat data D1 transmitted by long connection task C1. And there is also a mapping relationship between master node A2 and long connection task C1, and the specific mapping object of master node A2 is heartbeat data D2 transmitted by long connection task C1.
[0071] In addition, the standby node is used to obtain the node status of each master node. It can be known from the above system architecture that the standby node specifically obtains the node status of each master node registered in the name server through the name server. The node status can be an available state or an isolated state, that is, the node status of the node used to obtain the node status of each master node is specifically an isolated state, and the node status of the node used to manage the long connection tasks with a mapping relationship is an available state.
[0072] Specifically, the server obtains a backup node and multiple master nodes in the long connection task management scenario. Before performing long connection task management, the server can first configure the master node and the backup node, that is, configure the node status of each node to be configured through the node configuration file, and then configure the node configured in the available state as the master node, and configure the node configured in the isolated state as the backup node, and register the node in the available state (i.e., the master node) and the node in the isolated state (i.e., the backup node) to the name server. Therefore, in the process of performing long connection task management, the master node that can manage the long connection task with a mapping relationship can be obtained from the name server, and the backup node can be obtained from the name server.
[0073] Optionally, when the master node and the backup node are not registered in the name server, the server can also configure the master node and the backup node in real time to obtain the backup node and multiple master nodes in the long connection task management scenario, so as to manage the long connection tasks with mapping relationships through the master node, and obtain the node status of each master node through the backup node. The method of obtaining the backup node and multiple master nodes in the long connection task management scenario is not limited here.
[0074] Step 504: If the node state of at least one of the master nodes changes from the available state to the isolated state, the master node in the isolated state is determined as a node to be switched.
[0075] Among them, the available state is used to characterize that the node can manage the long connection tasks with a mapping relationship, and the isolated state is used to characterize that the node can obtain the node status of each master node. Based on this, the node to be switched is the master node in the isolated state, and the node to be switched is the master node waiting to be switched to the standby node.
[0076] Specifically, when it is determined that there is at least one master node among the master nodes whose node status has changed from an available state to an isolated state, the server can determine the master node in the isolated state as the node to be switched, that is, the server will not be able to normally manage the long connection task with the mapping relationship as the node to be switched, waiting for the backup node to replace the node to be switched to perform the corresponding mapping relationship.
[0077] Furthermore, in the process of the master node managing the long connection tasks with a mapping relationship, the master node can periodically report its own node status to the server, and when the master node determines that it is abnormal, it can adjust its own node status from the available state to the isolated state, and actively report to the server that its own node status has been adjusted to the isolated state. Alternatively, the server can actively query the node status of each master node, and when the node status is abnormal, the node status of the node with abnormal node status can also be adjusted from the available state to the isolated state, and the server can actively query in a periodic manner or in real time, which is not specifically limited here.
[0078] Step 506: determine a target persistent connection task that has a mapping relationship with the node to be switched, and switch the mapping object of the target persistent connection task from the node to be switched to the standby node.
[0079] Among them, the target long connection task is a long connection task that has a mapping relationship with the node to be switched. Specifically, the server determines the target long connection task that has a mapping relationship with the node to be switched, and switches the mapping object of the target long connection task from the node to be switched to the standby node. Based on this, as can be seen from the aforementioned implementation, the server can obtain the mapping relationship between each node and the long connection task through the nodes in an available state included in each heartbeat instance. Therefore, after determining the node to be switched, the target long connection task that has a mapping relationship with the node to be switched can be determined through the heartbeat instance to which the node to be switched belongs, and then the mapping object of the target long connection task is switched from the node to be switched to the standby node, that is, the standby node is registered in the heartbeat instance to which the node to be switched belongs, so that the standby node can receive the heartbeat data transmitted by the target long connection task through the heartbeat instance.
[0080] For example, there is a mapping relationship between the master node A1 and the long connection task C1, and the specific mapping object of the master node A1 is the heartbeat data D1 transmitted by the long connection task C1. And there is also a mapping relationship between the master node A2 and the long connection task C1, and the specific mapping object of the master node A2 is the heartbeat data D2 transmitted by the long connection task C1. Therefore, if it is determined that the node to be switched is the master node A2, then it can be determined that the target long connection task is the long connection task C1, and the specific mapping object is the heartbeat data D2 transmitted by the long connection task C1. At this time, the mapping object of the heartbeat data D2 transmitted by the long connection task C1 is switched from the node to be switched (i.e., the master node A2) to the standby node, that is, at this time, there is a mapping relationship between the standby node and the heartbeat data D2 transmitted by the long connection task C1.
[0081] It can be understood that the heartbeat data described in this embodiment are the latest heartbeat data sent periodically by the long connection task, and the heartbeat data sent in the subsequent cycle is updated by the heartbeat data sent in the previous cycle. It can be seen that the heartbeat data sent in the subsequent cycle includes the heartbeat data sent in the previous cycle. For example, when the cycle is 5 seconds, the heartbeat data sent by the long connection task C1 to the main node A2 in the 5th second is heartbeat data D21, and the heartbeat data sent by the long connection task C1 to the main node A2 in the 10th second is heartbeat data D22. At this time, heartbeat data D22 includes heartbeat data D21.
[0082] Step 508: Manage the target long connection task through the standby node.
[0083] Specifically, the target long connection task is managed through the standby node, that is, the server will manage the target long connection task through the standby node, and suspend the management of the target long connection task by the node to be switched. Furthermore, the server adjusts the node state of the standby node from the isolated state to the available state, that is, the standby node in the available state is used as the new main node, so the target long connection task can be managed by the standby node in the available state. Secondly, since the node to be switched is already in an isolated state, the server will suspend the management of the target long connection task by the node to be switched in the isolated state, that is, the node to be switched in the isolated state is used as the new standby node, so the node state of each node that has a mapping relationship with the long connection task can be obtained through the new standby node (that is, the node to be switched in the isolated state).
[0084] Based on this, if the node state of a new master node changes from an available state to an isolated state again, the node replacement can be completed by performing the aforementioned similar steps through a new standby node (i.e., the node to be switched in an isolated state), thereby ensuring stable management of the long connection task. It should be understood that the examples in this embodiment are used to understand this solution and should not be understood as a limitation of this solution.
[0085] In the above-mentioned long connection task management method, since the node status of the main node that manages the long connection task can be obtained through the backup node, when the node status of the main node changes, causing the main node to be unable to normally manage the target long connection task with a mapping relationship, the backup node can take over the management of the target long connection task by modifying the mapping relationship, so as to avoid problems such as repeated task startup, ensure the normal startup and real-time monitoring of the long connection task, that is, ensure the normal management of the long connection task, thereby improving the stability of the management of the long connection task.
[0086] In one embodiment, Figure 6 As shown, the mapping object of the target long connection task is switched from the node to be switched to the standby node, including:
[0087] Step 602, determining the target heartbeat instance to which the node to be switched belongs, where the target heartbeat instance is used to describe: the mapping relationship between the target heartbeat data of the target long connection task and the node in the available state.
[0088] Among them, the target heartbeat instance is used to describe: the mapping relationship between the target heartbeat data of the target long connection task and the node in the available state. That is, a heartbeat instance can include at least one node, and when there is a node in the available state in the heartbeat instance, the heartbeat instance can describe the mapping relationship between the node in the available state and the heartbeat data of the long connection task. Specifically as in the above example, for example, there is a heartbeat instance B1, and the heartbeat instance B1 includes the master node A1. If the heartbeat instance B1 has a heartbeat data transmission relationship with the long connection task C1, and the master node A1 receives the heartbeat data D1 transmitted by the long connection task C1 through the heartbeat instance B1, then the heartbeat instance B1 can be used to describe: the mapping relationship between the master node A1 in the available state and the heartbeat data D1 of the long connection task C1.
[0089] Specifically, by traversing each heartbeat instance, the heartbeat instance including the node to be switched is determined to be the target heartbeat instance, that is, the target heartbeat instance to which the node to be switched belongs is determined. For example, the heartbeat instance B1 includes the master node A1, the heartbeat instance B2 includes the master node A2, and the heartbeat instance B3 includes the master node A3. The node to be switched is determined to be the master node A2 by the method described in the aforementioned embodiment, then the server can determine the heartbeat instance B2 to which the node to be switched (i.e., the master node A2) belongs as the target heartbeat instance.
[0090] Step 604: register the standby node to the target heartbeat instance, and switch the mapping object of the target persistent connection task in the target heartbeat instance from the node to be switched to the standby node.
[0091] Specifically, the server registers the standby node to the target heartbeat instance, and in the process of completing the registration of the standby node to the target heartbeat instance, adjusts the node state of the standby node from the isolated state to the available state, that is, manages the standby node in the available state as the new master node. Further, the server switches the mapping object of the target long connection task in the target heartbeat instance from the node to be switched to the standby node, that is, switches the mapping object described by the target heartbeat instance and the target heartbeat data of the target long connection task from the node to be switched to the standby node.
[0092] For example, there is a heartbeat instance B1, and the heartbeat instance B1 includes the master node A1. If there is a heartbeat data transmission relationship between the heartbeat instance B1 and the long connection task C1, and the master node A1 receives the heartbeat data D1 transmitted by the long connection task C1 through the heartbeat instance B1, then when the master node A1 is determined to be the node to be switched, the heartbeat instance B1 can be determined to be the target heartbeat instance B1, and the heartbeat instance B1 is used to describe: the mapping relationship between the master node A1 in an available state and the heartbeat data D1 of the long connection task C1. Therefore, in the process of modifying the mapping object, it is specifically necessary to switch the mapping object of the heartbeat data D1 of the long connection task C1 from the node to be switched (that is, the master node A1) to the standby node. The heartbeat instance B1 after successfully completing the switching of the mapping object is used to describe: the mapping relationship between the standby node in an available state and the heartbeat data D1 of the long connection task C1.
[0093] Based on this, the target long connection tasks are managed through the standby node, including.
[0094] Step 606: Based on the target heartbeat instance, the target heartbeat data is received through the standby node.
[0095] Specifically, the server receives the target heartbeat data of the target long connection task through the standby node based on the target heartbeat instance. For ease of understanding, further introduction is given based on the above example. Before modifying the mapping relationship, the heartbeat data D1 is received through the master node A1 based on the heartbeat instance B1. After the mapping relationship modification is completed, since the mapping object of the heartbeat data D1 has been switched from the node to be switched (i.e., the master node A1) to the standby node, the server will receive the heartbeat data D1 through the standby node based on the heartbeat instance B1 to ensure stable reception and processing of the heartbeat data D1.
[0096] In this embodiment, by determining the target heartbeat instance to which the node to be switched belongs, the mapping relationship between the target heartbeat data described by the target heartbeat example and the node to be switched can be obtained. Therefore, the mapping object of the target heartbeat data is directly modified and adjusted in the target heartbeat instance, so that the heartbeat data corresponding to the node to be switched can be received and switched more accurately and reliably, thereby ensuring the reliability and stability of heartbeat data reception in the task management process, and further improving the stability of managing long connection tasks.
[0097] The following describes in detail how to register the standby node to the target heartbeat instance: In one embodiment, Figure 7 As shown, register the standby node to the target heartbeat instance, including:
[0098] Step 702: If the network protocol information of the standby node does not exist in the target heartbeat instance, determine the target routing instance to which the node to be switched belongs.
[0099] The routing instance is used to represent that a node in an available state processes a request for a persistent connection task with a mapping relationship. Therefore, the target routing instance is used to represent that a node to be switched in an available state processes a request for a target persistent connection task.
[0100] Specifically, when the server registers the standby node to the target heartbeat instance, the server needs to first determine whether the network protocol information of the standby node exists in the target heartbeat instance. If not, the server determines the target routing instance to which the node to be switched belongs. The aforementioned network protocol information is specifically an IP address (Internet Protocol Address, IPAddress).
[0101] Furthermore, before determining whether the network protocol information of the standby node exists in the target heartbeat instance, the server can also determine whether there is a node in the target heartbeat instance in an available state. If not, the server further determines whether the network protocol information of the standby node exists in the target heartbeat instance. On the contrary, if it exists, and the node in the available state is not the node to be switched, the node to be switched can be directly replaced with the node in the available state in the target heartbeat instance, that is, the mapping object of the target heartbeat data of the target long connection task is directly modified to the node in the available state in the target heartbeat instance.
[0102] Step 704: If there is an available route in the target routing instance and the network protocol information of the standby node does not exist in the target routing instance, register the standby node in the target heartbeat instance.
[0103] Specifically, the server needs to further determine whether there is an available route in the target routing instance. If so, that is, when there is an available route in the target routing instance, there may be a problem that the node to be switched has not completely exited the target routing instance, and a system alarm needs to be processed. On the contrary, if not, the server further determines whether there is network protocol information of the standby node in the target routing instance. If not, the standby node is registered in the target heartbeat instance, so that the standby node can receive the target heartbeat data periodically transmitted by the target long connection task.
[0104] In this embodiment, by judging whether the network protocol information of the standby node exists in the target heartbeat instance, repeated registration of the same node in the same heartbeat instance is avoided, and then judging whether the standby node can be registered in the target routing instance, thereby ensuring that in the process of managing the long connection task, the request sent by the target long connection task can be accurately received and processed, thereby improving the stability and reliability of the management of the long connection task.
[0105] It can be seen from the above embodiments that managing a persistent connection task at least includes: receiving heartbeat data of a persistent connection task, and processing a request for a persistent connection task. That is, in the process of managing a persistent connection task, the server should also process the request for a persistent connection task through a routing instance. The following will be described based on this: In one embodiment, if Figure 8 As shown, the method for managing long connection tasks also includes:
[0106] Step 802: If the duration for which the standby node successfully receives the target heartbeat data reaches a receiving duration threshold, the standby node is registered in the target routing instance.
[0107] Among them, the duration of successfully receiving the target heartbeat data is used to describe: the time when the node receives the target heartbeat data to the real-time recording time when the standby node continues to receive the target heartbeat data. The receiving duration threshold can be 10 seconds, 20 seconds or even 30 seconds. The specific receiving duration threshold needs to be determined according to the sending cycle of the target heartbeat data, which is not limited here.
[0108] Specifically, after completing the registration of the standby node to the target heartbeat instance and being able to receive the target heartbeat data through the standby node based on the target heartbeat instance, considering that the complete heartbeat data needs to be applied when processing the request, such as applying it to the live recording task management scenario, when playback display and video editing are required, the complete heartbeat data needs to be applied. Therefore, the basis for successfully processing the request of the target long connection task is to receive the complete heartbeat data.
[0109] Based on this, the server starts timing when the standby node receives the target heartbeat data. If the duration of successfully receiving the target heartbeat data reaches the receiving duration threshold, it means that the standby node has been able to receive the complete heartbeat data. At this time, the standby node is registered to the target routing instance, so that the standby node can accurately process the request of the target long connection task.
[0110] Step 804: Based on the target routing instance, the request for the target persistent connection task is processed by the standby node.
[0111] Specifically, after the server successfully registers the standby node to the target routing instance, when the user issues a request for the target persistent connection task, the server can process the request for the target persistent connection task through the standby node based on the target routing instance.
[0112] In this embodiment, the standby node will be registered with the target routing instance only when the duration for which the standby node successfully receives the target heartbeat data reaches the reception duration threshold. At this time, based on the target routing instance, the request for the target long connection task is processed by the standby node, which ensures that the standby node can process the request through complete heartbeat data, further improving the stability and reliability of managing long connection tasks.
[0113] The following will describe in detail the circumstances under which the node status of the master node is adjusted from the available state to the isolated state: In one embodiment, if Fig. 9 As shown, the method for managing long connection tasks also includes:
[0114] Step 902, obtain at least one of the task management information and task status results of each master node; the task management information represents the information when the master node manages the long connection task with a mapping relationship, and the task status result is used to represent the result corresponding to the status query of the long connection task with a mapping relationship performed by the master node.
[0115] Among them, the task management information represents the information when the master node manages the long connection task with a mapping relationship. It can be seen from the above embodiments that the management of the long connection task at least includes: receiving the heartbeat data of the long connection task, and processing the request of the long connection task. Therefore, the task management information can also describe the information under management from the above two dimensions, that is, the task management information can specifically represent: the information when the master node processes the request for the long connection task with a mapping relationship, and the result of the master node receiving the target heartbeat data for the long connection task with a mapping relationship.
[0116] Secondly, the task status result is used to characterize the result corresponding to the status query of the master node for the long connection task with a mapping relationship. It can be seen from the aforementioned embodiments that the master node can periodically report its own node status to the server, and the server can also actively query the node status of each master node. Therefore, in the case where the server fails to actively query the node status of the node, it is determined that the task status result represents the failure of the status query. Alternatively, the master node does not report the node status to the server according to the cycle duration, in which case it can also be determined that the task status result represents the failure of the status query.
[0117] Specifically, the server obtains at least one of the task management information and task status results of each master node, that is, the server can obtain the information of the management of the long connection task with the mapping relationship by the master node, thereby completing the acquisition of the task management information. Alternatively, the server can obtain the corresponding result of the status query of the long connection task with the mapping relationship, thereby completing the acquisition of the task status result. The server can obtain the task management information and the task status result at the same time, or obtain either the task management information or the task status result, which is not limited here.
[0118] Step 904: When the task management information or the task status result indicates that the master node is abnormal, the node status of the abnormal master node is adjusted from an available state to an isolated state.
[0119] Specifically, since the service can obtain at least one of the task management information and task status results of each master node, when judging whether there is an abnormality in the master node, any one of the task management information and task status results can be used for judgment. That is, when the server determines that the task management information or the task status result indicates that there is an abnormality in the master node, the node status of the abnormal master node can be adjusted from an available state to an isolated state.
[0120] Furthermore, if the task management information indicates that there is an abnormality in the master node, then the node state of the master node with the abnormality will be adjusted from the available state to the isolated state. At this time, the server may detect that the task management information indicates that there is an abnormality in the master node, thereby adjusting the node state of the master node with the abnormality from the available state to the isolated state. The master node may also monitor its own task management information indicating that there is an abnormality in itself, and then actively adjust its own node state from the available state to the isolated state, and actively report the updated node state to the server.
[0121] In this embodiment, it is possible to determine whether there is an abnormality in the master node through either task management information or task status results, that is, it is possible to determine from the dimension of the master node managing the long connection task and the dimension of status query on the master node. Task management can describe the network connection between the master node and the long connection task and the processing status of the master node itself, while status query can describe the network connection status between the master node and the server. In this way, various possibilities that may cause task abnormalities in actual applications can be taken into account, thereby ensuring that the node whose status is adjusted does indeed have an abnormality, so as to improve the reliability of management of long connection tasks.
[0122] The following describes in detail a specific implementation method of using task management information to indicate that the master node has an abnormality: In one embodiment, Fig.10 As shown, when the task management information or the task status result indicates that the master node is abnormal, the method for managing the long connection task also includes:
[0123] Step 1002, determine the task processing information and data reception results in the task management information of the master node; the task processing information is used to represent the information when the master node processes a request for a long connection task with a mapping relationship, and the data reception result is used to represent the result of the master node receiving the target heartbeat data for the long connection task with a mapping relationship.
[0124] Among them, it can be known from the above embodiments that the task management information can also describe the information under management from two dimensions. Therefore, the task management information specifically includes task processing information and data reception results, and the task processing information is used to represent the information under the condition that the master node processes the request for the long connection task with the mapping relationship, and the data reception result is used to represent the result of the master node receiving the heartbeat data for the long connection task with the mapping relationship. Specifically, the server specifically extracts the task processing information and the data reception result from the task management information of the master node.
[0125] Step 1004: The master node whose task processing information is normal but whose data reception result is abnormal is determined as an abnormal master node.
[0126] Among them, normal task processing is used to describe: the master node performs normal request processing on the long connection task with a mapping relationship. Then abnormal task processing is used to describe: the master node cannot perform normal request processing on the long connection task with a mapping relationship.
[0127] Secondly, data reception anomaly is used to describe: the time it takes for the master node to receive the heartbeat data for a long connection task with a mapping relationship exceeds the heartbeat reporting time. And normal data reception is used to describe: within the heartbeat reporting time, the master node successfully receives the heartbeat data sent by the long connection task with a mapping relationship. For example, when the heartbeat reporting time is 30 seconds, if the master node receives the heartbeat data for the long connection task with a mapping relationship, and the next heartbeat data is not successfully transmitted after more than 30 seconds, then it can be determined that the data reception is abnormal. It is understandable that the heartbeat reporting time can also be a time interval of 1 minute, 20 seconds, etc., which needs to be flexibly determined based on actual conditions.
[0128] Specifically, the server makes the following judgment on the task processing information and data reception results of each master node: judge whether the task processing information shows that the task processing is normal, and whether the data reception result shows that the data reception is abnormal. Then, based on the judgment result, the master node whose task processing information shows that the task processing is normal but whose data reception result shows that the data reception is abnormal is determined as the master node with the abnormality. Optionally, the server can also directly determine the node whose task processing information shows that the task processing is abnormal as the master node with the abnormality, that is, in this case, the master node with the abnormality cannot perform normal request processing on the long connection task with the mapping relationship.
[0129] For example, there are master nodes A1, A2, and A3. Master node A1 corresponds to task processing information E1 and data reception result F1, master node A2 corresponds to task processing information E2 and data reception result F2, and master node A3 corresponds to task processing information E3 and data reception result F3. If task processing information E1 indicates that the task processing of master node A1 is normal, and data reception result F1 indicates that data reception of master node A1 is normal, then master node A1 is a normal node. If task processing information E2 indicates that the task processing of master node A2 is abnormal, then master node A2 is abnormal. If task processing information E3 indicates that the task processing of master node A3 is normal, and data reception result F3 indicates that data reception of master node A3 is abnormal, then master node A3 is abnormal.
[0130] In this embodiment, the dimension of managing the long connection task from the master node is specifically judged from two more fine-grained dimensions: the completion result of the master node processing the request, and the reception result of the heartbeat data received by the master node. The processing status of the master node itself is determined by the completion result of the master node processing the request, and the network connection status between the master node and the long connection task is determined by the reception result of the heartbeat data received by the master node. The possibility of causing task abnormalities in actual applications is considered in more detail to ensure that the determined nodes with abnormalities are more reliable, so as to further improve the reliability of the management of long connection tasks.
[0131] Since in actual applications, there are situations where multiple tasks in a long connection state are processed simultaneously, the following describes in detail how to use task management information to indicate that the master node has an abnormality when multiple tasks in a long connection state are processed simultaneously: In one embodiment, Fig.11 As shown, the long connection task includes multiple long connection subtasks.
[0132] Among them, the long connection subtask is a task in a long connection state, and the task types of multiple long connection subtasks belonging to the same long connection task are consistent. For example, the long connection task C1 is specifically a live recording task, that is, the task type of the long connection task C1 is live recording, and the long connection task C2 is specifically a real-time chat task, that is, the task type of the long connection task C2 is real-time chat. Based on this, if the long connection task C1 includes the long connection subtask G1, the long connection subtask G2 and the long connection subtask G3, then the long connection subtask G1 to the long connection subtask G3 are all live recording tasks. Similarly, if the long connection task C2 includes the long connection subtask G4 and the long connection subtask G5, then the long connection subtask G4 and the long connection subtask G5 are both real-time chat tasks.
[0133] Based on this, when the task management information or the task status result indicates that the master node is abnormal, the method for managing the long connection task also includes:
[0134] Step 1102, determining the task management sub-information corresponding to each long connection sub-task in the task management information of the master node.
[0135] Among them, similar to the task management information, since the task management information represents the information when the master node manages the long connection task with a mapping relationship, and the task management information specifically includes the task processing information and the data receiving result. Therefore, the task management sub-information is also used to represent: the information when the master node manages the long connection sub-task with a mapping relationship, and the task management sub-information specifically includes the task processing sub-information and the data receiving sub-result. The task processing sub-information is used to represent the information when the master node processes the request for the long connection sub-task with a mapping relationship, and the data receiving sub-result is used to represent the result of the master node receiving the target heartbeat data for the long connection sub-task with a mapping relationship.
[0136] Specifically, the server first determines the long connection tasks that have a mapping relationship with each master node. When the long connection task is a single task in a long connection state, the server uses the method described in the above embodiment to determine the master node with an abnormality through the task management information. When the long connection task is multiple tasks in a long connection state, that is, the long connection task includes multiple long connection subtasks, the server will determine the task management sub-information corresponding to each long connection subtask in the task management information of the master node.
[0137] For example, the long connection task C1 includes the long connection subtask G1, the long connection subtask G2 and the long connection subtask G3. If there is a mapping relationship between the main node A1 and the long connection task C, then the task management information of the main node A1 specifically includes: the task management sub-information corresponding to the long connection subtask G1, the task management sub-information corresponding to the long connection subtask G2, and the task management sub-information corresponding to the long connection subtask G3.
[0138] Step 1104 , count the total number of tasks of the long connection subtasks, and count the number of task exceptions of the long connection subtasks corresponding to the task management sub-information representation.
[0139] Among them, the total number of tasks of the long connection subtask is specifically the total number of long connection subtasks in the long connection task. For example, the long connection task C1 that has a mapping relationship with the main node A1 includes: long connection subtask G1, long connection subtask G2 and long connection subtask G3, so the total number of tasks of the long connection subtask of the main node A1 is 3. For example, the long connection task C2 that has a mapping relationship with the main node A2 includes: long connection subtask G4 and long connection subtask G5, so the total number of tasks of the long connection subtask of the main node A2 is 2.
[0140] Secondly, the number of task exceptions is used to represent: the total number of long connection subtasks that have abnormalities among multiple long connection subtasks belonging to the same long connection task. For example, the long connection task C1 that has a mapping relationship with the main node A1 includes: long connection subtask G1, long connection subtask G2 and long connection subtask G3. If long connection subtask G2 and long connection subtask G3 both have abnormalities, then it can be determined that the number of task exceptions of the main node A1 is 2.
[0141] Specifically, the server counts the total number of long connection subtasks in the long connection task that has a mapping relationship with the main node to determine the total number of tasks, and counts the number of long connection subtasks in the long connection task that has a mapping relationship with the main node that have abnormalities to determine the number of task abnormalities. It can be understood that the method of representing the abnormality of the long connection subtask corresponding to the task management sub-information is similar to the aforementioned embodiment, that is, the long connection subtask with normal task processing and abnormal data reception in the task management sub-information is determined as the abnormal long connection subtask, and the long connection subtask with abnormal task processing in the task management sub-information is determined as the abnormal long connection subtask, which will not be repeated here.
[0142] Step 1106, calculating the ratio between the number of abnormal tasks and the total number of tasks to obtain the task abnormality ratio.
[0143] Specifically, the server calculates the ratio between the number of task anomalies and the total number of tasks to obtain the task anomaly ratio. The task anomaly ratio specifically represents the ratio of the number of task anomalies to the total number of tasks. For example, based on the above example, the total number of tasks of the long connection subtask of the master node A1 is 3, and the number of task anomalies of the master node A1 is 2, so it can be determined that the task anomaly ratio of the master node A1 is 2 / 3.
[0144] Step 1108, the master node whose task abnormality ratio reaches the task abnormality threshold is determined as an abnormal master node.
[0145] Among them, the task abnormality threshold is a pre-set value, and the task abnormality threshold is usually the minimum value of the task abnormality ratio. Specifically, the server determines the master node whose task abnormality ratio reaches the task abnormality threshold as the master node with abnormality. For example, taking the task abnormality threshold of 50% as an example, and the task abnormality ratio of the master node A1 is 2 / 3, the task abnormality ratio of the master node A2 is 1 / 2, and the task abnormality ratio of the master node A3 is 1 / 4, it can be determined that the task abnormality ratio of the master node A1 reaches the task abnormality threshold, and the task abnormality ratio of the master node A2 reaches the task abnormality threshold, so it can be determined that the master node A1 and the master node A2 are both master nodes with abnormalities. It can be understood that the task abnormality threshold exemplified in this embodiment is 50%, and in actual applications, the task abnormality threshold can be 60%, 70% and other values set based on actual application requirements, which are not specifically limited here.
[0146] In this embodiment, when processing multiple tasks in a long connection state at the same time, the proportion of abnormalities in the corresponding long connection subtasks represented by the task management sub-information is used to determine whether there is an abnormality in each main node, thereby avoiding the situation where only a small number of abnormal tasks among multiple long connection subtasks are judged as abnormal, improving the reliability and accuracy of node abnormality judgment, thereby improving the reliability and accuracy of subsequent state adjustments, that is, the reliability and accuracy of the management of long connection tasks can be further improved.
[0147] The following will describe in detail a specific implementation method of characterizing the abnormality of the master node through the data reception result when processing multiple tasks in the long connection state at the same time: In one embodiment, Fig.12 As shown, the long connection task includes multiple long connection subtasks.
[0148] Similar to the above-mentioned embodiment, the long connection subtask is a task in a long connection state, and the task types of multiple long connection subtasks belonging to the same long connection task are consistent. The details will not be repeated here.
[0149] Based on this, when the task management information or the task status result indicates that the master node is abnormal, the method for managing the long connection task also includes:
[0150] Step 1202, obtaining the task status sub-results corresponding to each long connection sub-task in the task status result of the master node.
[0151] Among them, similar to the task status result, since the task status result is used to characterize the result corresponding to the status query of the master node for the long connection task with a mapping relationship. Therefore, the task status sub-result is also used to characterize the result corresponding to the status query of the master node for the long connection sub-task with a mapping relationship. Secondly, it can be seen from the aforementioned embodiment again that the master node can periodically report its own node status to the server, and the server can also actively query the node status of each master node. Therefore, when the server actively queries the node corresponding to the long connection task with a mapping relationship, the node status corresponding to the long connection task with a mapping relationship is in a failed state, so as to determine that the task status sub-result represents the failure of the status query. Alternatively, the master node does not report the node status corresponding to the long connection task with a mapping relationship to the server according to the periodic duration, and at this time it can also be determined that the task status sub-result represents the failure of the status query.
[0152] Specifically, the server first determines the long connection tasks that have a mapping relationship with each master node. When the long connection task is a single task in a long connection state, the method described in the above embodiment is used to determine the master node with an abnormality through the task status result. When the long connection task is multiple tasks in a long connection state, that is, the long connection task includes multiple long connection subtasks, the server will determine the task status subresults corresponding to each long connection subtask in the task status result of the master node.
[0153] For example, the long connection task C1 includes the long connection subtask G1, the long connection subtask G2 and the long connection subtask G3. If there is a mapping relationship between the main node A1 and the long connection task C, then the task status result of the main node A1 specifically includes: the task status subresult corresponding to the long connection subtask G1, the task status subresult corresponding to the long connection subtask G2, and the task status subresult corresponding to the long connection subtask G3.
[0154] Step 1204 , count the total number of tasks of the long connection subtasks, and count the number of query exceptions of the long connection subtasks corresponding to the task status subresult representation that failed to perform status query.
[0155] Among them, the total number of tasks of the long connection subtask is specifically the total number of long connection subtasks in the long connection task. For example, the long connection task C1 that has a mapping relationship with the main node A1 includes: long connection subtask G1, long connection subtask G2 and long connection subtask G3, so the total number of tasks of the long connection subtask of the main node A1 is 3. For example, the long connection task C3 that has a mapping relationship with the main node A3 includes: long connection subtask G6, long connection subtask G7, long connection subtask G8 and long connection subtask G9, so the total number of tasks of the long connection subtask of the main node A3 is 4.
[0156] Secondly, the number of query exceptions is used to characterize: the total number of long connection subtasks that failed to perform status query among multiple long connection subtasks belonging to the same long connection task. For example, the long connection task C3 that has a mapping relationship with the main node A3 includes: long connection subtask G6, long connection subtask G7, long connection subtask G8 and long connection subtask G9. If the status query of long connection subtask G9 fails, then it can be determined that the number of task exceptions of the main node A3 is 1.
[0157] Specifically, the server counts the total number of long connection subtasks in the long connection task that has a mapping relationship with the main node to determine the total number of tasks, and counts the total number of long connection subtasks that fail to perform status queries among multiple long connection subtasks of the long connection task that has a mapping relationship with the main node to determine the number of query exceptions.
[0158] Furthermore, the failure of the status query of the long connection subtask corresponding to the task status subresult representation is similar to the above-mentioned embodiment, that is, when the server fails to actively query the node status of the master node corresponding to the long connection subtask, it is determined that the task status subresult representation status query has failed. Alternatively, the master node corresponding to the long connection subtask does not report the node status to the server according to the cycle duration, in which case it can also be determined that the task status subresult representation status query has failed, which will not be repeated here.
[0159] Step 1206, calculating the ratio between the number of query anomalies and the total number of tasks to obtain a query anomaly ratio.
[0160] Specifically, the server calculates the ratio between the number of query anomalies and the total number of tasks to obtain the task anomaly ratio. The task anomaly ratio specifically represents the ratio of the number of query anomalies to the total number of tasks. For example, based on the above example, the total number of tasks of the long connection subtask of the master node A3 is 4, and the number of task anomalies of the master node A3 is 1, so it can be determined that the task anomaly ratio of the master node A3 is 1 / 4.
[0161] Step 1208: The master node whose query anomaly ratio reaches the query anomaly threshold is determined as an abnormal master node.
[0162] Among them, the query anomaly threshold is a pre-set value, and the query anomaly threshold is usually the minimum value of the query anomaly ratio. Specifically, the server determines the master node whose query anomaly ratio reaches the query anomaly threshold as a master node with an abnormality. For example, taking the query anomaly threshold of 60% as an example, and the query anomaly ratio of master node A1 is 2 / 3, the query anomaly ratio of master node A2 is 1 / 2, and the query anomaly ratio of master node A3 is 1 / 4, it can be determined that the query anomaly ratio of master node A1 reaches the query anomaly threshold, so it can be determined that master node A1 is a master node with an abnormality. It can be understood that the query anomaly threshold exemplified in this embodiment is 60%, and in actual applications, the query anomaly threshold can be 50%, 70% or other values set based on actual application requirements, which are not specifically limited here.
[0163] In this embodiment, when processing multiple tasks in a long connection state at the same time, the proportion of status query failures of the corresponding long connection subtasks represented by the task status sub-result is used to determine whether there is an abnormality in each main node. From another dimension, it is avoided that only a small number of abnormal tasks among multiple long connection subtasks are subjected to abnormal judgment, so as to improve the reliability and accuracy of node abnormality judgment, thereby improving the reliability and accuracy of subsequent status adjustments, that is, the reliability and accuracy of the management of long connection tasks can be further improved.
[0164] In one embodiment, Fig.13 As shown, when the task management information or the task status result indicates that the master node is abnormal, the method for managing the long connection task also includes:
[0165] Step 1302: The task status result characterizes the master node that fails to query the status of the long connection task with the mapping relationship, and determines it as an abnormal master node.
[0166] Specifically, when the long connection status task is a single long connection status task, the task status result characterizes that the master node that failed to query the status of the long connection task with a mapping relationship is determined as an abnormal master node. For example, if the master nodes A1, A2, and A3 are all single long connection status tasks, if the task status result characterizes that the master node A1 failed to query the status of the long connection task with a mapping relationship, the task status result characterizes that the master node A2 successfully queryed the status of the long connection task with a mapping relationship, and the task status result characterizes that the master node A3 successfully queryed the status of the long connection task with a mapping relationship, then the master node A1 that failed the status query can be determined as an abnormal master node.
[0167] As described in the above embodiment, when the server fails to actively query the node status of the node, it is determined that the task status result indicates that the status query has failed. Alternatively, if the master node does not report the node status to the server according to the cycle duration, it can also be determined that the task status result indicates that the status query has failed. That is, it can be determined that the task status result indicates that the status query has failed in the above manner.
[0168] In this embodiment, when the long connection status task is a single long connection status task, it is directly determined whether the status query of the master node is successful through the task status result, so as to determine that the node that cannot successfully perform the status query is the master node with an abnormality, and the master node with an abnormality is determined more accurately and efficiently from the status query dimension, thereby improving the accuracy of managing long connection tasks.
[0169] The following describes how to configure the standby node and the master node: In one embodiment, Fig.14 As shown, the method for managing long connection tasks also includes:
[0170] Step 1402, obtaining multiple nodes to be configured and node configuration files.
[0171] The node to be configured is a node that has not been configured with a node state. The node configuration file is used to configure the initial node state for the node, and the node configuration file is a pre-set json file. For example, the node configuration file is:
[0172] {
[0173] "main_servers":["ip1","ip2"],
[0174] “backup_server”:”ip3”
[0175] }
[0176] Specifically, the server obtains multiple nodes to be configured and node configuration files. The server can determine the nodes to be configured and obtain the node configuration files from a data storage system with a communication connection, or it can determine the nodes to be configured through the node configuration files and related node configuration instructions input by an external connection device, which is not limited here.
[0177] Step 1404: configure the corresponding initial node state for each node to be configured through the node configuration file.
[0178] Among them, the initial node state is an available state or an isolated state. Specifically, the server configures each corresponding initial node state for each node to be configured through the node configuration file. That is, the node configuration file can be used to determine the initial node state corresponding to each node to be configured. For example, there are nodes to be configured H1, nodes to be configured H2, and nodes to be configured H3, and the initial node state configured by the node configuration file for the node to be configured H1 is an available state, the initial node state configured by the node configuration file for the node to be configured H2 is an isolated state, and the initial node state configured by the node configuration file for the node to be configured H3 is an available state.
[0179] Step 1406: determine the node to be configured whose initial node status is available as the master node, and determine the node to be configured whose initial node status is isolated as the standby node.
[0180] Specifically, the server determines the node to be configured whose initial node status is available as the primary node, and determines the node to be configured whose initial node status is isolated as the backup node. As can be seen from the above example, if the node configuration file configures the initial node status of the node to be configured H1 as available, the node configuration file configures the initial node status of the node to be configured H2 as isolated, and the node configuration file configures the initial node status of the node to be configured H3 as available, then the node to be configured H1 in available state and the node to be configured H3 in available state are determined as the primary node, and the node to be configured H2 in isolated state is determined as the backup node.
[0181] It is understandable that the aforementioned configuration method can be performed before performing long connection task management, and the determined standby node and master node are registered in the name server. And the aforementioned configuration method can also be performed when performing long connection task management, that is, when there is no master node and standby node registered in the name server, the server configures the standby node and master node in real time through the aforementioned method, and then registers the standby node and master node obtained by real-time configuration in the name server. The specific implementation sequence of the aforementioned configuration method is not limited in this embodiment.
[0182] In this embodiment, the initial node state is configured for the node to be configured through the node configuration file, and the backup node and the main node are configured through the initial node state to ensure that the main node can manage the long connection tasks with a mapping relationship, and the backup node can obtain the node state of each main node, further ensuring the accuracy and reliability of the long connection task management.
[0183] Based on the detailed description of the foregoing embodiment, the complete process of the method for managing long connection tasks in the embodiment of the present application will be described below. In one embodiment, Fig.15As shown, a method for managing long connection tasks is provided, and the method is applied to Figure 2 The server 204 in the example is used for explanation. It is understandable that the method can also be applied to the terminal 202, and can also be applied to a system including the terminal 202 and the server 204, and is implemented through the interaction between the terminal 202 and the server 204. In this embodiment, a long connection task including multiple long connection subtasks is used as an example for introduction. In this embodiment, the method includes the following steps:
[0184] Step 1501, obtaining a backup node and multiple master nodes in a long connection task management scenario.
[0185] Among them, the long connection task management scenario is specifically: the scenario of managing tasks in the long connection state. Secondly, the master node is used to manage the long connection tasks with mapping relationships, and the standby node is used to obtain the node status of each master node.
[0186] Specifically, the server obtains a backup node and multiple master nodes in the long connection task management scenario. Before performing long connection task management, the server can first configure the master node and the backup node, that is, configure the node status of each node to be configured through the node configuration file, and then configure the node configured in the available state as the master node, and configure the node configured in the isolated state as the backup node, and register the node in the available state (i.e., the master node) and the node in the isolated state (i.e., the backup node) to the name server. Therefore, in the process of performing long connection task management, the master node that can manage the long connection task with a mapping relationship can be obtained from the name server, and the backup node can be obtained from the name server.
[0187] Optionally, when the master node and the backup node are not registered in the name server, the server can also configure the master node and the backup node in real time to obtain the backup node and multiple master nodes in the long connection task management scenario, so as to manage the long connection tasks with mapping relationships through the master node, and obtain the node status of each master node through the backup node. The method of obtaining the backup node and multiple master nodes in the long connection task management scenario is not limited here.
[0188] Step 1502, obtaining at least one of the task management information and task status results of each master node.
[0189] Among them, the task management information represents the information when the master node manages the long connection task with a mapping relationship. Based on this, since the management of the long connection task at least includes: receiving the heartbeat data of the long connection task, and processing the request of the long connection task. Therefore, the task management information specifically includes task processing information and data reception results, and the task processing information is used to represent the information when the master node processes the request for the long connection task with a mapping relationship, and the data reception result is used to represent the result of the master node receiving the heartbeat data for the long connection task with a mapping relationship. Secondly, the task status result is used to represent the corresponding result of the master node's status query on the long connection task with a mapping relationship.
[0190] Specifically, the server obtains at least one of the task management information and task status results of each master node, that is, the server can obtain the information of the management of the long connection task with the mapping relationship by the master node, thereby completing the acquisition of the task management information. Alternatively, the server can obtain the corresponding result of the status query of the long connection task with the mapping relationship, thereby completing the acquisition of the task status result. The server can obtain the task management information and the task status result at the same time, or obtain either the task management information or the task status result, which is not limited here.
[0191] Step 1503: determine the task management sub-information corresponding to each long connection sub-task in the task management information of the master node.
[0192] Among them, the task management sub-information is also used to represent: the information when the master node manages the long connection sub-task with a mapping relationship, and the task management sub-information specifically includes task processing sub-information and data receiving sub-result. The task processing sub-information is used to represent the information when the master node processes the request for the long connection sub-task with a mapping relationship, and the data receiving sub-result is used to represent the result of the master node receiving the target heartbeat data for the long connection sub-task with a mapping relationship.
[0193] Specifically, the server first determines the long connection tasks that have a mapping relationship with each master node. When the long connection task is a single task in a long connection state, the server uses the method described in the above embodiment to determine the master node with an abnormality through the task management information. When the long connection task is multiple tasks in a long connection state, that is, the long connection task includes multiple long connection subtasks, the server will determine the task management sub-information corresponding to each long connection subtask in the task management information of the master node.
[0194] Step 1504 , count the total number of tasks of the long connection subtasks, and count the number of task exceptions of the long connection subtasks corresponding to the task management sub-information representation.
[0195] The total number of tasks of the long connection subtask is specifically the total number of long connection subtasks in the long connection task, and the number of task exceptions is used to represent: the total number of long connection subtasks with exceptions among multiple long connection subtasks belonging to the same long connection task.
[0196] Specifically, the server counts the total number of long connection subtasks in the long connection task that has a mapping relationship with the main node to determine the total number of tasks, and counts the number of abnormal long connection subtasks in the long connection task that has a mapping relationship with the main node to determine the number of task abnormalities.
[0197] Step 1505, calculating the ratio between the number of abnormal tasks and the total number of tasks to obtain the task abnormality ratio.
[0198] Specifically, the server calculates the ratio between the number of abnormal tasks and the total number of tasks to obtain a task abnormality ratio. The task abnormality ratio specifically represents the ratio of the number of abnormal tasks to the total number of tasks.
[0199] Step 1506: The master node whose task abnormality ratio reaches the task abnormality threshold is determined as an abnormal master node.
[0200] The task abnormality threshold is a preset value, and the task abnormality threshold is usually the minimum value of the task abnormality ratio. Specifically, the server determines the master node whose task abnormality ratio reaches the task abnormality threshold as an abnormal master node.
[0201] Step 1507, obtaining the task status sub-results corresponding to each long connection sub-task in the task status result of the master node.
[0202] The task status sub-result is used to represent the result of the master node's status query on the long connection sub-task with a mapping relationship.
[0203] Specifically, the server first determines the long connection tasks that have a mapping relationship with each master node. When the long connection task is a single task in a long connection state, the method described in the above embodiment is used to determine the master node with an abnormality through the task status result. When the long connection task is multiple tasks in a long connection state, that is, the long connection task includes multiple long connection subtasks, the server will determine the task status subresults corresponding to each long connection subtask in the task status result of the master node.
[0204] Step 1508 , count the total number of tasks of the long connection subtasks, and count the number of query exceptions of the long connection subtasks corresponding to the task status subresult representation that failed to perform status query.
[0205] The total number of tasks of the long connection subtask is specifically the total number of long connection subtasks in the long connection task, and the number of query exceptions is used to represent: the total number of long connection subtasks that fail to perform status query among multiple long connection subtasks belonging to the same long connection task.
[0206] Specifically, the server counts the total number of long connection subtasks in the long connection task that has a mapping relationship with the main node to determine the total number of tasks, and counts the total number of long connection subtasks that fail to perform status queries among multiple long connection subtasks of the long connection task that has a mapping relationship with the main node to determine the number of query exceptions.
[0207] Step 1509, calculating the ratio between the number of query anomalies and the total number of tasks to obtain a query anomaly ratio.
[0208] Specifically, the server calculates the ratio between the number of query anomalies and the total number of tasks to obtain a task anomaly ratio. The task anomaly ratio specifically represents the ratio between the number of query anomalies and the total number of tasks.
[0209] Step 1510: The master node whose query anomaly ratio reaches the query anomaly threshold is determined as an abnormal master node.
[0210] The query anomaly threshold is a preset value, and the query anomaly threshold is usually the minimum value of the query anomaly ratio. Specifically, the server determines the master node whose query anomaly ratio reaches the query anomaly threshold as the master node with an abnormality.
[0211] Step 1511, adjusting the node state of the abnormal master node from the available state to the isolated state.
[0212] Among them, the available state is used to indicate that the node can manage the long connection tasks with a mapping relationship, and the isolated state is used to indicate that the node can obtain the node status of each master node. Specifically, the server determines through the aforementioned method that when the task management information or the task status result indicates that the master node is abnormal, the node status of the abnormal master node can be adjusted from the available state to the isolated state.
[0213] Step 1512: determine the primary node in the isolated state as the node to be switched.
[0214] Specifically, the server determines the primary node in an isolated state as the node to be switched, that is, the server determines the primary node that cannot normally manage the long connection task with a mapping relationship as the node to be switched, waiting for the backup node to replace the node to be switched for the corresponding mapping relationship.
[0215] Step 1513, determining a target persistent connection task that has a mapping relationship with the node to be switched, and determining a target heartbeat instance to which the node to be switched belongs.
[0216] The target long connection task is a long connection task that has a mapping relationship with the node to be switched, and the target heartbeat instance is used to describe: the mapping relationship between the target heartbeat data of the target long connection task and the node in an available state.
[0217] Specifically, the server determines a target persistent connection task that has a mapping relationship with the node to be switched, and determines the heartbeat instance including the node to be switched as the target heartbeat instance by traversing each heartbeat instance, that is, determines the target heartbeat instance to which the node to be switched belongs.
[0218] Step 1514: If the network protocol information of the standby node does not exist in the target heartbeat instance, determine the target routing instance to which the node to be switched belongs.
[0219] The routing instance is used to represent that a node in an available state processes a request for a persistent connection task with a mapping relationship. Therefore, the target routing instance is used to represent that a node to be switched in an available state processes a request for a target persistent connection task.
[0220] Specifically, when the server registers the standby node to the target heartbeat instance, the server needs to first determine whether the network protocol information of the standby node exists in the target heartbeat instance. If not, the server determines the target routing instance to which the node to be switched belongs.
[0221] Step 1515: If there is an available route in the target routing instance and the network protocol information of the standby node does not exist in the target routing instance, the standby node is registered in the target heartbeat instance, and the mapping object of the target long connection task in the target heartbeat instance is switched from the node to be switched to the standby node.
[0222] Specifically, the server needs to further determine whether there is an available route in the target routing instance. If so, that is, when there is an available route in the target routing instance, there may be a problem that the node to be switched has not completely exited the target routing instance, and a system alarm needs to be processed. On the contrary, if not, the server further determines whether there is network protocol information of the standby node in the target routing instance. If not, the standby node is registered in the target heartbeat instance, thereby switching the mapping object of the target long connection task in the target heartbeat instance from the node to be switched to the standby node, so that the standby node can receive the target heartbeat data periodically transmitted by the target long connection task.
[0223] Step 1516, based on the target heartbeat instance, receiving the target heartbeat data through the standby node.
[0224] Specifically, the server receives the target heartbeat data of the target long connection task through the standby node based on the target heartbeat instance.
[0225] Step 1517: If the duration for which the standby node successfully receives the target heartbeat data reaches the receiving duration threshold, the standby node is registered in the target routing instance.
[0226] Specifically, the server starts timing when the standby node receives the target heartbeat data. If the duration of successfully receiving the target heartbeat data reaches the receiving duration threshold, it means that the standby node has been able to receive the complete heartbeat data. At this time, the standby node is registered to the target routing instance, so that the standby node can accurately process the request of the target long connection task.
[0227] Step 1518: Based on the target routing instance, the request for the target persistent connection task is processed by the standby node.
[0228] Specifically, after the server successfully registers the standby node to the target routing instance, when the user issues a request for the target persistent connection task, the server can process the request for the target persistent connection task through the standby node based on the target routing instance.
[0229] It should be understood that the specific implementation of steps 1501 to 1518 are similar to the above-mentioned embodiments and will not be repeated here.
[0230] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0231] Based on the same inventive concept, the embodiment of the present application also provides a long connection task management device for implementing the long connection task management method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more long connection task management device embodiments provided below can refer to the limitations of the long connection task management method above, and will not be repeated here.
[0232] In one embodiment, Fig.16As shown, a long connection task management device is provided, including: a node acquisition module 1602, a node determination module 1604, a node update module 1606 and a task management module 1608, wherein:
[0233] The node acquisition module 1602 is used to acquire a standby node and multiple master nodes in a long connection task management scenario. The master node is used to manage the long connection tasks with a mapping relationship, and the standby node is used to acquire the node status of each master node.
[0234] The node determination module 1604 is configured to determine the master node in the isolated state as a node to be switched if the node state of at least one master node among the master nodes changes from the available state to the isolated state;
[0235] The node updating module 1606 is used to determine a target long connection task that has a mapping relationship with the node to be switched, and update the mapping object of the target long connection task from the node to be switched to the standby node;
[0236] The task management module 1608 is used to manage the target long connection task through the standby node.
[0237] In one embodiment, the node update module 1606 is specifically used to determine the target heartbeat instance to which the node to be switched belongs, and the target heartbeat instance is used to describe: the mapping relationship between the target heartbeat data of the target long connection task and the node in the available state; register the standby node to the target heartbeat instance, and switch the mapping object of the target long connection task in the target heartbeat instance from the node to be switched to the standby node;
[0238] The task management module 1608 is specifically configured to receive target heartbeat data through a standby node based on a target heartbeat instance.
[0239] In one embodiment, the node update module 1606 is specifically used to determine the target routing instance to which the node to be switched belongs if the network protocol information of the standby node does not exist in the target heartbeat instance; if there is an available route in the target routing instance and the network protocol information of the standby node does not exist in the target routing instance, register the standby node to the target heartbeat instance.
[0240] In one embodiment, the node updating module 1606 is further configured to register the standby node with the target routing instance if the duration for which the standby node successfully receives the target heartbeat data reaches a receiving duration threshold;
[0241] The task management module 1608 is also used to process the request of the target long connection task through the standby node based on the target routing instance.
[0242] In one embodiment, Fig.17As shown, the long connection task management device also includes an information acquisition module 1702 and a node state adjustment module 1704;
[0243] The information acquisition module 1702 is used to obtain at least one of the task management information and the task status result of each master node; the task management information represents the information when the master node manages the long connection task with the mapping relationship, and the task status result is used to represent the result corresponding to the status query of the long connection task with the mapping relationship by the master node;
[0244] The node status adjustment module 1704 is used to adjust the node status of the abnormal master node from the available state to the isolated state when the task management information or the task status result indicates that the master node is abnormal.
[0245] In one embodiment, Fig.18 As shown, the long connection task management device also includes an abnormal node determination module 1802;
[0246] The abnormal node determination module 1802 is used to determine the task processing information and data reception results in the task management information of the master node; the task processing information is used to represent the information when the master node processes a request for a long connection task with a mapping relationship, and the data reception result is used to represent the result of the master node receiving the target heartbeat data for the long connection task with a mapping relationship; a master node whose task processing information shows normal task processing but whose data reception result shows data reception abnormality is determined to be an abnormal master node.
[0247] In one embodiment, the long connection task includes a plurality of long connection subtasks;
[0248] The abnormal node determination module 1802 is also used to determine the task management sub-information corresponding to each long connection sub-task in the task management information of the main node; count the total number of tasks of the long connection sub-task, and count the number of task anomalies in the long connection sub-task corresponding to the task management sub-information representation; calculate the ratio between the number of task anomalies and the total number of tasks to obtain the task anomaly ratio; and determine the main node whose task anomaly ratio reaches the task anomaly threshold as the main node with an abnormality.
[0249] In one embodiment, the long connection task includes a plurality of long connection subtasks;
[0250] The abnormal node determination module 1802 is also used to obtain the task status sub-results corresponding to each long connection sub-task in the task status result of the main node; count the total number of tasks of the long connection sub-task, and count the number of query anomalies in which the status query of the long connection sub-task corresponding to the task status sub-result fails; calculate the ratio between the number of query anomalies and the total number of tasks to obtain the query anomaly ratio; and determine the main node whose query anomaly ratio reaches the query anomaly threshold as an abnormal main node.
[0251] In one embodiment, the abnormal node determination module 1802 is further used to determine the master node for which the task status result indicates that the status query of the long connection task with the mapping relationship fails as an abnormal master node.
[0252] In one embodiment, the task management module 1608 is specifically used to adjust the node state of the standby node from the isolated state to the available state; and manage the target long connection task through the standby node in the available state.
[0253] In one embodiment, Fig.19 As shown, the long connection task management device also includes a node processing module 1902;
[0254] The node processing module 1902 is used to suspend the management of the target long connection task by the node to be switched in the isolated state; the node to be switched in the isolated state is used as a new standby node, and the node status of each node that has a mapping relationship with the long connection task is obtained through the new standby node.
[0255] In one embodiment, Fig. 20 As shown, the long connection task management device also includes a node configuration module 2002;
[0256] The node configuration module is used to obtain multiple nodes to be configured and node configuration files; configure the corresponding initial node state for each node to be configured through the node configuration file; determine the node to be configured whose initial node state is available as the main node, and determine the node to be configured whose initial node state is isolated as the backup node.
[0257] Each module in the above-mentioned long connection task management device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0258] In one embodiment, a computer device is provided. The computer device may be a server or a terminal. In this embodiment, the computer device is a server as an example for explanation. The internal structure diagram thereof may be as follows: Fig.21As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Wherein, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Wherein, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store heartbeat data and node configuration files and other data related to the embodiment of the present application. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for long connection task management is implemented.
[0259] Those skilled in the art will understand that Fig.21 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0260] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0261] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0262] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0263] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the object or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0264] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0265] The technical feature information of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical feature information in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical feature information, they should be considered to be within the scope of this specification.
[0266] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for managing long connection tasks, characterized in that: include: Acquire a standby node and multiple master nodes in a long connection task management scenario, wherein the master node is used to manage the long connection tasks with a mapping relationship, and the standby node is used to obtain the node status of each of the master nodes; If the node state of at least one master node among the master nodes changes from an available state to an isolated state, the master node in the isolated state is determined as a node to be switched; Determine a target long connection task that has a mapping relationship with the node to be switched, and switch the mapping object of the target long connection task from the node to be switched to the standby node; The target long connection task is managed by the standby node.
2. The method according to claim 1, characterized in that The step of switching the mapping object of the target long connection task from the node to be switched to the standby node includes: Determine a target heartbeat instance to which the node to be switched belongs, where the target heartbeat instance is used to describe: a mapping relationship between the target heartbeat data of the target long connection task and the node in the available state; Registering the standby node to the target heartbeat instance, and switching the mapping object of the target long connection task in the target heartbeat instance from the node to be switched to the standby node; The managing the target long connection task by the standby node includes: Based on the target heartbeat instance, the target heartbeat data is received by the standby node.
3. The method according to claim 2, characterized in that The step of registering the standby node with the target heartbeat instance includes: If the network protocol information of the standby node does not exist in the target heartbeat instance, determining the target routing instance to which the node to be switched belongs; If there is an available route in the target routing instance and the network protocol information of the standby node does not exist in the target routing instance, the standby node is registered in the target heartbeat instance.
4. The method according to claim 2, characterized in that: The method further comprises: If the duration for which the standby node successfully receives the target heartbeat data reaches a receiving duration threshold, registering the standby node with the target routing instance; Based on the target routing instance, the request for the target persistent connection task is processed by the standby node.
5. The method according to claim 1, characterized in that The method further comprises: Obtain at least one of the task management information and the task status result of each of the master nodes; the task management information represents the information under which the master node manages the long connection tasks with a mapping relationship, and the task status result is used to represent the result corresponding to the status query of the master node on the long connection tasks with a mapping relationship; When the task management information or the task status result indicates that the master node is abnormal, the node status of the abnormal master node is adjusted from the available status to the isolated status.
6. The method according to claim 5, characterized in that In the case where the task management information or the task status result indicates that the master node is abnormal, the method further includes: Determine the task processing information and data reception result in the task management information of the master node; the task processing information is used to represent the information when the master node performs request processing on the long connection task with a mapping relationship, and the data reception result is used to represent the result of the master node receiving the target heartbeat data for the long connection task with a mapping relationship; The master node whose task processing information shows that the task processing is normal and whose data reception result shows that the data reception is abnormal is determined as the master node with the abnormality.
7. The method according to claim 6, characterized in that The long connection task includes multiple long connection subtasks; In the case where the task management information or the task status result indicates that the master node is abnormal, the method further includes: Determine the task management sub-information corresponding to each of the long connection sub-tasks in the task management information of the master node; Counting the total number of tasks of the long connection subtask, and counting the number of task exceptions of the long connection subtask corresponding to the task management sub-information representation; Calculating the ratio between the number of abnormal tasks and the total number of tasks to obtain a task abnormality ratio; The master node whose task anomaly ratio reaches the task anomaly threshold is determined as the master node with the anomaly.
8. The method according to claim 6, characterized in that The long connection task includes multiple long connection subtasks; In the case where the task management information or the task status result indicates that the master node is abnormal, the method further includes: Obtain the task status sub-results corresponding to the respective long connection sub-tasks in the task status result of the master node; Counting the total number of tasks of the long connection subtask, and counting the number of query exceptions of the long connection subtask corresponding to the task status subresult representation that failed to perform status query; Calculating the ratio between the number of query anomalies and the total number of tasks to obtain a query anomaly ratio; The master node whose query anomaly ratio reaches the query anomaly threshold is determined as the master node with the anomaly.
9. The method according to claim 6, characterized in that In the case where the task management information or the task status result indicates that the master node is abnormal, the method further includes: The task status result represents the master node that fails to query the status of the long connection task with the mapping relationship, and determines it as the master node with the abnormality.
10. The method according to claim 1, characterized in that The managing the target long connection task by the standby node includes: Adjusting the node state of the standby node from the isolated state to the available state; The target long connection task is managed by the standby node in the available state.
11. The method according to claim 1, characterized in that The method further comprises: Suspending the management of the target persistent connection task by the node to be switched in the isolated state; The node to be switched in the isolated state is used as a new standby node, and the node status of each node having a mapping relationship with the long connection task is obtained through the new standby node.
12. The method according to claim 1, characterized in that The method further comprises: Get multiple nodes to be configured and node configuration files; Configuring the initial node state corresponding to each node to be configured through the node configuration file; The node to be configured whose initial node state is the available state is determined as the master node, and the node to be configured whose initial node state is the isolated state is determined as the standby node.
13. A long connection task management device, characterized in that: The device comprises: A node acquisition module is used to acquire a standby node and multiple master nodes in a long connection task management scenario, wherein the master node is used to manage the long connection tasks with a mapping relationship, and the standby node is used to acquire the node status of each of the master nodes; A node determination module, configured to determine the master node in the isolated state as a node to be switched if the node state of at least one master node among the master nodes changes from an available state to an isolated state; A node updating module, used for determining a target long connection task having a mapping relationship with the node to be switched, and updating a mapping object of the target long connection task from the node to be switched to the standby node; The task management module is used to manage the target long connection task through the standby node.
14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 12 are implemented.
15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.