A key-value request parallel scheduling method and system

By creating multiple instances, queues and threads in the key-value storage system, and using numbering and hash mapping rules to process requests, the problem of traditional systems failing to make full use of high bandwidth and multi-core CPUs is solved, and the key-value requests are significantly improved. Processing speed and parallelism.

CN113568908BActive Publication Date: 2024-11-19HUAZHONG UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110804293.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-16
Publication Date
2024-11-19
Estimated Expiration
2041-07-16

AI Technical Summary

Technical Problem

Traditional key-value storage systems fail to make full use of parallelism and bandwidth on high-bandwidth storage devices and multi-core CPU hardware platforms, resulting in limited request processing speed, high CPU single-core occupancy rate, and failure to effectively improve performance.

Method used

By creating multiple key-value storage system instances, request queues and request processing threads, and through number binding, the request is assigned to the corresponding queues and threads using preset mapping rules, supporting parallel processing and batch execution, using hash functions Implement load balancing.

Benefits of technology

It improves the processing speed and parallelism of key-value requests, reduces resource competition and data synchronization, improves system performance, and realizes effective utilization of high-bandwidth storage devices and multi-core CPUs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113568908B_ABST
    Figure CN113568908B_ABST
Patent Text Reader

Abstract

The present invention discloses a key-value request parallel scheduling method and system, which deploy multiple key-value storage system instances, multiple request processing threads and multiple request queues, and bind them one by one through numbers; when receiving a key-value request issued by a user, by executing a request response step for each key-value request, it is ensured that when there are multiple concurrent user requests, they can be allocated to multiple request queues, and sent to multiple key-value storage system instances for execution through multiple parallel request processing threads, thereby increasing the parallelism of IO and realizing the utilization of CPU multi-threading; at the same time, the keys managed by each key-value storage system instance are independent of each other, avoiding resource competition and data synchronization between different key-value storage system instances, so as to facilitate efficient parallel execution, thereby realizing a significant improvement in the key-value request processing speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer storage, and more specifically, relates to a key-value request parallel scheduling method and system. Background Art

[0002] In recent years, with the development and application of information technologies such as cloud computing, big data, the Internet of Things, and artificial intelligence, the amount of data has shown explosive growth. How to effectively store data and provide efficient data access services has become an important issue for existing computer storage systems.

[0003] The key-value storage system is a common computer storage system. The unit of data storage is a key-value pair consisting of two pieces of data, a key and a value. The key-value storage system is used to store key-value pair data in a persistent storage device and provide the function of querying key-value pairs by pressing a key. The key-value storage request interface includes key-value requests such as storage (put), modification (update), deletion (delete), reading (get), and range query (scan) of key-value pairs. The parameters of the storage and modification requests are key and value, which are used to store new key-value pairs or modify the corresponding values ​​according to the key; the parameter of the deletion request is key, which is used to delete the existing key-value pairs according to the key. The parameter of the read request is key, which is used to query whether the corresponding key-value pair is stored according to the key data, and return the value data if it exists. The input parameters of the range query request are a start key and an end key, which are used to query and return all key-value pair data within the range from the start key to the end key.

[0004] Traditional key-value storage systems, such as LevelDB, RocksDB, and Cassandra, are often designed for low-parallelism and low-bandwidth storage devices, such as disks, and can achieve high bandwidth using only a single thread. However, new high-bandwidth storage devices (such as SSDs, NVMs, etc.) have higher bandwidth and parallelism. The single-thread IO method of traditional key-value storage systems cannot fully utilize the bandwidth of storage devices, resulting in the use of high-performance storage devices not being able to effectively improve the performance of key-value storage systems. In addition, traditional key-value storage systems often use serial scheduling for concurrent key-value storage requests, and multiple concurrent requests are executed one by one in sequence in steps such as writing logs. Therefore, the request processing flow of a single key-value storage system often uses only a single thread, resulting in an excessively high CPU single-core occupancy rate, limiting the request processing speed, and not fully utilizing the multi-threaded parallel processing capabilities of modern computer multi-core CPUs. Therefore, the request processing speed of traditional key-value storage systems on hardware platforms based on high-bandwidth storage devices and multi-core CPUs has not been improved as it should be. Summary of the invention

[0005] In view of the above defects or improvement needs of the prior art, the present invention provides a key-value request parallel scheduling method and system, thereby solving the technical problems of the existing key-value storage system's lack of parallelism and low bandwidth utilization.

[0006] To achieve the above object, according to one aspect of the present invention, a key-value request parallel scheduling method is provided, comprising:

[0007] S1, create n key-value storage system instances, request queues, and request processing threads, and number them in the same way; where n is an integer greater than 1;

[0008] S2, receiving a user request and determining the type of the request;

[0009] S3, if the request is a key-value pair storage, modification, deletion or read request, determine the number i corresponding to the key parameter of the request according to the preset mapping rule; put the request into the request queue numbered i, waiting to be acquired by the request processing thread numbered i and sent to the key-value storage system instance numbered i for execution;

