Coroutine-based key-value storage system write optimization scheduling method, task scheduler and key-value storage system

By using a coroutine-based write optimization scheduling method for key-value storage systems, write requests are encapsulated into coroutine tasks using a task scheduler, enabling efficient overlapping execution between the processor and disk. This solves the problem of low CPU-disk collaboration efficiency in existing technologies and improves the system's write efficiency and resource utilization.

CN122431818APending Publication Date: 2026-07-21HUAZHONG UNIV OF SCI & TECH +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAZHONG UNIV OF SCI & TECH
Filing Date
2026-04-01
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In high-concurrency scenarios, existing key-value storage systems suffer from low CPU and disk coordination efficiency, resulting in high write request latency, low resource utilization, and difficulty in achieving efficient overlapping execution of CPU computing tasks and disk I/O tasks.

Method used

A write optimization scheduling method based on coroutines is adopted for key-value storage systems. The write request is encapsulated into a coroutine task by the task scheduler, and the state-aware scheduling strategy of I/O task completion queue, post-task queue and write request queue is used to alternately schedule coroutine tasks and I/O polling tasks, so as to achieve efficient overlapping execution of processor and disk.

Benefits of technology

It improves the utilization of processor and disk resources, reduces the overall wait time for write requests and system write latency, and improves the system's write efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122431818A_ABST
    Figure CN122431818A_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on the write optimization scheduling method of key-value storage system of coroutine, task scheduler and key-value storage system, by encapsulating write request as coroutine task, avoid operating system kernel context switching storm;Second, by introducing the queue state perception scheduling strategy for three queues, efficient overlap of processor execution phase and disk execution phase is realized, the resource utilization of processor and disk is significantly improved, and the scheduling strategy is according to the order of I / O task completion queue priority highest, post task queue second, write request queue lowest, so that the key processing path after disk persistence completion can be executed preferentially, and the next batch of write request is awakened in time, so as to reduce the overall waiting time of write request and system write delay;Third, the completion state is detected by independent I / O polling task, instead of using interrupt or callback mode, avoid the kernel state and user state switching overhead caused by interrupt processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of key-value storage technology, and more specifically, relates to a write optimization scheduling method, a task scheduler, and a key-value storage system based on coroutines. Background Technology

[0002] Key-value stores, as a fundamental data storage format, are widely used in database systems, distributed storage systems, and various internet services. To meet the requirements of data consistency, durability, and ordering in high-concurrency scenarios, existing key-value stores typically employ a write-ahead logging (WAL) mechanism to ensure data reliability. That is, when a write request arrives, the system first sequentially writes the corresponding key-value pair change records to the write-ahead log on the persistent medium. After the log is written, the data is written to the memory structure, and the corresponding post-operations are executed. Finally, a successful write result is returned to the client.

[0003] In the aforementioned write process, to improve throughput, the system typically aggregates multiple write requests and submits the write-ahead log (LAB) operations in batches. However, most existing implementations employ threaded or synchronous execution models. During LAB writing, the CPU thread needs to wait for disk I / O operations to complete before executing memory updates and other post-processing logic. While logically simple, this execution model can lead to low coordination efficiency between computing and storage resources and high write request latency in actual operation.

[0004] Specifically, when the write-ahead log is written by the disk device, the CPU is often idle or inefficiently polling, failing to fully utilize its computing power. Conversely, when the CPU performs memory post-processing or waits for the next batch of write requests to be aggregated, the disk device may be idle and unable to maintain a high load. This alternating execution pattern of the CPU and disk over time results in low overall system resource utilization, which can easily become a bottleneck limiting system write throughput and increasing write latency, especially in high-concurrency write scenarios.

[0005] Furthermore, with the continuous improvement of storage media performance and the continuous growth of write request scale, traditional write processing methods based on thread blocking or coarse-grained scheduling are difficult to manage the different execution stages of write requests in a fine manner, and are also difficult to achieve efficient overlapping execution between CPU computing tasks and disk I / O tasks while ensuring write order and persistence.

[0006] Therefore, how to schedule the execution process of write requests more finely and efficiently while ensuring the orderliness and persistence of key-value storage systems, reduce idle time and waiting between the CPU and disk, and improve the overall write efficiency and resource utilization of the system has become a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0007] In view of the above-mentioned defects or improvement needs of the prior art, the present invention provides a write optimization scheduling method, task scheduler and key-value storage system based on coroutines, thereby solving the technical problems of poor overall write efficiency and resource utilization in the prior art.

