Data processing method and system based on hybrid task thread pool, medium and program product
By adopting the collaborative working model of I/O completion port thread pool and non-I/O type thread pool in the data storage service, the problem of resource demand and processing time prediction of the data storage service when processing multiple tasks is solved, and high efficiency is achieved. Stable data processing and system performance improvement.
Patent Information
- Application Number
- CN202410878260.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-09-10
AI Technical Summary
It is difficult for data storage services to predict resource requirements and processing times when processing multiple different tasks, leading to problems such as lags, missing data, and downtime. It is also difficult to effectively schedule and prioritize task execution in user mode.
Adopting a collaborative working model based on I/O completion port thread pool and non-I/O type thread pool, the task request is parsed through the state machine and allocated to the corresponding thread pool for processing, ensuring that long-term tasks are completed by the I/O completion port Thread pool processing, short instructions are processed by non-I/O type thread pool to avoid thread blocking and optimize disk read and write operations.
It achieves efficient and stable data processing, avoids stuck and missing data, improves the system's operating performance and scalability, and simplifies task scheduling and priority management.
Smart Images

Figure CN118626271A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to a data processing method, system, medium and program product based on a mixed task thread pool. Background Art
[0002] The most typical operation of the data storage service application program is to receive data packets from network devices, proofread the data packets, write the correct data packets to disk, and save them into specific disk files according to the corresponding rules. In this process, the data storage service often needs to wait, read and write network sockets, operate databases, respond to specific user links, log records, timeout mechanisms, data caching, exchange, delete files and other tasks. In these cases, the data storage service program often cannot foresee when the corresponding events will be driven, nor can it accurately judge how much system resources and processing time are required to process these events. If a long I / O operation causes the working thread to be suspended and cannot respond to other events in time, it is likely to cause the data storage service program to freeze, miss data, and crash. In many industries, the storage requirements for historical data cannot accept this phenomenon, and it is also difficult to arrange on-duty personnel to check whether all the stored data in the past 24 hours is correct and complete.
[0003] In the actual working process, many data storage server running programs often cannot well structure various tasks and the mechanism for executing these tasks. First of all, under the premise of user mode, some tasks can complete the reception or output of data in one call, while some tasks need to be called several times to complete all actions. Some tasks can be executed when the running program is idle, some need to respond immediately, some need to be executed at a fixed time, and some are passively triggered. That is, in user mode, the nature and attributes of tasks are viewed from different dimensions such as time, space, and priority. Furthermore, from the deeper kernel mode, that is, the system-level scheduling dimension, the real workers who execute tasks - the scheduling, priority, CPU affinity of program threads, and the influence of thread scheduling between the same program and between different programs in the system, have brought the task execution mechanism of the running program into a very difficult and complex design environment.
[0004] The above issues related to the operation of data storage services will eventually lead to frequent unknown errors, low operating efficiency, and extremely difficult addition, deletion, and modification of functions in the actual production process. Summary of the invention
[0005] In view of the problems existing in the prior art, the purpose of the present invention is to provide a data processing method, system, medium and program product based on a mixed task thread pool, which has high operating efficiency and stable operation.
[0006] To achieve the above object, the technical solution adopted by the present invention is: A data processing method based on a hybrid task thread pool, the method processes a data storage service of a hybrid multi-task model based on the collaborative work of an I / O completion port thread pool and a non-I / O type thread pool, wherein the I / O completion port thread pool is used to process task instructions that require long-term work, and the non-I / O type thread pool is used to process short instructions of a signaling type; the method specifically comprises the following steps: Step 1: Design the I / O completion port thread pool and the non-I / O type thread pool; Step 2: When the main thread listens to a task request, it sends the task request to the task queue; when the task time slice is up, the task request is delivered to the state machine for parsing, and the state machine calls different function plug-ins and sends them to the I / O completion port thread pool or non-I / O type thread pool; Specifically, the state machine's analysis of the task request includes: determining whether the task instruction in the task request is a short instruction of the signaling type or an instruction that requires a long time to work, and also determining whether the task instruction is a bookmark instruction; when it is determined to be an instruction that requires a long time to work, the corresponding task request is sent to the I / O completion port thread pool for processing, and steps 3-5 are executed; when it is determined to be a short instruction of the signaling type, the corresponding task request is sent to the non-I / O type thread pool for processing, and step 6 is executed; whether the task request is sent to the I / O completion port thread pool or the non-I / O type thread pool, when the task instruction is determined to be a bookmark instruction, it means that the corresponding task request was not completed in the previous execution cycle and needs to be processed again as a priority; Step 3: When the task request enters the I / O completion port thread pool, a storage file task, a data stream receiving task, and a data stream timeout mechanism are created in the I / O completion port thread pool, and the data stream of the task request is added to the storage queue; Step 4. The I / O completion port starts to receive the data stream after the user request is successfully connected. The data stream will be pushed into the available data packet queue according to the received data packets. When the time slice of the storage file task arrives, the read and write data cache function will traverse the entire current data packet queue, and first determine whether the beginning of the current storage file is a key frame data packet. If not, the current data packet will be discarded until the key frame data packet arrives. When the key frame data packet arrives, the read / write data function in the designed I / O completion port class is called to write the data packet to the disk file, ensuring that the written data is an integer multiple of the disk volume size, and modifying the corresponding offset value in the write function. The offset value is an integer multiple of the disk volume size. Step 5: After the data write operation is completed, the driver notification of the completion of the write operation is obtained in the I / O completion port thread structure, and the overlapped structure is passed out at the same time. This overlapped structure is passed in when the data write function is called in step 6; Step 6: When a task request enters the non-I / O type thread pool, the task delivery function delivers the task request to the task queue of the working thread according to the priority of the task request, and waits for the time slice to arrive to execute the task request; During the execution of steps 3-5, step 6 is executed synchronously.
[0007] The step 1 is specifically as follows: Step 1.1, design a globally unique I / O completion port class for file reading and writing, and associate all related disk I / Os with the I / O completion port class; The I / O completion port class includes a core creation completion port function, a completion port and device association function, a completion port status acquisition function, a simulation completion port status completion function, a cancellation / end completion port function, and a read / write data function; Step 1.2, design an I / O completion port notification structure, which includes the required overlapping structure, a data buffer area opened based on a virtual memory method, and a read and write data buffer function; The overlapping structure in the I / O completion port notification structure is used to complete the transmission of the total amount of bytes of read and write data and the detection of the completion port status each time an I / O request occurs. It uses the original overlapping structure of Windows to allow users to customize the incoming and outgoing information during the working process of the completion port notification mechanism; The starting address of the data cache area opened by virtual memory is an integer multiple of the system allocation granularity. At the same time, the minimum cache size opened by virtual memory is the system paging size of 4KB, which can simultaneously meet the requirements that the size of the I / O completion port operation file read and write cache data and the size of the read and write cache data offset value are integer multiples of the disk volume size; The read and write data cache functions are used to set the offset value in the original overlap structure of Windows. This offset value is an integer multiple of the disk volume size. Step 1.3, design an I / O type thread structure for reading and writing files hosted by an I / O completion port. The main structure of the I / O type thread for reading and writing files consists of a loop whose condition is always true. In the loop, the get completion port status function in the I / O completion port class of step 1.1 is called to determine whether there is a completed file reading and writing task. If so, custom processing of the corresponding task is performed; Step 1.4, design a non-I / O type thread structure driven by a custom time slice; The main structure of the non-I / O type thread consists of a task queue and tasks in the task queue that run according to time; the supporting architecture of the non-I / O type thread structure consists of a delivery task function, which is used to deliver the task to the task queue of a random working thread and wait for it to be executed when the time slice arrives.
[0008] A data processing system based on a mixed task thread pool comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of a data processing method based on a mixed task thread pool as described above. A computer-readable storage medium stores a computer program / instruction thereon, and when the computer program / instruction is executed by a processor, the steps of a data processing method based on a mixed task thread pool as described above are implemented. A computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps of a data processing method based on a mixed task thread pool as described above.
[0009] After adopting the above scheme, the present invention processes mixed multitasking based on the cooperative work of I / O completion port thread pool and non-I / O type thread pool. For tasks that require long-term processing, the I / O completion port cooperates with the program under the driver and user mode layer, and manages the thread pool associated with the I / O completion port. At the same time, the heuristic working mechanism inside the completion port automatically adjusts the suspension and running status of the working threads in the managed thread pool, and controls the entire thread pool managed by the completion port at the optimal execution efficiency. For non-I / O type short time slice tasks, a task execution thread pool based on time slice operation is designed at the user mode level. If the task cannot be completed within one time slice, it will be re-delivered to the task queue with higher priority (this type of task is a bookmark instruction). This design method will not block any thread, and all threads will be smoothly scheduled and executed according to the operating system. The most troublesome disk reading and writing have been handed over to the driver by the completion port for processing. The two thread pools will not have any blocking in user mode, and the service running program always maintains high performance and high scalability. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 It is the overall workflow diagram of the present invention; Figure 2 Schematic diagram of a task request entering the main thread; Figure 3 A schematic diagram of calling the corresponding plug-in for the state machine; Figure 4 For non-storage type task workflow; Figure 5 A workflow diagram for storage type tasks. DETAILED DESCRIPTION
[0011] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be more comprehensive and complete and will fully convey the concept of the example embodiments to those skilled in the art. In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure. The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices. The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0012] like Figure 1-5 As shown, the present invention discloses a data processing method based on a hybrid task thread pool, which processes a data storage service of a hybrid multi-task model based on the collaborative work of an I / O completion port thread pool and a non-I / O type thread pool, wherein the I / O completion port thread pool is used to process task instructions that require long-term work, i.e., storage type task instructions; and the non-I / O type thread pool is used to process short instructions of a signaling type, i.e., non-storage type task instructions. The method of the present invention specifically includes the following steps: Step 1: Design the I / O completion port thread pool and non-I / O type thread pool.
[0013] Step 1.1: Design a globally unique I / O completion port class for file reading and writing, and associate all related disk I / Os with the I / O completion port class.
[0014] The I / O completion port class includes a core creation completion port function, a completion port and device association function, a completion port status acquisition function, a simulation completion port status completion function, a cancellation / end completion port function, and a read / write data function.
[0015] Step 1.2, design an I / O completion port notification structure, which includes the required overlapping structure, a data buffer area opened based on a virtual memory method, and a read and write data buffer function; The overlapping structure in the I / O completion port notification structure is used to complete the transmission of the total amount of bytes of read and write data and the detection of the completion port status each time an I / O request occurs. It adopts the original overlapping structure of Windows, and users can customize the incoming and outgoing information during the working process of the completion port notification mechanism.
[0016] The data buffer area in the I / O completion port notification structure is opened by using a virtual memory method. Since the present invention does not need to let the system cache mechanism cache the operation file when opening the operation file, but directly reads and writes it, the reading and writing of file data in this way needs to follow the principle that the starting address of the cache is an integer multiple of the disk volume size (a multiple of 64KB). The starting address of the data buffer area opened by the virtual memory method is an integer multiple of the system allocation granularity, that is, a multiple of 64KB. At the same time, the minimum cache size opened by the virtual memory method is the system paging size of 4KB, which can simultaneously meet the requirements that the I / O completion port operation file read and write cache data volume size and the read and write cache data volume offset value size are integer multiples of the disk volume size (64KB).
[0017] The read and write data cache functions are used to set the offset value in the original overlapping structure of Windows. This offset value is an integer multiple of the disk volume size, that is, a multiple of 64KB.
[0018] Step 1.3, design an I / O type thread structure for reading and writing files hosted by the I / O completion port. The main structure of the read and write file I / O type thread consists of a loop whose condition is always true. In the loop, the get completion port status function in the I / O completion port class of step 1.1 is called to determine whether there is a completed file reading and writing task. If so, custom processing of the corresponding task is performed, such as slicing the file size according to the set time requirements.
[0019] Step 1.4: Design a non-I / O type thread structure driven by a custom time slice.
[0020] The main structure of the non-I / O type thread consists of a task queue and tasks in the task queue that run according to time. The supporting architecture of the non-I / O type thread structure consists of a delivery task function, which is used to deliver tasks to the task queue of a random working thread and wait for execution when the time slice arrives.
[0021] Step 2: When the main thread listens to a task request, it sends the task request to the task queue; when the task time slice expires, the task request is delivered to the state machine for parsing, and the state machine calls different function plug-ins to send them to the I / O completion port thread pool or non-I / O type thread pool.
[0022] Specifically, the state machine's analysis of the task request includes: determining whether the task instruction in the task request is a short instruction of the signaling type or an instruction that requires a long time to work, and also determining whether the task instruction is a bookmark instruction. When it is determined to be an instruction that requires a long time to work, the corresponding task request is sent to the I / O completion port thread pool for processing, and steps 3-5 are executed; when it is determined to be a short instruction of the signaling type, the corresponding task request is sent to the non-I / O type thread pool for processing, and step 6 is executed. Regardless of whether the task request is sent to the I / O completion port thread pool or the non-I / O type thread pool, when the task instruction is determined to be a bookmark instruction, it means that the corresponding task request was not completed in the previous execution cycle and needs to be processed again, and its priority is higher.
[0023] Step 3: When the task request enters the I / O completion port thread pool, a storage file task, a data stream receiving task, and a data stream timeout mechanism are created in the I / O completion port thread pool, and the data stream of the task request is added to the storage queue.
[0024] Step 4. The I / O completion port starts to receive the data stream after the user's request is successfully connected. The data stream will be pushed into the available data packet queue according to the received data packets. When the time slice of the storage file task arrives, the read and write data cache function will traverse the entire current data packet queue, first determine whether the beginning of the current storage file is a key frame data packet, if not, the current data packet will be discarded until the key frame data packet arrives. When the key frame data packet arrives, call the read / write data function in the designed I / O completion port class to write the data packet to the disk file. At this time, ensure that the written data is an integer multiple of the disk volume size (an integer multiple of 64KB), and modify the corresponding offset value in the write function. The offset value is an integer multiple of the disk volume size, that is, a multiple of 64KB, otherwise the system's write function will not know where to start writing in the file in the I / O completion port scenario.
[0025] Step 5. After the write data operation is completed, the driver notification of the completion of the write operation is obtained in the I / O completion port thread structure, and the overlapped structure is passed out at the same time. This overlapped structure is passed in when the write data function is called in step 6. At this time, you can get this structure and perform specific actions through the custom data field.
[0026] Step 6: When a task request enters the non-I / O type thread pool, the task delivery function delivers the task request to the task queue of the working thread according to the priority of the task request, and waits for the time slice to arrive to execute the task request.
[0027] In the above processing, during the execution of steps 3-5, step 6 can be run synchronously.
[0028] The present invention processes mixed multitasking based on the cooperative work of I / O completion port thread pool and non-I / O type thread pool. For tasks that need to be processed for a long time, the I / O completion port cooperates with the program under the driver and user mode layer, and the I / O completion port is managed by the associated thread pool, and the suspension and running state of the working thread in the managed thread pool is automatically adjusted by the heuristic working mechanism inside the completion port, so that the thread pool managed by the entire completion port is controlled at the optimal execution efficiency. For non-I / O type short time slice tasks, a task execution thread pool based on time slice operation is designed at the user mode level. If the task cannot be completed within one time slice, it will be re-delivered to the task queue with higher priority (this type of task is a bookmark instruction). This design method will not block any thread, all threads will be smoothly scheduled and executed according to the operating system, and the most troublesome disk reading and writing have been handed over to the driver by the completion port for processing. The two thread pools will not have any blocking in the user mode, and the service running program always maintains high performance and high scalability.
[0029] The solution described in this article includes how to design, coordinate, and operate asynchronous sockets, non-storage type tasks, storage type tasks, idle tasks, timeout tasks, and the thread pool that executes these tasks, the task queues supporting the thread pool, time slices, task priorities in user mode, and the system kernel. Through the design described in this article, threads with storage task types and threads with non-storage tasks will work together clearly and distinctly, and the server execution mechanism will be stable, solid, efficient, and highly scalable, and easy to maintain, expand, and improve in the future.
[0030] The present invention also provides a data processing system based on a hybrid task thread pool, which includes a memory, a processor and a computer program stored in the memory, and the processor executes the computer program to implement the steps of the above-mentioned data processing method based on a hybrid task thread pool. The present invention further provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiments. It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied. Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure. Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data processing method based on a mixed task thread pool, characterized in that: The method processes a data storage service of a mixed multi-task model based on the collaborative work of an I / O completion port thread pool and a non-I / O type thread pool, wherein the I / O completion port thread pool is used to process task instructions that require long-term work, and the non-I / O type thread pool is used to process short instructions of a signaling type; the method specifically comprises the following steps: Step 1: Design the I / O completion port thread pool and the non-I / O type thread pool; Step 2: When the main thread listens to a task request, it sends the task request to the task queue; when the task time slice is up, the task request is delivered to the state machine for parsing, and the state machine calls different function plug-ins and sends them to the I / O completion port thread pool or non-I / O type thread pool; Specifically, the state machine's analysis of the task request includes: determining whether the task instruction in the task request is a short instruction of the signaling type or an instruction that requires a long time to work, and also determining whether the task instruction is a bookmark instruction; when it is determined to be an instruction that requires a long time to work, the corresponding task request is sent to the I / O completion port thread pool for processing, and steps 3-5 are executed; when it is determined to be a short instruction of the signaling type, the corresponding task request is sent to the non-I / O type thread pool for processing, and step 6 is executed; whether the task request is sent to the I / O completion port thread pool or the non-I / O type thread pool, when the task instruction is determined to be a bookmark instruction, it means that the corresponding task request was not completed in the previous execution cycle and needs to be processed again as a priority; Step 3: When the task request enters the I / O completion port thread pool, a storage file task, a data stream receiving task, and a data stream timeout mechanism are created in the I / O completion port thread pool, and the data stream of the task request is added to the storage queue; Step 4. The I / O completion port starts to receive the data stream after the user request is successfully connected. The data stream will be pushed into the available data packet queue according to the received data packets. When the time slice of the storage file task arrives, the read and write data cache function will traverse the entire current data packet queue, and first determine whether the beginning of the current storage file is a key frame data packet. If not, the current data packet will be discarded until the key frame data packet arrives. When the key frame data packet arrives, the read / write data function in the designed I / O completion port class is called to write the data packet to the disk file, ensuring that the written data is an integer multiple of the disk volume size, and modifying the corresponding offset value in the write function. The offset value is an integer multiple of the disk volume size. Step 5: After the data write operation is completed, the driver notification of the completion of the write operation is obtained in the I / O completion port thread structure, and the overlapped structure is passed out at the same time. This overlapped structure is passed in when the data write function is called in step 6; Step 6: When a task request enters the non-I / O type thread pool, the task delivery function delivers the task request to the task queue of the working thread according to the priority of the task request, and waits for the time slice to arrive to execute the task request; During the execution of steps 3-5, step 6 is executed synchronously.
2. The data processing method based on a mixed task thread pool according to claim 1, characterized in that: The step 1 is specifically as follows: Step 1.1, design a globally unique I / O completion port class for file reading and writing, and associate all related disk I / Os with the I / O completion port class; The I / O completion port class includes a core creation completion port function, a completion port and device association function, a completion port status acquisition function, a simulation completion port status completion function, a cancellation / end completion port function, and a read / write data function; Step 1.2, design an I / O completion port notification structure, which includes the required overlapping structure, a data buffer area opened based on a virtual memory method, and a read and write data buffer function; The overlapping structure in the I / O completion port notification structure is used to complete the transmission of the total amount of bytes of read and write data and the detection of the completion port status each time an I / O request occurs. It uses the original overlapping structure of Windows to allow users to customize the incoming and outgoing information during the working process of the completion port notification mechanism; The starting address of the data cache area opened by virtual memory is an integer multiple of the system allocation granularity. At the same time, the minimum cache size opened by virtual memory is the system paging size of 4KB, which can simultaneously meet the requirements that the size of the I / O completion port operation file read and write cache data and the size of the read and write cache data offset value are integer multiples of the disk volume size; The read and write data cache functions are used to set the offset value in the original overlap structure of Windows. This offset value is an integer multiple of the disk volume size. Step 1.3, design an I / O type thread structure for reading and writing files hosted by an I / O completion port. The main structure of the I / O type thread for reading and writing files consists of a loop whose condition is always true. In the loop, the get completion port status function in the I / O completion port class of step 1.1 is called to determine whether there is a completed file reading and writing task. If so, custom processing of the corresponding task is performed; Step 1.4, design a non-I / O type thread structure driven by a custom time slice; The main structure of the non-I / O type thread consists of a task queue and tasks in the task queue that run according to time; the supporting architecture of the non-I / O type thread structure consists of a delivery task function, which is used to deliver the task to the task queue of a random working thread and wait for it to be executed when the time slice arrives.
3. A data processing system based on a mixed task thread pool, characterized in that: It includes a memory, a processor and a computer program stored in the memory, and the processor executes the computer program to implement the steps of a data processing method based on a mixed task thread pool as described in claim 1 or 2.
4. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by the processor, the steps of the data processing method based on the mixed task thread pool as described in claim 1 or 2 are implemented.
5. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by the processor, the steps of the data processing method based on the mixed task thread pool as described in claim 1 or 2 are implemented.