[0010] If the request is a key-value pair range query request, n copies of the request are placed in n request queues respectively, waiting to be acquired by corresponding n request processing threads respectively and sent to corresponding n key-value storage system instances for execution.

[0011] Preferably, the step of waiting for the request processing thread numbered i to obtain and send the request to the key-value storage system instance numbered i for execution comprises:

[0012] Step C1, the request processing thread numbered i checks whether there is a request in the request queue numbered i, and if so, obtains the request from the request queue and proceeds to step C2; if not, continues to poll and check the request queue;

[0013] Step C2, the request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, and then proceeds to step C3;

[0014] Step C3: the request processing thread receives the processing result fed back by the key-value storage system instance, and sends the processing result to the user, and then returns to step C1.

[0015] Preferably, the request processing thread numbered i checks whether there is a request in the request queue numbered i, and if so, obtains the request from the request queue, specifically:

[0016] If there are multiple adjacent requests of the same type in the request queue, the request processing thread obtains the multiple adjacent requests of the same type in batches.

[0017] Preferably, the request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, specifically:

[0018] In the case where the multiple adjacent requests of the same type are key-value pair storage, modification or deletion requests, if the key-value storage system instance numbered i supports batch execution of the requests of the same type, the requests of the same type are encapsulated into a batch request and sent to the key-value storage system instance for batch execution; otherwise, the requests of the same type are sent sequentially to the key-value storage system instance for execution;

[0019] In the case where the multiple adjacent requests of the same type are key-value pair read requests, if the key-value storage system instance numbered i supports batch execution of the requests of the same type, the requests of the same type are encapsulated into a batch request and sent to the key-value storage system instance for batch execution; otherwise, the requests of the same type are sent simultaneously to the key-value storage system instance in a multi-threaded parallel manner for execution.

[0020] Preferably, if the multiple adjacent requests of the same type are key-value pair storage, modification or deletion requests, when the sum of the key-value pair data sizes of the multiple adjacent requests of the same type obtained by the request processing thread is larger than the minimum write unit of the underlying storage device, the request processing thread stops obtaining the requests of the same type;

[0021] If the multiple adjacent requests of the same type are key-value pair read requests, when the number of the multiple adjacent requests of the same type obtained by the request processing thread is greater than the number of CPU cores, the acquisition of the requests of the same type is stopped.

[0022] Preferably, the preset mapping rule is determined based on a hash function.

[0023] Preferably, the waiting is respectively acquired by the corresponding n request processing threads and sent to the corresponding n key-value storage system instances for execution, including:

[0024] Step D1, n request processing threads respectively check whether there are requests in the corresponding request queues, if yes, they respectively obtain the requests from the request queues and enter step D2; if no, they continue to poll and check the request queues;

[0025] Step D2, the n request processing threads respectively send the acquired requests to the corresponding key-value storage system instances for execution, and then proceed to step D3;

[0026] Step D3, the n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instances, and respectively send the processing results to the user, and then return to step D1.

[0027] Preferably, the n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instance, and respectively send the processing results to the user, specifically:

[0028] The processing results are sent to the user in ascending order of the keys.

[0029] Preferably, after numbering the n key-value storage system instances, the method further includes:

[0030] The correspondence between the n key-value storage system instances and the serial numbers is stored.

[0031] According to another aspect of the present invention, a key-value request parallel scheduling system is provided, comprising:

[0032] The system initialization module is used to number n key-value storage system instances; create n request queues and request processing threads and number them in the same way so that each key-value storage system instance, request queue and request processing thread corresponds to each other; wherein n is an integer greater than 1,

[0033] A request response module, used for determining the type of the request when receiving the request;

[0034] A request processing module, for determining, if the request is a key-value pair storage, modification, deletion or read request, a number i corresponding to the key parameter of the request according to a preset mapping rule; placing the request into a request queue numbered i, waiting to be acquired by a request processing thread numbered i and sent to a key-value storage system instance numbered i for execution;

[0035] If the request is a key-value pair range query request, n copies of the request are placed in n request queues respectively, waiting to be acquired by corresponding n request processing threads respectively and sent to corresponding n key-value storage system instances for execution.

[0036] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects compared with the prior art:

[0037] 1. The method provided by the present invention deploys multiple key-value storage system instances, multiple request processing threads and multiple request queues, and binds them one by one through numbers; when receiving a key-value request issued by a user, by executing a request response step for each key-value request, it is ensured that when there are multiple concurrent user requests, they can be allocated to multiple request queues, and sent to multiple key-value storage system instances for execution through multiple parallel request processing threads, thereby increasing the parallelism of IO and realizing the utilization of CPU multi-threading; at the same time, the keys managed by each key-value storage system instance are independent of each other, avoiding resource competition and data synchronization between different key-value storage system instances, so as to facilitate efficient parallel execution, thereby realizing a significant improvement in the key-value request processing speed.