[0008] To achieve the above objectives, according to a first aspect of the present invention, a write optimization scheduling method for a key-value storage system based on coroutines is provided, comprising: The task scheduler checks whether its I / O task completion queue, post-task queue, and write request queue are empty in each time slice; when a write request for a key-value pair to be written arrives, the write request is encapsulated as a coroutine task and the coroutine task is added to the write request queue of the task scheduler. In the current time slice, when the task scheduler detects that the I / O task completion queue and the post-task queue are empty, it alternately schedules the coroutine tasks and I / O polling tasks in the write request queue. Scheduling the coroutine tasks in the write request queue includes: retrieving and waking up the current coroutine task from the write request queue; scheduling the write task submission task of the current coroutine task to the processor for execution; and after the processor completes the write task submission task, scheduling the persistent storage task of the current coroutine task to the storage medium for execution. The I / O polling task is used to detect the completion status of persistent storage tasks executed by the storage medium, and when it detects that a persistent storage task is complete, it puts the corresponding coroutine task into the I / O task completion queue. When the task scheduler detects that the I / O task completion queue is not empty, it takes the current coroutine task out of the I / O task completion queue, generates the post-processing task corresponding to the current coroutine task, and puts it into the post-task queue. When the task scheduler detects that the I / O task completion queue is empty and the post-processing task queue is not empty, it retrieves the current post-processing task from the post-processing task queue and schedules the current post-processing task to the processor for execution.

[0009] According to the above-described write optimization scheduling method for a coroutine-based key-value storage system, when there are multiple current coroutine tasks retrieved from the write request queue, the write task submission task of the current coroutine task is used to aggregate the key-value pairs to be written corresponding to the multiple current coroutine tasks, generate an aggregated write-ahead log based on the aggregation result, and submit the aggregated write-ahead log to the storage medium; the persistent storage task of the current coroutine task is used to sequentially write the corresponding key-value pairs to be written to the storage medium based on the aggregated write-ahead log.

[0010] According to the above-mentioned write optimization scheduling method for the coroutine-based key-value storage system, when there is only one current coroutine task taken out from the write request queue, the write task submission task of the current coroutine task is used to generate a write-ahead log based on the key-value pair to be written corresponding to the current coroutine task; the persistent storage task of the current coroutine task is used to write the corresponding key-value pair to be written to the storage medium based on the write-ahead log.

[0011] According to the above-described coroutine-based key-value storage system write optimization scheduling method, the step of retrieving the current coroutine task from the I / O task completion queue and generating a post-processing task corresponding to the current coroutine task and placing it into the post-task queue specifically includes: Schedule the coroutine tasks in the write request queue; The post-processing task corresponding to the current coroutine task retrieved from the I / O task completion queue is generated and placed into the post-task queue.

[0012] According to the above-mentioned write optimization scheduling method for a coroutine-based key-value storage system, the post-processing task corresponding to any coroutine task includes at least writing the key-value pair corresponding to the coroutine task into the memory data structure and updating the index information of the memory data structure.

[0013] According to the above-described coroutine-based key-value storage system write optimization scheduling method, the I / O polling task runs in user mode.

[0014] According to a second aspect of the invention, a task scheduler is provided for performing the method as described in the first aspect.

[0015] According to a third aspect of the present invention, a key-value storage system is provided, comprising: a processor, a storage medium, and a task scheduler as described in the second aspect.

[0016] According to a fourth aspect of the invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to perform the method as described in the first aspect.

[0017] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects: By encapsulating write requests as coroutine tasks, when a write request enters the storage media persistence phase, the coroutine is suspended, and its thread resources are immediately released and reclaimed by the task scheduler. These resources are then used to alternately schedule other coroutine tasks or I / O polling tasks in the write request queue, avoiding operating system kernel-mode context switching storms. Secondly, by introducing a queue-state-aware scheduling strategy for the three queues, efficient overlap between the processor execution phase and the disk execution phase is achieved, significantly improving the resource utilization of the processor and disk. Furthermore, the scheduling strategy prioritizes the I / O task completion queue, followed by the post-task queue, and finally the write request queue, ensuring that critical processing paths after disk persistence are executed first and promptly waking up the next batch of write requests, thereby reducing the overall waiting time of write requests and system write latency. Thirdly, by detecting completion status through an independent I / O polling task instead of using interrupts or callbacks, the kernel-mode and user-mode switching overhead caused by interrupt handling is avoided, further improving write efficiency. Attached Figure Description

