Real-time multi-task delivery methods, devices, electronic equipment and storage media
By allocating database thread pool handles and child processes in the Linux operating system, the problem of low efficiency in multitasking of the Linux operating system is solved, and second-level multitasking and efficient task processing are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2026-03-10
AI Technical Summary
The existing Linux operating system is inefficient in multitasking, cannot achieve second-level multitasking, and has a limit on the number of main processes.
By acquiring a preset number of tasks to be run, allocating database thread pool handles, and mounting child processes to the Linux operating system, the system avoids using the CONtab task system, directly achieving second-level multi-task execution, and allocating child processes to each task to circumvent the main process limit.
It enables multi-task execution within seconds, improves task processing efficiency, avoids database resource consumption issues, and solves the problems of task loss and duplicate processing.
Smart Images

Figure CN114281495B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a real-time multitasking method, apparatus, electronic device, and storage medium. Background Technology
[0002] Current Linux operating systems typically employ CONTAB task systems, which require cumbersome configuration files to run tasks. These are mostly shell files, offering only scheduled execution modes such as minutes, hours, and days, and cannot handle multitasking down to the second. Furthermore, current Linux operating systems limit the number of concurrently running main processes, resulting in low task processing efficiency under multitasking conditions. Summary of the Invention
[0003] In view of this, embodiments of the present invention provide a real-time multi-task distribution method, apparatus, electronic device, and storage medium capable of achieving second-level multi-task operation and high task processing efficiency.
[0004] In a first aspect, embodiments of the present invention provide a real-time multi-task delivery method for a Linux operating system, comprising:
[0005] Get a preset number of tasks to be run;
[0006] Based on the number of tasks, obtain the same number of database thread pool handles, wherein the Linux operating system and the server have pre-established several TCP connections, and the database thread pool handles point to idle TCP connections among the TCP connections.
[0007] Based on the number of tasks, the current main process is branched into the same number of child processes, so that each child process is used to run one task, and a database thread pool handle is allocated to each child process.
[0008] The branched child processes and their corresponding database thread pool handles are mounted to the Linux operating system and run by the Linux operating system.
[0009] In conjunction with the first aspect, in one embodiment of the first aspect, obtaining a preset number of tasks to be run includes:
[0010] A preset number of tasks to be run are obtained from the task queue, wherein the task queue is an asynchronous persistent memory queue;
[0011] The step of attaching the branched child process and its corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system includes:
[0012] Once the child process has finished running, its corresponding task is removed from the task queue.
[0013] In conjunction with the first aspect, in another implementation of the first aspect, the step of mounting the branched child process and its corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system includes:
[0014] When each child process runs, its current task execution status is written into a pre-defined process running status register.
[0015] In conjunction with the first aspect, in another embodiment of the first aspect, the step of mounting the branched child process and the corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system includes:
[0016] When a task needs to be changed, a task change request is written to the process running status register.
[0017] The process running status register is read periodically, and the corresponding child processes are processed according to the task change requests contained therein.
[0018] Secondly, embodiments of the present invention provide a real-time multi-task distribution device for a Linux operating system, comprising:
[0019] The first acquisition module is used to acquire a preset number of tasks to be run;
[0020] The second acquisition module is used to acquire the same number of database thread pool handles as the number of tasks, wherein the Linux operating system and the server have pre-established several TCP connections, and the database thread pool handles point to idle TCP connections among the TCP connections.
[0021] The branching module is used to branch the current main process into the same number of child processes according to the number of tasks, so that each child process is used to run one task, and a database thread pool handle is allocated to each child process;
[0022] The mounting module is used to mount the branched child processes and their corresponding database thread pool handles to the Linux operating system, where they are run by the Linux operating system.
[0023] In conjunction with the second aspect, in one embodiment of the second aspect, the first acquisition module includes:
[0024] The acquisition unit is used to acquire a preset number of tasks to be run from the task queue, wherein the task queue is an asynchronous persistent memory queue;
[0025] The device further includes:
[0026] The deletion module is used to remove the corresponding task from the task queue after the child process has finished running.
[0027] In conjunction with the second aspect, in another embodiment of the second aspect, the branch module includes:
[0028] The write unit is used to write the current task execution status of each subprocess into a pre-defined process running status register when each subprocess is running.
[0029] In conjunction with the second aspect, in another embodiment of the second aspect, the apparatus further includes:
[0030] The writing module is used to write a task change request to the process running status register when a task needs to be changed.
[0031] The processing module is used to periodically read the process running status register and process the corresponding subprocess according to the task change request in it.
[0032] Thirdly, embodiments of the present invention provide an electronic device, the electronic device comprising: a housing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is disposed within the space enclosed by the housing, and the processor and the memory are disposed on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, for executing any of the aforementioned methods.
[0033] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing one or more programs, which can be executed by one or more processors to implement any of the methods described above.
[0034] The real-time multi-task deployment method, apparatus, electronic device, and storage medium provided in this invention are used with a Linux operating system. First, a preset number of tasks to be run are acquired. Then, based on the number of tasks, an equal number of database thread pool handles are acquired. The Linux operating system and the server have pre-established several TCP connections, and the database thread pool handles point to idle TCP connections. Next, based on the number of tasks, the current main process is branched into an equal number of child processes, so that each child process is used to run one task. A database thread pool handle is allocated to each child process. Finally, the branched child processes and their corresponding database thread pool handles are mounted to the Linux operating system for execution. Thus, this invention converts tasks into processes and directly mounts them to the operating system, eliminating the need for the Linux operating system's Conftab task system, enabling second-level multi-task execution. Furthermore, this invention allocates a child process to each task instead of a main process, thus circumventing the system's limitation on the number of main processes and allowing multiple tasks to run concurrently, greatly improving task processing efficiency. In addition, this invention can run a preset number of child processes / tasks at once, solving the problem of excessive task execution and large database resource consumption in existing technologies. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 This is a flowchart of an embodiment of the real-time multi-task delivery method of the present invention;
[0037] Figure 2 This is a schematic diagram of an embodiment of the real-time multi-task delivery method of the present invention;
[0038] Figure 3 This is a schematic diagram of the structure of an embodiment of the real-time multi-task distribution device of the present invention;
[0039] Figure 4 This is a schematic diagram of the structure of an embodiment of the electronic device of the present invention. Detailed Implementation
[0040] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0041] It should be understood that the described embodiments are merely some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0042] On the one hand, embodiments of the present invention provide a real-time multi-task delivery method for the Linux operating system, such as... Figure 1 As shown, the method in this embodiment may include:
[0043] Step 101: Obtain a preset number of tasks to be run;
[0044] In this step, the tasks to be run can come from log data reported by terminal traffic devices, including but not limited to firewalls, hardware, software, system operations, network connections, etc. Each log data corresponds to one task. There may be many tasks to be run, making it difficult to run them all at once. Therefore, a preset number of tasks can be obtained each time. The preset number can be flexibly set according to the situation, for example, it can be 3, 4, 5 or more.
[0045] Figure 2 This is a schematic diagram of an embodiment of the real-time multi-task delivery method of the present invention. This step basically corresponds to... Figure 2 The "Task Queue Distribution Module" in the document.
[0046] Step 102: Based on the number of tasks, obtain the same number of database thread pool handles, wherein the Linux operating system and the server have pre-established several TCP connections, and the database thread pool handles point to idle TCP connections among the TCP connections.
[0047] In this step, based on the number of tasks to be run, the same number of database thread pool handles can be obtained from a pre-established database thread pool; the database thread pool can store running threads and the database thread pool handles they use, as well as idle database thread pool handles.
[0048] In this step, the Linux operating system and the server have pre-established several TCP connections. This significantly reduces the time required to create TCP connections, reduces the connection pressure on the server's database service, increases program processing speed, and allows for the concurrent execution of different types of tasks. Each database thread pool handle points to each established TCP connection, and an idle database thread pool handle points to an idle TCP connection. In this step, an idle database thread pool handle is obtained, thus allocating an available database thread pool handle to subsequent child processes. This facilitates interaction between the child processes and the server's database, and allows them to write the results to the server's database after execution.
[0049] Step 103: Based on the number of tasks, branch the current main process into the same number of child processes, so that each child process is used to run one task, and allocate a database thread pool handle to each child process;
[0050] In this step, based on the number of tasks to be run, the current main process is forked to create an equal number of child processes, so that each child process can run one task. Each child process is also assigned a database thread pool handle, which facilitates the interaction between the child process and the server's database, and allows the child process to write the results to the server's database after execution.
[0051] In this step, a child process is assigned to each task instead of a main process. This avoids the system's limit on the number of main processes and greatly improves task processing efficiency.
[0052] Step 104: Mount the branched child process and its corresponding database thread pool handle to the Linux operating system for execution.
[0053] Steps 103-104 above basically correspond to Figure 2 The "process task mounting module" and "operating system task mounting" in the middle are... Figure 2 The process branches into five subprocesses, which are used to execute Task 1, Task 2, Task 3, Task 4, and Task 5, respectively. It's conceivable that once a subprocess finishes running, its resources can be released, and steps 101-104 above can be re-executed to continue processing other pending tasks.
[0054] In existing technologies, under special circumstances, such as server power outages or server restarts, problems such as task loss and duplicate data processing may occur. To solve this problem, as an optional embodiment, obtaining a preset number of tasks to be run (step 101) may include:
[0055] Step 1011: Obtain a preset number of tasks to be run from the task queue, wherein the task queue is an asynchronous persistent memory queue; Figure 2 In this context, the task queue is the same as the system log queue;
[0056] Simultaneously, the step of mounting the branched child process and its corresponding database thread pool handle to the Linux operating system for execution (step 104) may include the following:
[0057] Step 105: After the child process finishes running, remove its corresponding task from the task queue.
[0058] In this way, the tasks stored in the task queue are those that have not yet been processed. Even in special circumstances such as server power failure or server restart, the tasks can be re-executed, effectively avoiding problems such as task loss and duplicate data processing.
[0059] As another optional embodiment, the step of mounting the branched child process and its corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system (step 104) may include:
[0060] Step 1041: When each child process runs, its current task execution status is written to a pre-established process running status register.
[0061] In this step, the process running status register corresponds to Figure 2 The "Process Running Status" register is a dedicated register, not representing the system process status. This allows for better monitoring of the running status of each child process (task). The current task execution status of a child process can include running, completed, etc.
[0062] As another optional embodiment, the step of mounting the branched child process and its corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system (step 104) may be followed by:
[0063] Step 105': When a task needs to be changed, write a task change request to the process running status register;
[0064] In this step, the task change request can be a task pause, restart, or cancellation.
[0065] Step 106': Periodically read the process running status register and process the corresponding child process according to the task change request in it.
[0066] In this step, the process execution status register is read periodically. When a task change request is detected, the corresponding child process is processed accordingly (pause, restart, cancel, etc.). It's conceivable that the task change request can also be directly written into the process execution status register as the current task execution status. In this case, step 106' could involve periodically reading the process execution status register, processing the child process based on its execution status, and marking the process as complete after processing to avoid duplicate processing. Steps 105'-106' above enable real-time pause, restart, and cancel functions for multiple tasks.
[0067] The above step 106' corresponds to Figure 2 The "process controller" in the context. It is conceivable that step 106' could also include:
[0068] Step 1061': Compare the process status in the process running status register with the system process status;
[0069] Step 1062': If there is a discrepancy, update the process status in the process running status register to the system process status; or, if there is no corresponding child process information in the system process status, re-attach the corresponding child process and its corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system.
[0070] The steps 1061'-1062' above can effectively resolve abnormal situations that may occur during process execution.
[0071] In summary, the real-time multi-task deployment method provided by this embodiment of the invention, used on a Linux operating system, first obtains a preset number of tasks to be run. Then, based on the number of tasks, it obtains the same number of database thread pool handles. The Linux operating system and the server have pre-established several TCP connections, and the database thread pool handles point to idle TCP connections. Next, based on the number of tasks, the current main process branches out the same number of child processes, so that each child process is used to run one task, and a database thread pool handle is allocated to each child process. Finally, the branched child processes and their corresponding database thread pool handles are mounted to the Linux operating system for execution. Thus, this embodiment of the invention converts tasks into processes and directly mounts them to the operating system, eliminating the need for the Linux operating system's Conftab task system, enabling second-level multi-task execution. Furthermore, this embodiment of the invention allocates a child process to each task instead of a main process, thus circumventing the system's limitation on the number of main processes, allowing multiple tasks to run concurrently, greatly improving task processing efficiency. In addition, this embodiment of the invention can run a preset number of child processes / tasks at once, solving the problem of excessive task execution and large-scale database resource consumption in existing technologies.
[0072] On the other hand, embodiments of the present invention provide a real-time multi-task distribution device for a Linux operating system, such as... Figure 3 As shown, the device may include:
[0073] The first acquisition module 11 is used to acquire a preset number of tasks to be run;
[0074] The second acquisition module 12 is used to acquire the same number of database thread pool handles according to the number of tasks, wherein the Linux operating system and the server have pre-established several TCP connections, and the database thread pool handles point to idle TCP connections among the TCP connections.
[0075] Branching module 13 is used to branch the current main process into the same number of child processes according to the number of tasks, so that each child process is used to run one task, and to allocate a database thread pool handle to each child process.
[0076] Mounting module 14 is used to mount the branched child process and the corresponding database thread pool handle to the Linux operating system for execution by the Linux operating system.
[0077] The apparatus of this embodiment can be used to perform Figure 1 The technical solutions of the method embodiments shown are similar in principle and in effect, and will not be described again here.
[0078] Preferably, the first acquisition module 11 includes:
[0079] The acquisition unit is used to acquire a preset number of tasks to be run from the task queue, wherein the task queue is an asynchronous persistent memory queue;
[0080] The device further includes:
[0081] The deletion module is used to remove the corresponding task from the task queue after the child process has finished running.
[0082] Preferably, the branch module 13 includes:
[0083] The write unit is used to write the current task execution status of each subprocess into a pre-defined process running status register when each subprocess is running.
[0084] Preferably, the device further includes:
[0085] The writing module is used to write a task change request to the process running status register when a task needs to be changed.
[0086] The processing module is used to periodically read the process running status register and process the corresponding subprocess according to the task change request in it.
[0087] This invention also provides an electronic device. Figure 4 This is a schematic diagram of the structure of an embodiment of the electronic device of the present invention, which can realize the present invention. Figure 1 The process of the illustrated embodiment is as follows: Figure 4As shown, the above-mentioned electronic device may include: a housing 41, a processor 42, a memory 43, a circuit board 44, and a power supply circuit 45, wherein the circuit board 44 is disposed inside the space enclosed by the housing 41, and the processor 42 and the memory 43 are disposed on the circuit board 44; the power supply circuit 45 is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory 43 is used to store executable program code; the processor 42 runs a program corresponding to the executable program code by reading the executable program code stored in the memory 43, for executing the method described in any of the foregoing method embodiments.
[0088] For details on the specific execution process of the above steps by processor 42, and the steps further executed by processor 42 through running executable program code, please refer to the present invention. Figure 1 The description of the illustrated embodiments will not be repeated here.
[0089] This electronic device exists in various forms, including but not limited to:
[0090] (1) Mobile communication devices: These devices are characterized by their mobile communication capabilities and primarily aim to provide voice and data communication. These terminals include: smartphones (e.g., iPhones), multimedia phones, feature phones, and low-end phones, etc.
[0091] (2) Ultra-mobile personal computer devices: These devices fall under the category of personal computers, possessing computing and processing capabilities, and generally also have mobile internet access features. These terminals include PDAs, MIDs, and UMPCs, such as the iPad.
[0092] (3) Portable entertainment devices: These devices can display and play multimedia content. This category includes: audio and video players (such as iPods), handheld game consoles, e-books, as well as smart toys and portable car navigation devices.
[0093] (4) Server: A device that provides computing services. The components of a server include a processor, hard disk, memory, system bus, etc. Servers are similar to general computer architectures, but because they need to provide highly reliable services, they have higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.
[0094] (5) Other electronic devices with data interaction functions.
[0095] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps described in any of the above method embodiments.
[0096] Embodiments of the present invention also provide an application program that is executed to implement the method provided in any embodiment of the present invention.
[0097] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0098] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments. For ease of description, the above devices are described by dividing them into various functional units / modules. Of course, in implementing this invention, the functions of each unit / module can be implemented in one or more software and / or hardware.
[0099] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0100] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A real-time multitasking issuing method for a Linux operating system, characterized in that, The method comprises the steps of: acquiring a preset number of tasks to be run; the tasks to be run are derived from log data reported by a terminal traffic device, each piece of log data corresponds to a task, and the tasks to be run include tasks of different types; according to the number of the tasks, acquiring a same number of database thread pool handles, wherein the Linux operating system has established a plurality of TCP connections with a server in advance, and the database thread pool handles point to idle TCP connections in the TCP connections; according to the number of the tasks, branching a same number of child processes from a current main process, so that each child process is used to run a task, and each child process is allocated a database thread pool handle; mounting the branched child processes and the corresponding database thread pool handles to the Linux operating system, and running by the Linux operating system.
2. The method of claim 1, wherein, The step of acquiring a preset number of tasks to be run comprises the steps of: acquiring a preset number of tasks to be run from a task queue, wherein the task queue is an asynchronous persistent memory queue; after the step of mounting the branched child processes and the corresponding database thread pool handles to the Linux operating system and running by the Linux operating system, the method further comprises the step of: when a child process is run, deleting the task corresponding to the child process from the task queue.
3. The method according to claim 1 or 2, characterized in that, The step of mounting the branched child processes and the corresponding database thread pool handles to the Linux operating system and running by the Linux operating system comprises the step of: when each child process is running, writing a current task execution state of the child process into a pre-established process running state register.
4. The method of claim 3, wherein, After the step of mounting the branched child processes and the corresponding database thread pool handles to the Linux operating system and running by the Linux operating system, the method further comprises the steps of: when a task needs to be changed, writing a task change request into the process running state register; periodically reading the process running state register, and processing a corresponding child process according to the task change request in the process running state register.
5. A real-time multitasking issuing device for Linux operating system, characterized in that, The method comprises the steps of: a first acquiring module is configured to acquire a preset number of tasks to be run; the tasks to be run are derived from log data reported by a terminal traffic device, each piece of log data corresponds to a task, and the tasks to be run include tasks of different types; a second acquiring module is configured to acquire a same number of database thread pool handles according to the number of the tasks, wherein the Linux operating system has established a plurality of TCP connections with a server in advance, and the database thread pool handles point to idle TCP connections in the TCP connections; a branching module is configured to branch a same number of child processes from a current main process according to the number of the tasks, so that each child process is used to run a task, and each child process is allocated a database thread pool handle; a mounting module is configured to mount the branched child processes and the corresponding database thread pool handles to the Linux operating system, and run by the Linux operating system.
6. The apparatus of claim 5, wherein, The first acquiring module comprises the steps of: The acquisition unit is configured to acquire a preset number of tasks to be executed from a task queue, the task queue being an asynchronous persistent memory queue; The device further comprises: The deletion module is configured to delete the task corresponding to the child process from the task queue after the child process is executed.
7. The apparatus of claim 5 or 6, wherein, The branch module comprises: The writing unit is configured to write the current task execution state of each child process into a pre-established process execution state register when the child process is executed.
8. The apparatus of claim 7, wherein, The device further comprises: The writing module is configured to write a task change request into the process execution state register when the task needs to be changed. The processing module is configured to periodically read the process execution state register and process the corresponding child process according to the task change request in the process execution state register.
9. An electronic device, comprising: The electronic device comprises a housing, a processor, a memory, a circuit board and a power circuit, wherein the circuit board is arranged inside a space enclosed by the housing, the processor and the memory are arranged on the circuit board; the power circuit is configured to supply power to each circuit or device of the electronic device; the memory is configured to store executable program codes; the processor is configured to run programs corresponding to the executable program codes by reading the executable program codes stored in the memory, and the programs are configured to execute the method of any one of claims 1-4.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method of any one of claims 1-4.
Citation Information
Patent Citations
Three-dimensional space data parallel scheduling method and system
CN103077074A
Multi-process management method, storage medium, electronic device and system
CN109062686A