[0038] 2. The method provided by the present invention, when the request is a key-value pair storage, modification, deletion or read request, ensures that the same key will only be mapped to the same queue through a preset mapping rule. Therefore, the keys stored in each key-value storage system instance are independent. When responding to a key-value pair read request, it is only necessary to query the key-value storage system instance with the corresponding number according to the mapping rule, thereby ensuring that the key-value pair storage, modification, deletion or read request with the same key parameter will ultimately be executed on only one key-value storage system instance, and no unnecessary access overhead will occur. Multiple key-value requests whose key parameters meet the mapping rules can be executed on each key-value storage system instance; when the request is a key-value pair range query request, the range query request is copied and placed in all request queues, ensuring the parallel execution of the range query request, accelerating the processing speed of the range query request, and reducing processing delays.

[0039] 3. The method provided by the present invention combines and executes multiple adjacent key-value pair storage, modification or deletion requests when the request processing thread obtains a request from the head of the corresponding partition request queue. On the one hand, it reduces the software overhead of separately processing multiple requests, and on the other hand, it adapts to the IO granularity of the underlying storage device, further improving the processing speed of key-value pair storage, modification, deletion or reading requests; combines and executes multiple adjacent key-value pair read requests in parallel, thereby improving the parallelism of processing key-value pair read requests and further improving the processing speed of key-value pair read requests.

[0040] 4. The method provided by the present invention limits the number of storage, modification, deletion or reading requests for key-value pairs obtained in batches, thereby reducing the tail delay of request processing.

[0041] 5. The method provided by the present invention uses a hash function as a mapping rule from a key parameter to a number i to perform request allocation, and can evenly distribute requests to each request queue, thereby ensuring the load balancing of each key-value storage system instance; in the case of such load balancing, multiple key-value storage system instances can fully process requests in parallel, further improving the overall parallelism of the system, maintaining the system in a high parallelism state, thereby improving the processing speed of key-value requests.

[0042] 6. The method provided by the present invention, after numbering the n key-value storage system instances, also includes storing the correspondence between the n key-value storage system instances and the numbers, and can replace the initialization of the key-value storage system instances by loading the existing n key-value storage system instances and their numbers. When the scheduling system is shut down due to human error or failure, if the entire scheduling system needs to be restarted, the original numbering information can be restored according to the records to restore the original mapping relationship and binding relationship. Because the correspondence between the number and the key-value storage system instance has not changed after the restart, the key-value pairs stored by executing the key-value storage request before the scheduling system is shut down can be correctly read. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 This is a flowchart of a key-value request parallel scheduling method provided by the present invention;

[0044] Figure 2 The second flowchart of the key-value request parallel scheduling method provided by the present invention;

[0045] Figure 3 The third flowchart of the key-value request parallel scheduling method provided by the present invention;

[0046] Figure 4 Schematic diagram of the dispatch method for existing key-value requests;

[0047] Figure 5 The fourth flowchart of the key-value request parallel scheduling method provided by the present invention;

[0048] Figure 6 The fifth flowchart of the key-value request parallel scheduling method provided by the present invention;

[0049] Figure 7 A schematic diagram of a process flow of batch processing, storage, modification or deletion requests by a request processing thread in the key-value request parallel scheduling method provided by the present invention;

[0050] Figure 8 This is one of the schematic diagrams of the process of batch processing of read requests by a request processing thread in the key-value request parallel scheduling method provided by the present invention;

[0051] Fig. 9This is the second schematic diagram of the process flow of batch processing of read requests by a request processing thread in the key-value request parallel scheduling method provided by the present invention. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0053] The embodiment of the present invention provides a key-value request parallel scheduling method, such as Figure 1-Figure 2 As shown, including:

[0054] S1, create n key-value storage system instances, request queues, and request processing threads, and number them in the same way; where n is an integer greater than 1.

[0055] Specifically, step S1 is system initialization, including initialization of n key-value storage system instances, initialization of n request queues, and initialization of n request processing threads.

[0056] The number n of key-value storage system instances is a number preset by a user. According to the number n of instances preset by the user, n key-value storage system software instances are initialized: the n key-value storage system software instances are numbered from 1 to n;

[0057] At the same time, n request queues and n request processing threads are created, and the request queues and request processing threads are also numbered from 1 to n, and the initialization of the n request queues and n request processing threads is completed to indicate a one-to-one binding relationship between the three.

[0058] The above system initialization step initializes multiple key-value storage instances and numbers them, creates the same number of request queues and request processing threads, and binds them one by one with numbers.

[0059] Preferably, after numbering the n key-value storage system instances, the method further includes:

[0060] The correspondence between the n key-value storage system instances and the serial numbers is stored.

[0061] Specifically, the correspondence between the n key-value storage system instances and the numbers is recorded and stored on the hardware; when there are already n initialized key-value storage system instances, and the correspondence between the n key-value storage system instances and the numbers has been recorded and stored, the initialization of the key-value storage system instances can be replaced by loading the existing n key-value storage system instances and their numbers.

[0062] The above initialization method is applicable to when the scheduling system is shut down due to human error or failure. If the entire scheduling system needs to be restarted, the original numbering information can be restored according to the records to restore the original mapping and binding relationships. Because the corresponding relationship between the number and the key-value storage system instance has not changed after the restart, the key-value pairs stored by executing the key-value storage request before the scheduling system is shut down can be correctly read.