[0018] Figure 1 A flowchart illustrating the write optimization scheduling method for a coroutine-based key-value storage system provided in this embodiment of the invention; Figure 2 This is a schematic diagram illustrating the state transition of each queue in the write optimization scheduling method of the coroutine-based key-value storage system provided in this embodiment of the invention. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0020] This invention provides a method for optimizing write scheduling in a coroutine-based key-value storage system, such as... Figure 1 As shown, it includes: The task scheduler checks whether its I / O task completion queue, post-task queue, and write request queue are empty in each time slice; when a write request for a key-value pair to be written arrives, the write request is encapsulated as a coroutine task and the coroutine task is added to the write request queue of the task scheduler. In the current time slice, when the task scheduler detects that the I / O task completion queue and the post-task queue are empty, it alternately schedules the coroutine tasks and I / O polling tasks in the write request queue. Scheduling the coroutine tasks in the write request queue includes: retrieving and waking up the current coroutine task from the write request queue; scheduling the write task submission task of the current coroutine task to the processor for execution; and after the processor completes the write task submission task, scheduling the persistent storage task of the current coroutine task to the storage medium for execution. The I / O polling task is used to detect the completion status of persistent storage tasks executed by the storage medium, and when it detects that a persistent storage task is complete, it puts the corresponding coroutine task into the I / O task completion queue. When the task scheduler detects that the I / O task completion queue is not empty, it takes the current coroutine task out of the I / O task completion queue, generates the post-processing task corresponding to the current coroutine task, and puts it into the post-task queue. When the task scheduler detects that the I / O task completion queue is empty and the post-processing task queue is not empty, it retrieves the current post-processing task from the post-processing task queue and schedules the current post-processing task to the processor for execution.

[0021] Specifically, the task scheduler maintains three queues: an I / O task completion queue, a post-task queue, and a write request queue. The task scheduler monitors the status of these three queues at each time slice to determine if they are empty. When a write request for a key-value pair arrives, it needs to be encapsulated as a coroutine task and added to the task scheduler's write request queue. This encapsulation can be achieved using the `bthread_start_background` function from the `bthread` library, or other encapsulation functions from other coroutine libraries; this embodiment of the invention does not specifically limit this approach. By encapsulating all write requests as coroutine tasks, combined with subsequent scheduling methods, system resource utilization can be effectively improved, especially in high-concurrency scenarios, enhancing the overall write efficiency of the key-value storage system. Specifically, after encapsulating write requests as coroutine tasks, thread scheduling, originally handled by the operating system kernel, is moved up to the user-space task scheduler. At this point, the disk write wait time is no longer equivalent to the thread blocking time. The coroutine task only occupies the execution thread in the two instantaneous states of submitting I / O requests and receiving completion notifications. The threads in the other waiting phases can be reclaimed by the task scheduler and reused to execute other ready coroutine tasks, thereby avoiding the context switching storm between the operating system kernel mode and user mode. In high-concurrency write scenarios, this can improve the effective instruction throughput of the CPU.

[0022] In the current time slice, the task scheduler will execute different scheduling strategies based on the current state of the I / O task completion queue, the post-task queue, and the write request queue.

[0023] Specifically, when the task scheduler detects that the I / O task completion queue and the post-task queue are empty, it alternately schedules coroutine tasks and I / O polling tasks in the write request queue. Scheduling coroutine tasks in the write request queue includes: retrieving and waking up the current coroutine task (coroutine tasks are suspended when not scheduled to yield resources to other coroutine tasks), and scheduling the current coroutine task's write task submission task to the processor for execution. When the processor executes the write task submission task, it generates a write-ahead log recording the write operations based on the corresponding key-value pairs to be written for the coroutine task, and submits this write-ahead log to the disk, thereby triggering the disk to execute the current coroutine task's persistent storage task. During the execution of this task, the disk writes the write operations recorded in the write-ahead log to disk and stores the corresponding key-value pairs to be written on the disk. In some embodiments, when multiple current coroutine tasks are retrieved from the write request queue, the write task submission task of the current coroutine task is used to aggregate the key-value pairs to be written corresponding to the multiple current coroutine tasks, generate an aggregated write-ahead log based on the aggregation result, and then submit the aggregated write-ahead log to the storage medium. The persistent storage task of the current coroutine task is then used to sequentially write the corresponding key-value pairs to be written to the storage medium based on the aggregated write-ahead log. In other embodiments, when only one current coroutine task is retrieved from the write request queue, the write task submission task of the current coroutine task is used to generate a write-ahead log based on the key-value pairs to be written corresponding to the current coroutine task; the persistent storage task of the current coroutine task is used to write the corresponding key-value pairs to be written to the storage medium based on the write-ahead log.

