Cross-process heterogeneous task running method and system
By deploying heterogeneous work units and task managers in distributed services, and utilizing the subscription publishing model and heartbeat information synchronization of the Redis service, the problem of management complexity of heterogeneous functional modules is solved, and the scalability and reliability of the system are improved. , achieving the unification and efficiency of cross-process task management.
Patent Information
- Application Number
- CN202410716901.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-27
AI Technical Summary
Existing technology makes it difficult to uniformly manage heterogeneous functional modules implemented based on different development languages in distributed services, resulting in low system management complexity and reliability.
By deploying heterogeneous work units and task managers in the business system, using the subscription publishing model of the Redis service for communication, and synchronizing task execution progress through heartbeat information, cross-process multi-task running methods and systems are implemented.
It realizes the unified management of heterogeneous functional modules, improves the scalability and reliability of the system, ensures the consistency of task execution, and automatically recovers when the task manager or heterogeneous work unit goes down.
Smart Images

Figure CN118708375A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a cross-process multi-tasking operation method and system, a computing device, and a computer-readable storage medium. Background Art
[0002] In the distributed services of the existing technology, the functions of the system are usually composed of different functional modules, or new functions need to be added to the original system in the future. These functional modules that complete different tasks may be implemented based on different development languages. For example, the main business functional module of the system is implemented by Java or Go, while the crawler, machine learning and other parts are implemented based on heterogeneous languages. It is difficult to directly manage these heterogeneous functional modules through a unified environment. Summary of the invention
[0003] In view of this, embodiments of the present application provide a cross-process multi-tasking operation method and system, a computing device, and a computer-readable storage medium to address the technical defects existing in the prior art.
[0004] According to a first aspect of an embodiment of the present application, a cross-process multi-task running method is provided, comprising:
[0005] Deploy a heterogeneous work unit in the business system, and after the heterogeneous work unit is successfully deployed, subscribe to the first channel of the Redis service;
[0006] The task manager of the business system acts as a publisher and publishes the task instruction to the first channel of the Redis service;
[0007] The heterogeneous work unit executes the task according to the task instruction on the subscribed first channel, and publishes the execution result to the second channel of the Redis service, where the second channel is subscribed by the task manager;
[0008] The task manager processes according to the message of the second channel.
[0009] According to a second aspect of an embodiment of the present application, a cross-process multi-task operation system is provided, including:
[0010] Heterogeneous work units deployed in the business system, task managers in the business system, and Redis services;
[0011] The heterogeneous work unit subscribes to the first channel of the Redis service after being successfully deployed; the task manager, as a publisher, publishes the task instruction to the first channel of the Redis service;
[0012] The heterogeneous work unit executes the task according to the task instruction on the subscribed first channel, and publishes the execution result to the second channel of the Redis service, where the second channel is subscribed by the task manager;
[0013] The task manager processes according to the message of the second channel.
[0014] According to a third aspect of an embodiment of the present application, a computing device is provided, comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein the processor implements the steps of the cross-process multi-tasking method when executing the instructions.
[0015] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, and when the instructions are executed by a processor, the steps of the cross-process multi-tasking operation method are implemented.
[0016] In the above-mentioned embodiments of the present application, heterogeneous work units and task managers are deployed in the business system. When performing task interactions, the heterogeneous work units communicate with the task manager through the subscription and publishing mode of the Redis service, ensuring consistent management of all functional modules. Heartbeat information is further used to synchronize the progress of task execution between the two to maintain the consistency of task execution; heartbeat information continuously sent to the Redis service channel is also used to implement task recovery when the task manager or heterogeneous work unit goes down. Through the method of the embodiments of the present application, even if the functional modules are developed based on different programming languages and operating environments, unified and efficient management can be achieved, greatly improving the scalability and reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a structural block diagram of a computing device provided in an embodiment of the present application;
[0018] Figure 2 It is a flowchart of a cross-process multi-task operation method provided by an embodiment of the present application;
[0019] Figure 3 It is a structural diagram of a cross-process multi-tasking operation system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0021] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0022] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "in response to determination".
[0023] In the present application, a cross-process multi-tasking operation method and system, a computing device and a computer-readable storage medium are provided, which are described in detail one by one in the following embodiments.
[0024] Figure 1 The structure block diagram of a computing device 100 according to an embodiment of the present application is shown. The components of the computing device 100 include but are not limited to a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and the database 150 is used to store data.
[0025] The computing device 100 also includes an access device 140 that enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0026] In one embodiment of the present application, the above components of the computing device 100 and Figure 1 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 1The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0027] The computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 100 may also be a mobile or stationary server.
[0028] Next, a cross-process multi-task operation method provided by an embodiment of the present application is described. Figure 2 As shown, the method includes steps 202 to 208.
[0029] Step 202: deploy a heterogeneous work unit in the business system. After the heterogeneous work unit is successfully deployed, subscribe to a designated first channel of the Redis service.
[0030] In an embodiment of the present application, heterogeneous work units are first deployed in the original business system. The development language used by these heterogeneous work units is different from that of the business system and cannot run in the same runtime as the business system.
[0031] Preferably, the heterogeneous work unit works in an independent container environment. For example, in a K8S system, adding a new heterogeneous work unit means deploying a new service, and the heterogeneous work unit has a unique identifier. For a work unit developed based on Python, first create a Dockerfile, create a Dockerfile file based on the work unit, and build a Docker image based on the Dockerfile.
[0032] Furthermore, the Docker image is pushed to the container image repository so that K8S can access the Docker image. Then a Kubernetes Deployment configuration file (such as a yaml file) is created to describe how the work unit runs, and the kubectl apply command is used to deploy the Docker image to the K8S system.
[0033] Furthermore, when the Docker image is successfully deployed and started, it automatically connects to the Redis service and subscribes to the first channel; for example, the heterogeneous worker unit is identified as workerX, and the subscribed channel may be channel-workerX-A.
[0034] Step 204: The task manager of the business system acts as a publisher and publishes the instruction to the first channel of the Redis service.
[0035] In this step, the business system submits the generated task instructions to the task manager, which publishes them to the designated channel of the Redis service, and the heterogeneous work units that subscribe to the designated channel execute the relevant instructions.
[0036] Optionally, the above instructions are defined by the protobuf protocol, for example:
[0037]
[0038]
[0039] There are two message types in this instruction: MsgManagerTaskSend and PbTaskItem. Among them, the MsgManagerTaskSend message has two fields: aim_worker_id and task. The aim_worker_id field is a string used to identify the target heterogeneous work unit. The task field is of PbTaskItem type and stores relevant information about the task. The PbTaskItem message also has multiple fields, which are the parameters of the specific task.
[0040] Furthermore, after creating a PbTaskItem object instance, the task manager puts the task into a MsgManagerTaskSend object instance, and then uses a serialization method to serialize the instance object into a string and sends it to the Redis service.
[0041] Step 206: The heterogeneous work unit executes the task according to the instruction on the subscribed first channel, and publishes the execution result to the second channel of the Redis service, which is subscribed by the task manager.
[0042] In this step, since the heterogeneous work unit has subscribed to the first channel of the Redis service after successful deployment and continues to listen to messages on the channel, when the task manager sends the task instruction to the first channel of the Redis service, the heterogeneous work unit can obtain the task instruction. Then the heterogeneous work unit parses the task instruction, for example, parses it into a Protobuf message and executes it.
[0043] Furthermore, the heterogeneous worker publishes the task execution result to the second channel of the Redis service, such as channel-workerX-B, where the second channel is subscribed by the task manager, that is, the task manager receives the message sent by the heterogeneous worker through the second channel of the Redis service.
[0044] The task execution result includes a task completion message, which is used to tell the task manager the execution status of the task.
[0045] Preferably, the message sent by the heterogeneous work unit also includes heartbeat information. The heartbeat can also be defined by protobuf, for example:
[0046]
[0047] Heartbeat information is used to periodically inform the task manager of the task execution progress of heterogeneous work units on the corresponding channel.
[0048] Step 208: The task manager processes the message of the second channel.
[0049] Redis's publish-subscribe model is stateless, which means that if a publisher publishes a message, only the listening subscribers can receive it. In order to monitor the status of heterogeneous work units, when the task manager receives a message from the second channel, it processes it accordingly according to the message type.
[0050] When the message type is a task completion message, further processing is performed based on the description of the task execution in the message. When the task is successfully executed, the heterogeneous work unit is informed of the task completion and removed from the local cache; when the task fails, the task is retried according to the preset rules.
[0051] Preferably, when heterogeneous work units execute complex tasks, in order to prevent the task manager from misjudging the heterogeneous work units as downtime due to the long task execution time, heartbeat information is periodically sent to inform the task manager of the task execution progress, such as Figure 3 As shown; when the heterogeneous work unit is executing a task, it periodically sends heartbeat information to the second channel subscribed by the task manager.
[0052] Furthermore, the task manager also confirms the abnormality of the heterogeneous work unit through the heartbeat message. After the task manager sends the task instruction, it monitors the heartbeat information of the target heterogeneous unit.
[0053] Specifically, the heartbeat information is sent at a period of T. When the task manager does not receive the heartbeat information of the target heterogeneous unit within N periods of T, the heterogeneous work unit is set to the disconnection warning level; the task manager continues to wait, and if it still does not receive the heartbeat information of the target heterogeneous unit within M periods of T, it determines that the heterogeneous work unit is faulty, where M>N. The task manager marks the current task as failed and sends it to other heterogeneous work units for execution.
[0054] Furthermore, when the original task manager crashes, the backup task manager takes over the functions of the original task manager. The backup task manager loads the task information of the original task manager and continues to receive the heartbeat information continuously sent by the heterogeneous work unit to the second channel until the task is successfully executed and then removes the heterogeneous work unit task from the local cache.
[0055] In the above-mentioned embodiment of the present application, in order to solve the problem of unified management between various heterogeneous work units and main business functions in the system business, each heterogeneous work unit is encapsulated into an independent container, and each container is an independent operating environment, which can be designed and developed based on the development language and operating environment required by each. When performing task interaction, the heterogeneous work units communicate with the task manager through the subscription and publishing mode of the Redis service, ensuring the consistent management of all functional modules. Further, the heartbeat information is used to synchronize the task execution progress between the two to maintain the consistency of task execution; similarly, the heartbeat information continuously sent to the Redis service channel is used to realize task recovery work when the task manager or heterogeneous work unit goes down. Through the method of the embodiment of the present application, even if the functional modules are developed based on different programming languages and operating environments, unified and efficient management can be achieved, which greatly improves the scalability and reliability of the system.
[0056] Corresponding to the above method embodiment, the present application also provides an embodiment of a cross-process multi-task operation system, such as Figure 3 As shown, the system includes:
[0057] Heterogeneous work units deployed in the business system, task managers in the business system, and Redis services;
[0058] The heterogeneous work unit subscribes to the first channel of the Redis service after being successfully deployed; the task manager, as a publisher, publishes the task instruction to the first channel of the Redis service;
[0059] The heterogeneous work unit executes the task according to the task instruction on the subscribed first channel, and publishes the execution result to the second channel of the Redis service, where the second channel is subscribed by the task manager;
[0060] The task manager processes according to the message of the second channel.
[0061] The above is a schematic scheme of a cross-process multi-task operation system of this embodiment. It should be noted that the technical scheme of this system and the technical scheme of the above-mentioned cross-process multi-task operation method belong to the same concept, and the details not described in detail in the technical scheme of this system can be referred to the description of the technical scheme of the above-mentioned cross-process multi-task operation method.
[0062] In one embodiment of the present application, a computing device is also provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein when the processor executes the instructions, the steps of the cross-process multi-tasking operation method are implemented.
[0063] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above-mentioned cross-process multi-tasking operation method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above-mentioned cross-process multi-tasking operation method.
[0064] An embodiment of the present application further provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the cross-process multi-tasking operation method as described above.
[0065] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the above-mentioned cross-process multi-task operation method belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the above-mentioned cross-process multi-task operation method.
[0066] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0067] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or system capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0068] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0069] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0070] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the present application. The present application selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. A cross-process multi-task operation method, characterized in that: include: Deploy a heterogeneous work unit in the business system, and after the heterogeneous work unit is successfully deployed, subscribe to the first channel of the Redis service; The task manager of the business system acts as a publisher and publishes the task instruction to the first channel of the Redis service; The heterogeneous work unit executes the task according to the task instruction on the subscribed first channel, and publishes the execution result to the second channel of the Redis service, where the second channel is subscribed by the task manager; The task manager processes according to the message of the second channel.
2. The method according to claim 1, wherein: The heterogeneous working units work in independent containers.
3. The method according to claim 1, wherein: The second channel for publishing the execution results to the Redis service includes: The execution result includes a task completion message and a heartbeat message; the heartbeat information is used to inform the task manager of the execution progress of the current task of the heterogeneous work unit.
4. The method according to claim 3, wherein: The task manager processes the message of the second channel by: When the message type is a task completion message and when the task is successfully executed, the heterogeneous work unit is notified of the task completion and is removed from the local cache; when the task fails to execute, the task is retried according to preset rules.
5. The method according to claim 3, wherein: The task manager processes the message of the second channel by: When the task manager does not receive the heartbeat information of the heterogeneous unit within M cycles T, it determines that the heterogeneous work unit fails, marks the current task as failed and sends it to other heterogeneous work units for execution.
6. The method according to claim 3, wherein: The task manager processes the message of the second channel by: When the task manager crashes, the backup task manager takes over, loads the task information of the original task manager, and continues to receive the heartbeat information sent by the heterogeneous work unit to the second channel.
7. The method according to claim 3, wherein: The heartbeat information is continuously sent to the second channel until the heterogeneous work unit task is removed from the local cache after the task is successfully executed.
8. A cross-process multi-tasking operation system, characterized in that: include: Heterogeneous work units deployed in the business system, task managers in the business system, and Redis services; The heterogeneous work unit subscribes to the first channel of the Redis service after successful deployment; the task manager, as a publisher, publishes the task instruction to the first channel of the Redis service; The heterogeneous work unit executes the task according to the task instruction on the subscribed first channel, and publishes the execution result to the second channel of the Redis service, where the second channel is subscribed by the task manager; The task manager processes according to the message of the second channel.
9. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the instructions, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing computer instructions, characterized in that: When the instruction is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