[0063] Preferably, when the system initialization step is performed for the first time, after the n key-value storage system instances are numbered, the correspondence between the n key-value storage system instances and the numbers is recorded and stored; or when the system initialization step is not performed for the first time, after the n key-value storage system instances are numbered, the correspondence between the n key-value storage system instances and the numbers is recorded and stored.

[0064] Since the serial number of the key-value storage system instance is recorded and stored, the key range stored in a specific key-value storage system instance can be known according to the preset mapping relationship.

[0065] S2, receiving a user request and determining the type of the request;

[0066] S3, if the request is a key-value pair storage, modification, deletion or read request, determine the number i corresponding to the key parameter of the request according to the preset mapping rule; put the request into the request queue numbered i, waiting to be obtained by the request processing thread numbered i and sent to the key-value storage system instance numbered i for execution; wherein i∈n;

[0067] If the request is a key-value pair range query request, n copies of the request are placed in n request queues respectively, waiting to be acquired by corresponding n request processing threads respectively and sent to corresponding n key-value storage system instances for execution.

[0068] Key-value requests include requests to store, modify, delete, read, and range query key-value pairs.

[0069] Specifically, the steps S2-S3 include request response and request processing, and the request response step is called when a key-value request is received.

[0070] When a request is received, the type of the request is determined; when the request is a key-value pair storage, modification, deletion or read request, the request response includes:

[0071] B1: Calculate the number: when a key value request is received, the number i corresponding to the key parameter is calculated according to the key parameter and the number in the key value request and the preset mapping rule, and then enter step B2;

[0072] B2 request allocation: put the request at the end of the request queue numbered i, and then wait for the request to be obtained by the request processing thread and sent to the key-value storage system instance numbered i for execution.

[0073] That is, when a key-value request sent by a user is received, the key-value request is allocated to a corresponding request queue according to a preset mapping relationship using a request response step.

[0074] The method provided by the present invention deploys multiple key-value storage system instances, multiple request processing threads and multiple request queues, and binds them one by one through numbers; distributes multiple key-value requests sent by users to multiple request queues, and sends them to multiple key-value storage system instances for execution through multiple parallel request processing threads, making full use of the parallel IO capability of high-bandwidth storage media and the multi-thread processing capability of modern computer CPUs; at the same time, the keys managed by each key-value storage system instance are independent of each other, avoiding resource competition and data synchronization between different key-value storage system instances, so as to facilitate efficient parallel execution, thereby achieving a significant improvement in the key-value request processing speed.

[0075] Preferably, the preset mapping rule is determined based on a hash function.

[0076] Specifically, in step B1, when the received request is a key-value pair storage, modification, deletion, or read request, a hash function is used as a mapping rule from a key parameter to number i, that is, the result modulo n of the key data is added by one to obtain i.

[0077] Preferably, the waiting is obtained by the request processing thread numbered i and sent to the key-value storage system instance numbered i for execution, that is, the request processing step, such as Figure 3 As shown, including:

[0078] Step C1, the request processing thread numbered i checks whether there is a request in the request queue numbered i. If so, it obtains the request from the request queue and enters step C2; if not, it continues to poll and check the request queue.

[0079] Specifically, the request processing step is executed by the request processing thread created in step S1. The request processing thread checks whether there is a key value request in the request queue to which it is bound. If there is a request in the request queue, the key value request is obtained from the head of the request queue, and then step C2 is entered; if there is no request, the request queue is continuously polled and checked.

[0080] Step C2: the request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, and then proceeds to step C3.

[0081] Specifically, after obtaining the key-value request, the request processing thread sends the obtained request to the bound key-value storage system instance for execution, and enters step C3 after waiting for the execution to be completed.

[0082] Step C3: the request processing thread receives the processing result fed back by the key-value storage system instance, and sends the processing result to the user, and then returns to step C1.

[0083] Specifically, the request processing thread receives the processing result fed back by the key-value storage system instance after the execution is completed, and the request is deemed to be completed, and the process returns to step C1.

[0084] Preferably, the request processing thread numbered i checks whether there is a request in the request queue numbered i, and if so, obtains the request from the request queue, specifically:

[0085] If there are multiple adjacent requests of the same type in the request queue, the request processing thread obtains the multiple adjacent requests of the same type in batches.

[0086] Specifically, batch processing of requests can reduce software overhead, and processing multiple requests simultaneously can also help increase parallelism. However, if read requests and write requests are processed simultaneously, incorrect data may be read because the order of request execution cannot be guaranteed. Therefore, batch acquisition requests are limited to only adjacent requests of the same type.

[0087] The request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, specifically:

[0088] In the case where the multiple adjacent requests of the same type are key-value pair storage, modification or deletion requests, if the key-value storage system instance numbered i supports batch execution of the requests of the same type, the requests of the same type are encapsulated into a batch request and sent to the key-value storage system instance for batch execution; otherwise, the requests of the same type are sent sequentially to the key-value storage system instance for execution;