[0024] Additionally, the I / O polling task is used to detect the completion status of persistent storage tasks executed by the storage medium, and when the completion of a persistent storage task is detected, the corresponding coroutine task is placed into the I / O task completion queue. In some embodiments, the I / O polling task runs in user mode to avoid switching between operating system kernel mode and user mode, so that the entire write process is executed in user mode.

[0025] If the task scheduler detects that the I / O task completion queue is not empty in the current time slice, it retrieves the current coroutine task from the I / O task completion queue, generates a post-processing task corresponding to the current coroutine task, and places it in the post-task queue. In some embodiments, when the I / O task completion queue is detected to be not empty, the coroutine tasks in the write request queue can be scheduled first, the next batch of coroutine tasks in the write request queue can be retrieved and woken up to schedule the write task submission task of the corresponding coroutine task, and the post-processing task corresponding to the current coroutine task retrieved from the I / O task completion queue can be generated and placed in the post-task queue. This allows the disk to synchronously execute the persistent storage tasks corresponding to the next batch of coroutine tasks while the subsequent processor is executing the tasks in the post-task queue, achieving efficient collaborative scheduling of different execution stages of write requests and improving the parallel utilization of the processor and disk.

[0026] If the task scheduler detects that the I / O task completion queue is empty and the subsequent task queue is not empty in the current time slice, it retrieves the current post-processing task from the subsequent task queue and schedules it to the processor for execution. Therefore, at the task scheduler, the processing priorities of tasks in the I / O task completion queue, subsequent task queue, and write request queue, from highest to lowest, are: tasks in the I / O task completion queue, tasks in the subsequent task queue, and tasks in the write request queue. In some embodiments, the post-processing task corresponding to any coroutine task includes at least writing the key-value pair corresponding to the coroutine task into the memory data structure and updating the index information of the memory data structure.

[0027] As can be seen, the post-processing tasks and persistent storage tasks of different coroutine tasks can be completed in parallel by the processor and disk throughout the entire timeline. Both post-processing tasks and persistent storage tasks are time-consuming data writing operations. Therefore, by processing the post-processing tasks and persistent storage tasks of different coroutine tasks in parallel, the parallel utilization of the processor and disk can be effectively improved, thereby improving the efficiency of key-value pair writing in the system.

[0028] The following combination Figure 2 The embodiments of the present invention will be further explained. In these embodiments, four state changes of the write optimization scheduling method for a coroutine-based key-value storage system are demonstrated. Each change from ① to ④ represents the task scheduler reselecting a task for execution.

[0029] In the example, the left side shows the system's processor and storage medium (i.e., disk), while the right side shows the three queues of the task scheduler and the tasks in the queues.

[0030] Initially, all queues are empty. Then, write requests arrive, as shown in state ①, requiring two writes.<K1,V1> ,<K2,V2> It is placed in the write request queue; at this time, the I / O completion queue and the post-task queue are empty, and the task scheduler is in the scheduling state of processing write requests, aggregation, and submitting persistence requests to the storage medium.

[0031] Then, the task scheduler switches to a polling state to check if any persistent tasks have been completed, at which point a write request is made.<K3,V3> Arrival, as shown in state ②; when a persistent task is found to be completed, the completed task will be added to the I / O task completion queue.

[0032] At this point, as in state ③, the task scheduler checks the three queues again, prioritizing the coroutine tasks in the I / O task completion queue. Externally, the task scheduler processes the tasks in the I / O task completion queue, wakes up and submits the K3,,V3 persistence request to the storage medium, and submits...<K1,V1> ,<K2,V2> Post-processing tasks are placed in the post-task queue.

[0033] Finally, as shown in state ④, the task scheduler selects a post-processing task from the post-task queue, executes the post-processing task, and returns a success message.

[0034] Furthermore, the system state will continue to flow to state ②, and if there is a new write request, the state will continue to flow in sequence.