[0089] In the case where the multiple adjacent requests of the same type are key-value pair read requests, if the key-value storage system instance numbered i supports batch execution of the requests of the same type, the requests of the same type are encapsulated into a batch request and sent to the key-value storage system instance for batch execution; otherwise, the requests of the same type are sent simultaneously to the key-value storage system instance in a multi-threaded parallel manner for execution.

[0090] Specifically, when the request processing thread obtains a request from the head of the corresponding partition request queue (ie, step C1), if the head of the queue has multiple adjacent key-value pair storage, modification or deletion requests or multiple adjacent key-value pair read requests, these requests are obtained in batches and processed in batches in the subsequent step C2.

[0091] Among them, for multiple key-value pair storage, modification or deletion requests, if the key-value storage system instance supports batch storage transactions, these requests are encapsulated into a batch storage transaction and let the bound key-value storage system instance process it. If it does not support it, it is processed in sequence on the key-value storage system instance.

[0092] For multiple key-value pair read requests, if the key-value storage system instance supports batch read transactions, these requests are encapsulated into a batch read transaction and sent to the bound key-value storage system instance for processing. If it does not support, these read requests are sent to the key-value storage system instance in a multi-threaded parallel manner for processing.

[0093] This batch processing approach leverages the capabilities of the key-value storage system itself as much as possible, further reducing software overhead.

[0094] Preferably, if the multiple adjacent requests of the same type are key-value pair storage, modification or deletion requests, then when the sum of the key-value pair data sizes of the multiple adjacent requests of the same type obtained by the request processing thread is larger than the minimum write unit of the underlying storage device, stop obtaining the requests of the same type.

[0095] Specifically, there is a limit on the number of key-value pair storage, modification or deletion requests obtained in batches. When the sum of the key-value pair data sizes of the obtained requests is larger than the minimum write unit of the underlying storage device, no more requests will be obtained and the batch processing step C2 will be directly entered.

[0096] Processing too many storage, modification, or deletion requests at one time will increase the tail latency of request processing, so the number of batch acquisition requests needs to be limited. For storage, modification, or deletion requests, the sum of the sizes of key-value pairs contained in a batch of key-value requests determines the IO size of the key-value storage system instance writing logs. When the IO size is smaller than the minimum write unit of the underlying storage device, write amplification will occur. When the IO size reaches the minimum write unit of the underlying storage device, it is conducive to IO parallelism.

[0097] If the multiple adjacent requests of the same type are key-value pair read requests, when the number of the multiple adjacent requests of the same type obtained by the request processing thread is greater than the number of CPU cores, the acquisition of the requests of the same type is stopped.

[0098] Specifically, there is a limit on the number of read requests for batch acquisition of key-value pairs. When the number of acquired requests is greater than the number of CPU cores, no more requests will be acquired and the batch processing step C2 will be directly entered.

[0099] Processing too many key-value pair read requests in batches at one time will also increase the tail latency of request processing, so the number of batch acquisition requests also needs to be limited. For key-value pair read requests, regardless of whether the underlying storage device supports batch read transactions, multi-threading will eventually be used for parallel reading. However, the performance improvement brought by the number of threads exceeding the number of CPU cores is limited, and more thread creation overhead will be introduced.

[0100] If the request is a key-value pair range query request, the request response includes:

[0101] N identical range query requests are copied and put into the n request queues respectively, waiting to be acquired by the corresponding n request processing threads respectively and sent to the corresponding n key-value storage system instances for execution.

[0102] When the received request is a range query request, the calculation step is not performed. Instead, n identical range query requests are copied and placed in all n request queues, waiting to be obtained by the corresponding n request processing threads and sent to the corresponding n key-value storage system instances for execution.

[0103] Since the range query request may involve all key-value storage system instances, the request is copied to all request queues so that all key-value storage system instances can execute in parallel with higher efficiency.

[0104] Preferably, the waiting is respectively acquired by the corresponding n request processing threads and sent to the corresponding n key-value storage system instances for execution, that is, the request processing step includes:

[0105] In step D1, n request processing threads respectively check whether there are requests in the corresponding request queues. If yes, they obtain the requests from the request queues respectively and enter step D2; if no, they continue to poll and check the request queues.

[0106] Specifically, the request processing step is executed by the request processing thread created in step S1. The request processing thread checks whether there is a key value request in the request queue to which it is bound. If there is a request in the request queue, the key value request is obtained from the head of the request queue, and then step D2 is entered; if there is no request, the request queue is continuously polled and checked.

[0107] Step D2: The n request processing threads respectively send the obtained requests to the corresponding key-value storage system instances for execution, and then proceed to step D3.

[0108] Specifically, after obtaining the key-value request, the request processing thread sends the obtained request to the bound key-value storage system instance for execution, and enters step D3 after waiting for the execution to be completed.

[0109] Step D3, the n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instances, and respectively send the processing results to the user, and then return to step D1.

[0110] Specifically, the request processing thread receives the processing result fed back by the key-value storage system instance after the execution is completed, and the request is deemed to be completed, and the process returns to step D1.