[0035] In summary, the method provided by this invention encapsulates write requests as coroutine tasks, so that when a write request enters the storage medium persistence stage, the coroutine is suspended, and the thread resources it occupies are immediately released and reclaimed by the task scheduler for alternating scheduling of other coroutine tasks or I / O polling tasks in the write request queue, thus avoiding operating system kernel mode context switching storms. Secondly, by introducing a queue state-aware scheduling strategy for the three queues, efficient overlap between the processor execution stage and the disk execution stage is achieved, significantly improving the resource utilization of the processor and disk. Moreover, the scheduling strategy follows the order of highest priority for the I / O task completion queue, followed by the post-task queue, and lowest priority for the write request queue, so that critical processing paths after disk persistence are completed can be executed first, and the next batch of write requests can be woken up in time, thereby reducing the overall waiting time of write requests and system write latency. Thirdly, by detecting the completion status through an independent I / O polling task instead of using interrupts or callbacks, the kernel mode and user mode switching overhead caused by interrupt handling is avoided, further improving write efficiency.

[0036] This invention provides a task scheduler for executing the methods described in any of the above embodiments.

[0037] This invention provides a key-value storage system, characterized in that it includes: a processor, a storage medium, and a task scheduler as described in the above embodiments.

[0038] This invention provides a computer-readable storage medium storing computer instructions that cause a processor to perform the method described in any of the above embodiments.

[0039] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A write optimization scheduling method for a key-value storage system based on coroutines, characterized in that, include: The task scheduler checks whether its I / O task completion queue, post-task queue, and write request queue are empty in each time slice; when a write request for a key-value pair to be written arrives, the write request is encapsulated as a coroutine task and the coroutine task is added to the write request queue of the task scheduler. In the current time slice, when the task scheduler detects that the I / O task completion queue and the post-task queue are empty, it alternately schedules the coroutine tasks and I / O polling tasks in the write request queue. Scheduling the coroutine tasks in the write request queue includes: retrieving and waking up the current coroutine task from the write request queue; scheduling the write task submission task of the current coroutine task to the processor for execution; and after the processor completes the write task submission task, scheduling the persistent storage task of the current coroutine task to the storage medium for execution. The I / O polling task is used to detect the completion status of persistent storage tasks executed by the storage medium, and when it detects that a persistent storage task is complete, it puts the corresponding coroutine task into the I / O task completion queue. When the task scheduler detects that the I / O task completion queue is not empty, it takes the current coroutine task out of the I / O task completion queue, generates the post-processing task corresponding to the current coroutine task, and puts it into the post-task queue. When the task scheduler detects that the I / O task completion queue is empty and the post-processing task queue is not empty, it retrieves the current post-processing task from the post-processing task queue and schedules the current post-processing task to the processor for execution.

2. The write optimization scheduling method for a coroutine-based key-value storage system as described in claim 1, characterized in that, When there are multiple current coroutine tasks retrieved from the write request queue, the write task submission task of the current coroutine task is used to aggregate the key-value pairs to be written corresponding to the multiple current coroutine tasks, generate an aggregated write-ahead log based on the aggregation result, and submit the aggregated write-ahead log to the storage medium; the persistent storage task of the current coroutine task is used to sequentially write the corresponding key-value pairs to be written to the storage medium based on the aggregated write-ahead log.

3. The write optimization scheduling method for a coroutine-based key-value storage system as described in claim 1, characterized in that, When there is only one current coroutine task retrieved from the write request queue, the write task submission task of the current coroutine task is used to generate a write-ahead log based on the key-value pair to be written corresponding to the current coroutine task; the persistent storage task of the current coroutine task is used to write the corresponding key-value pair to be written to the storage medium based on the write-ahead log.

4. The write optimization scheduling method for a coroutine-based key-value storage system as described in claim 1, characterized in that, The step of retrieving the current coroutine task from the I / O task completion queue and generating a corresponding post-processing task for the current coroutine task, which is then placed into the post-task queue, specifically includes: Schedule the coroutine tasks in the write request queue; The post-processing task corresponding to the current coroutine task retrieved from the I / O task completion queue is generated and placed into the post-task queue.

5. The write optimization scheduling method for a coroutine-based key-value storage system as described in claim 1, characterized in that, The post-processing task corresponding to any coroutine task includes at least writing the key-value pair corresponding to the coroutine task into the memory data structure and updating the index information of the memory data structure.

6. The write optimization scheduling method for a coroutine-based key-value storage system as described in claim 1, characterized in that, The I / O polling task runs in user mode.

7. A task scheduler, characterized in that, The task scheduler is used to execute the coroutine-based key-value storage system write optimization scheduling method as described in any one of claims 1-6.

8. A key-value storage system, characterized in that, include: A processor, a storage medium, and a task scheduler as described in claim 7.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a processor to execute the write optimization scheduling method for a coroutine-based key-value storage system as described in any one of claims 1-6.