[0111] Preferably, the n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instance, and respectively send the processing results to the user, specifically:

[0112] The processing results are sent to the user in ascending order of the keys.

[0113] Specifically, when all n replicated range query requests are executed, the results are sorted by key and returned to the user together.

[0114] Since the key-value storage system often returns the results to the user in ascending order of the key when processing range query requests, in order to ensure that the execution results obtained by the user sending the range query request are consistent with those obtained when this scheduling method is not used, after all key-value storage system instances return the execution results, the results are sorted and then returned to the user.

[0115] The application scenario of the present invention is in computer hardware and software systems, which is used to store key-value data on storage devices according to user requests and provide functions such as addition, deletion, modification, and query (storage, deletion, modification, reading, and range query). Figure 4As shown, the upper layer of the program (such as LevelDB, RocksDB, Cassandra, etc., referred to as the key-value storage system instance) that actually performs the functions of storing, deleting, modifying, reading, and range querying key-value pairs is the user application, and the lower layer is the file system and the storage devices it manages (such as HDD, SSD, NVM, etc.), and the storage device can be one or more. The user sends key-value requests to the key-value storage system through the user application, including storage requests, deletion requests, modification requests, read requests, range query requests, and other types. When processing the request, the key-value storage system will store the key-value data and other index data in the file system in the form of files, and then the file system will store them in the storage device to ensure the persistence of the data in the hardware. In this case, although multiple user applications are allowed to send requests at the same time, when a single key-value storage system processes these requests, it is often unable to utilize the full bandwidth of the underlying storage device due to insufficient parallelism.

[0116] The application examples provided by the present invention are as follows: Figure 5 As shown in the figure, the position of the scheduling system in the specific application scenario is known. Figure 4 Compared with the common application cases shown in the figure, the present invention adds a scheduling system between the key-value storage system and the user application, and allows multiple key-value storage systems to exist at the same time (each key-value storage system is referred to as a key-value storage system instance in the present invention). The request sent by the user application is scheduled by the scheduling system and is eventually assigned to multiple key-value storage systems for parallel execution. Each key-value storage system instance maintains the key-value data and index data that it needs to store in the form of files on the file system. Ultimately, these data are stored by the file system on one or more storage devices at the bottom.

[0117] The method provided by the present invention is described below with a specific example.

[0118] like Figure 6 As shown, the preset number of instances n=4, the system initialization step S1 initializes 4 key-value storage system instances, creates 4 request queues and 4 request processing threads, and binds them one by one in the way of marking 1 to 4 numbers, and divides them into four groups.

[0119] If the initialization step is performed for the first time when the scheduling system is initialized, the corresponding relationship between the key-value storage system instance and the number can be recorded and stored. If the initialization step is performed when the scheduling system is restarted after being shut down, the number of the key-value storage instance can be restored by using the recorded corresponding relationship between the key-value storage instance and the number, and a new request queue and request processing thread can be established and bound to it.

[0120] The key-value storage system used will store all its data in the same directory, and has the function of restoring the key-value storage system by inputting the directory where the data is located after it is shut down. At this time, different directories can be used as data storage directories for different key-value storage system instances during the initialization, and the numbers of the corresponding key-value storage system instances are recorded by the directory names; when restarting, the key-value storage system instances are restored by using these directories, and their numbers in the scheduling system are restored according to the directory names.

[0121] Step S2, upon receiving a key value request, determining the type of the request;

[0122] Step S3: If the request is a key-value pair storage, modification, deletion or read request, the request response step includes:

[0123] B1 Calculate the number: When a key value request is received, the number i corresponding to the key parameter is calculated according to the key parameter in the key value storage request and the preset mapping rule, and then enter step B2. The preset mapping rule is: the number i is equal to the modulo 4 of the key parameter plus one. Therefore, the numbers i calculated for the four key value requests with key parameters of 1, 10, 7, and 0 are 2, 3, 4, and 1 respectively.

[0124] B2 Request Allocation: Put the request at the end of the request queue numbered i, and then wait for the request to be obtained and executed by the request processing thread. Figure 1 In the basic embodiment shown, four key value requests with different calculated numbers i are placed at the end of four request queues.

[0125] If the request is a key-value pair range query request, the request response step includes:

[0126] Copy n requests and put them at the end of each request queue. After all the requests are executed, sort the processing results of each request by key, and then return the results to the user and end the request response step.

[0127] The request processing steps include:

[0128] C1, the request processing thread checks whether there is a key-value request in the request queue to which it is bound. If there is a request in the request queue, it obtains the key-value request from the head of the request queue and then proceeds to step C2; if there is no request, it continues to poll and check the request queue. Figure 2 As shown, all request processing threads poll to check whether there are any requests in the request queue; among them, the request processing thread numbered 1 will check and obtain the request of "storage key=0" in the request queue after the four key value requests are assigned to the request queue in step B2, and the same applies to other request processing threads.

[0129] C2, after the request processing thread obtains the key value request, it sends the obtained request to the bound key value storage system instance for execution, and waits for the execution to complete before executing step C3. Figure 2 As shown, the four request processing threads can send the obtained key-value requests to the bound key-value storage system instance in parallel for execution, and wait for the execution results.

[0130] C3, after the key-value storage system instance is executed, the processing result is sent to the user, and the request is considered to be executed. Then return to step C1. Figure 2 As shown, when a key-value storage system instance completes the execution of a request, the request processing thread receives and temporarily stores the processing result returned by the key-value storage system instance, and sends the processing result to the user, and the request is considered to be executed.

[0131] Preferably, when a request processing thread polls and checks the request queue in step C1, it finds that there are multiple adjacent key-value pair storage, modification, deletion requests or multiple adjacent key-value pair read requests at the head of the request queue. At this time, the request processing thread will obtain them in batches.

[0132] Preferably, when a request processing thread obtains multiple storage, modification, and deletion requests in step C1, a request key-value pair length and L are set. Initially, L is 0, and the key-value pair length is increased for each key-value storage request L obtained. If the underlying storage device is a block device, and its minimum write unit is 4KB, then when L exceeds 4KB, no more key-value storage requests will be obtained, L will be reset to 0, and step C2 will be entered.

[0133] Preferably, when a request processing thread obtains multiple key-value pair read requests in step C1, if the number of CPU cores is T, then when the number of read requests obtained is T, it will stop obtaining more requests and enter step C2.

[0134] Preferably, the key-value storage system instance supports batch write transactions (such as WriteBatch of LevelDB and RocksDB), that is, it allows multiple storage, modification or deletion requests to be encapsulated together and executed as one request. In this case, the execution steps of the request processing thread are as follows: Figure 7 When step C1 obtains multiple key-value storage requests, they will be encapsulated into a batch storage transaction in step C2 (for example, creating a WriteBatch and adding these requests to the WriteBatch), and then sent to the key-value storage system instance for batch execution.

[0135] Preferably, the key-value storage system instance supports batch read transactions (such as RocksDB's Multiget), that is, allows multiple read requests to be packaged together and executed as one request. Figure 8 As shown, when step C1 obtains multiple key-value pair read requests, they will be encapsulated into a batch read transaction in step C2 (for example, the keys of these key-value read requests are put into an array, and then the array is used as a parameter of Multiget), and then sent to the key-value storage system instance for batch execution. After waiting for the execution to complete, step C3 is entered.

[0136] Preferably, the key-value storage system instance does not support batch read transactions (such as LevelDB), such as Fig. 9 As shown, when multiple key-value pair read requests are obtained in step C1, threads equal to the number of key-value read requests are created in step C2, and each thread sends one of the key-value pair read requests to the key-value storage system instance for execution. After waiting for all key-value read requests to be executed, step C3 is entered.

[0137] The key-value request parallel scheduling system provided by the present invention is described below. The key-value request parallel scheduling system described below and the key-value request parallel scheduling method described above can be referred to each other.

[0138] An embodiment of the present invention provides a key-value request parallel scheduling system, including:

[0139] The system initialization module is used to number n key-value storage system instances; create n request queues and request processing threads and number them in the same way so that each key-value storage system instance, request queue and request processing thread corresponds to each other; wherein n is an integer greater than 1,

[0140] A request response module, used for determining the type of the request when receiving the request;

[0141] A request processing module, for determining, if the request is a key-value pair storage, modification, deletion or read request, a number i corresponding to the key parameter of the request according to a preset mapping rule; placing the request into a request queue numbered i, waiting to be acquired by a request processing thread numbered i and sent to a key-value storage system instance numbered i for execution;

[0142] If the request is a key-value pair range query request, n copies of the request are placed in n request queues respectively, waiting to be acquired by corresponding n request processing threads respectively and sent to corresponding n key-value storage system instances for execution.

[0143] Specifically, the scheduling system is used to receive key-value requests issued by users, send them to key-value storage system instances for execution, return the execution results to users, and ensure the correctness of the execution results (i.e., consistent with the execution results of directly sending requests to a key-value storage system without going through the scheduling system), and includes: multiple request queues, multiple parallel request processing threads, and multiple key-value storage system instances, which are equal in number and bound one by one. The request queue is used to place key-value requests, the request processing thread is used to perform request processing, and the key-value storage system instance is used to actually execute key-value requests.

[0144] It will be easily understood by those skilled in the art that the above description is only 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 in the protection scope of the present invention.

Claims

1. A method for parallel scheduling of key-value requests, It is characterized in that include: S1, create n key-value storage system instances, request queues, and request processing threads, and number them in the same way; where n is an integer greater than 1; S2, receiving a user request and determining the type of the request; S3, if the request is a key-value pair storage, modification, deletion or read request, determine the number i corresponding to the key parameter of the request according to the preset mapping rule; put the request into the request queue numbered i, waiting to be acquired by the request processing thread numbered i and sent to the key-value storage system instance numbered i for execution; If the request is a key-value pair range query request, n copies of the request are made and put into n request queues respectively, waiting to be acquired by corresponding n request processing threads respectively and sent to corresponding n key-value storage system instances for execution; The step of waiting for the request processing thread numbered i to obtain and send the request to the key-value storage system instance numbered i for execution includes: Step C1, the request processing thread numbered i checks whether there is a request in the request queue numbered i, and if so, obtains the request from the request queue and proceeds to step C2; if not, continues to poll and check the request queue; Step C2, the request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, and then proceeds to step C3; Step C3, the request processing thread receives the processing result fed back by the key-value storage system instance, and sends the processing result to the user, and returns to step C1; The waiting is respectively acquired by the corresponding n request processing threads and sent to the corresponding n key-value storage system instances for execution, including: Step D1, n request processing threads respectively check whether there are requests in the corresponding request queues, if yes, they respectively obtain the requests from the request queues and enter step D2; if no, they continue to poll and check the request queues; Step D2, the n request processing threads respectively send the acquired requests to the corresponding key-value storage system instances for execution, and then proceed to step D3; Step D3, the n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instances, and respectively send the processing results to the user, and then return to step D1.

2. The key-value request parallel scheduling method according to claim 1, It is characterized in that The request processing thread numbered i checks whether there is a request in the request queue numbered i, and if so, obtains the request from the request queue, specifically: If there are multiple adjacent requests of the same type in the request queue, the request processing thread obtains the multiple adjacent requests of the same type in batches.

3. The key-value request parallel scheduling method according to claim 2, It is characterized in that The request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, specifically: In the case where the multiple adjacent requests of the same type are key-value pair storage, modification or deletion requests, if the key-value storage system instance numbered i supports batch execution of the requests of the same type, the requests of the same type are encapsulated into a batch request and sent to the key-value storage system instance for batch execution; Otherwise, the requests of the same type are sent sequentially to the key-value storage system instance for execution; In the case where the multiple adjacent requests of the same type are key-value pair read requests, if the key-value storage system instance numbered i supports batch execution of the requests of the same type, encapsulating the requests of the same type into a batch request and sending it to the key-value storage system instance for batch execution; Otherwise, the requests of the same type are sent to the key-value storage system instance in a multi-threaded parallel manner for execution.

4. The key-value request parallel scheduling method according to claim 3, It is characterized in that If the multiple adjacent requests of the same type are key-value pair storage, modification or deletion requests, when the sum of the key-value pair data sizes of the multiple adjacent requests of the same type obtained by the request processing thread is larger than the minimum write unit of the underlying storage device, stop obtaining the requests of the same type; If the multiple adjacent requests of the same type are key-value pair read requests, when the number of the multiple adjacent requests of the same type obtained by the request processing thread is greater than the number of CPU cores, the acquisition of the requests of the same type is stopped.

5. The method for parallel scheduling of key-value requests according to any one of claims 1 to 4, It is characterized in that The preset mapping rule is determined based on a hash function.

6. The key-value request parallel scheduling method according to claim 1, It is characterized in that The n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instances, and respectively send the processing results to the user, specifically: The processing results are sent to the user in ascending order of the keys.

7. The key-value request parallel scheduling method according to claim 1, It is characterized in that After numbering the n key-value storage system instances, the method further includes: The correspondence between the n key-value storage system instances and the serial numbers is stored.

8. A key-value request parallel scheduling system, It is characterized in that include: The system initialization module is used to number n key-value storage system instances; create n request queues and request processing threads and number them in the same way so that each key-value storage system instance, request queue and request processing thread corresponds to each other; wherein n is an integer greater than 1, A request response module, used for determining the type of the request when receiving the request; A request processing module, for determining, if the request is a key-value pair storage, modification, deletion or read request, a number i corresponding to the key parameter of the request according to a preset mapping rule; placing the request into a request queue numbered i, waiting to be acquired by a request processing thread numbered i and sent to a key-value storage system instance numbered i for execution; If the request is a key-value pair range query request, n copies of the request are made and put into n request queues respectively, waiting to be acquired by corresponding n request processing threads respectively and sent to corresponding n key-value storage system instances for execution; The step of waiting for the request processing thread numbered i to obtain and send the request to the key-value storage system instance numbered i for execution includes: Step C1, the request processing thread numbered i checks whether there is a request in the request queue numbered i, and if so, obtains the request from the request queue and proceeds to step C2; if not, continues to poll and check the request queue; Step C2, the request processing thread sends the obtained request to the key-value storage system instance numbered i for execution, and then proceeds to step C3; Step C3, the request processing thread receives the processing result fed back by the key-value storage system instance, and sends the processing result to the user, and returns to step C1; The waiting is respectively acquired by the corresponding n request processing threads and sent to the corresponding n key-value storage system instances for execution, including: Step D1, n request processing threads respectively check whether there are requests in the corresponding request queues, if yes, they respectively obtain the requests from the request queues and enter step D2; if no, they continue to poll and check the request queues; Step D2, the n request processing threads respectively send the acquired requests to the corresponding key-value storage system instances for execution, and then proceed to step D3; Step D3, the n request processing threads respectively receive the processing results fed back by the corresponding key-value storage system instances, and respectively send the processing results to the user, and then return to step D1.