A key-value cache system, method and device
The key-value cache system improves range query performance and cache efficiency by segregating query results into dedicated and non-dedicated areas based on access frequency, reducing I/O and computing overhead, and optimizing cache space utilization.
Patent Information
- Application Number
- CN202411260300.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2044-09-10
AI Technical Summary
Existing key-value storage systems based on block cache suffer from poor performance and low cache efficiency during range queries due to the need for traversing and merging multiple data blocks, leading to high I/O operations and computing overhead, while point queries result in inefficient use of cache space by caching entire blocks despite accessing only a small number of keys.
A key-value cache system with a dedicated area for range query results and a non-dedicated area for point query results, utilizing a heat statistics component to adjust the distribution of these areas based on access frequency, and employing a skip list structure for efficient data storage and retrieval.
This approach reduces I/O operations and computing overhead for range queries by caching sorted query results, optimizes cache space usage through dynamic area adjustments, and maintains high performance for both point and range queries.
Smart Images

Figure CN118779349B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the field of data storage, and in particular relates to a key-value cache system, method and device. Background Art
[0002] Key value storage system (KVS) is the basic storage engine for various data-intensive applications and is widely used in the field of data management. In order to meet the needs of real-time data processing and big data analysis, the KVS system must efficiently handle a large number of write operations while maintaining low disk I / O overhead.
[0003] At present, key-value storage systems usually save storage I / O by caching the target data in the block cache in memory. The blocks in the block cache are indexed by the SSTable (Sorted StringTable) file ID and the offset of the block in the SSTable. The block cache can support both point queries (referring to querying the key-value pairs of a specific key) and range queries (referring to querying all key-value pairs within a specified range).
[0004] The blocks in the block cache are direct mappings of the blocks in the files stored on the hard disk. The blocks in the files on the hard disk store data in an ordered manner within the block but out of order between blocks. However, the range query of the key-value storage system needs to return a completely sorted sequence of key-value pairs that meet the query requirements. Therefore, the key-value storage system based on block query needs to traverse and merge multiple data blocks to merge and sort the target data when processing range queries, which involves a large number of I / O operations and computing overhead, resulting in slow query speed. At the same time, when processing point queries, the block cache must cache the entire block even if only a small number of keys in the block are frequently accessed. In this case, the cache space is not fully utilized. Summary of the invention
[0005] The disclosed embodiment proposes a key-value pair caching solution to solve the problem that the existing key-value storage system based on block cache has poor performance and low cache efficiency when processing range queries.
[0006] A first aspect of an embodiment of the present disclosure provides a key-value cache system, including a cache area, a heat statistics component, and a range adjustment component, wherein:
[0007] The cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results;
[0008] The heat statistics component is used to count the number of accesses to each key in the key-value pair data stored in each storage area constituting the cache area;
[0009] The range adjustment component is used to record the start and end positions of the storage area corresponding to each query, and adjust the distribution of the dedicated area and the non-dedicated area based on the operation and access frequency of the storage area.
[0010] In some embodiments, the cache area further includes a non-dedicated cache, and the non-dedicated cache is used to store access addresses of data in the non-dedicated area.
[0011] In some embodiments, the cache area stores data based on a skip list structure.
[0012] A second aspect of an embodiment of the present disclosure provides a key-value caching method, which is applied to the key-value caching system according to the first aspect of the present disclosure, including:
[0013] Initializing a cache area, wherein the cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results;
[0014] Acquire operations on each of the storage areas constituting the cache area and count access frequencies of the storage areas, and adjust the distribution of the dedicated area and the non-dedicated area based on the operations on the storage areas and the access frequencies;
[0015] Obtain and execute an operation instruction on a key-value pair, wherein if the operation instruction is a range query instruction, the range query instruction is executed in the dedicated area, and if a hit is found, a target key-value pair is returned; if a hit is found, the range query instruction is continued to be executed in a memory table and / or a disk according to a first preset rule, and the target key-value pair is sorted based on the range query instruction and written into the dedicated area.
[0016] In some embodiments, adjusting the distribution of the dedicated area and the non-dedicated area based on the operation on the cache area and the access frequency comprises:
[0017] If the operation is a write operation of writing the target key-value pair into the cache area caused by a range query, writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area; or
[0018] If the operation is a write operation of writing the target key-value pair into the cache area caused by a point query, writing the target key-value pair into the non-dedicated area according to a second preset rule; and / or
[0019] If the data stored in the cache area after the write operation is performed will exceed a first preset threshold, an eviction operation is performed based on the access frequency before performing the write operation.
[0020] In some embodiments, performing the eviction operation based on the access frequency includes:
[0021] Based on the ratio of the access frequency to the capacity of the storage area, it is determined whether the storage area is an area to be released; if so and the area to be released is the dedicated area, the storage area of the key-value pair in the area to be released whose number of accesses to the key exceeds a second preset threshold is marked as a non-dedicated area, and the storage address is saved in the non-dedicated cache, and the dedicated area in the area to be released is released; if the area to be released is the non-dedicated area, the area to be released is directly released.
[0022] In some embodiments, the obtaining and executing the operation instruction on the key-value pair further includes:
[0023] If the operation instruction is a "Put" operation on a key-value pair, a search is performed in the cache area with the key in the key-value pair. If found, the query result is updated based on the key value in the key-value pair, and the query result is marked as dirty data; if not found, the key-value pair is written to the memory table.
[0024] In some embodiments, the obtaining and executing the operation instruction on the key-value pair further includes:
[0025] The key-value cache system includes a non-dedicated cache. If the operation instruction is a point query instruction, the non-dedicated cache is first queried. If not found, the cache area is continued to be searched. If found in the cache area, the target key-value pair is returned, and the storage area of the target key-value pair is marked as a non-dedicated area. The storage address is saved in the non-dedicated cache. If not found, the query instruction is continued to be executed in the memory table and / or disk according to the first preset rule, and the target key-value pair is written to the non-dedicated area.
[0026] In some embodiments, writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area includes:
[0027] If the write operation is caused by a "Seek" operation in a range query, writing the target key-value pair into the cache area according to a second preset rule, and marking the cache area as a dedicated area;
[0028] If the write operation is caused by a "Next" operation in a range query, a dedicated area is determined according to a second preset rule, the target key-value pair is written into the dedicated area, and the length of the dedicated area is updated.
[0029] A third aspect of an embodiment of the present disclosure provides a key-value cache device, which is applied to the key-value cache system according to the first aspect of the present disclosure, including:
[0030] An initialization module, used to initialize a cache area, wherein the cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results;
[0031] an adjustment module, configured to obtain operations on each of the storage areas constituting the cache area and calculate access frequencies of the storage areas, and adjust the distribution of the dedicated area and the non-dedicated area based on the operations on the storage areas and the access frequencies;
[0032] An execution module is used to obtain and execute an operation instruction on a key-value pair, wherein if the operation instruction is a range query instruction, the range query instruction is executed in the cache area, and if a hit is found, a target key-value pair is returned; if a hit is found, the range query instruction is continued to be executed in a memory table and / or a disk according to a first preset rule, and the target key-value pair is sorted based on the range query instruction and written into the dedicated area.
[0033] In summary, the key-value cache system, method and device provided by the embodiments of the present disclosure cache the query results of executing historical queries according to different query types, and give priority to searching in the cache area when executing query tasks, because the query results of historical range queries have been sorted according to query requirements and saved in the same dedicated area. Therefore, when the query results of the range query to be executed fall within the query results of the historical range query, the sorted target data that meets the query requirements can be directly obtained from the dedicated area, reducing the I / O operations and computing overhead required for merging and sorting the target data, and improving the range query performance; at the same time, a non-dedicated area is set specifically for caching point query records, because the distribution of dedicated areas and non-dedicated areas is dynamically adjusted according to the heat and operation of the cache area, the dedicated area can also retain the hot key values for point queries through the eviction strategy and release the area for storing other keys, thereby improving the cache efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The features and advantages of the present disclosure will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the present disclosure in any way. In the accompanying drawings:
[0035] Figure 1 It is a schematic diagram of an existing key-value cache system based on block cache;
[0036] Figure 2 is a schematic diagram of a key-value cache system (OmniCache) shown in some embodiments of the present disclosure;
[0037] Figure 3 is a flowchart of a key-value caching method according to some embodiments of the present disclosure;
[0038] Figure 4 This is the implementation process of the Put operation in some embodiments of the present disclosure;
[0039] Figure 5 This is the implementation process of the Get operation in some embodiments of the present disclosure;
[0040] Figure 6 This is the implementation process of the Seek operation in some embodiments of the present disclosure;
[0041] Figure 7 is the implementation process of the Next operation in some embodiments of the present disclosure;
[0042] Figure 8 is a schematic diagram of a key-value cache device according to some embodiments of the present disclosure. DETAILED DESCRIPTION
[0043] In the detailed description below, many specific details of the present disclosure are set forth by way of example in order to provide a thorough understanding of the relevant disclosure. However, it will be apparent to one of ordinary skill in the art that the present disclosure can be implemented without these details. It should be understood that the use of the terms "system," "device," "unit," and / or "module" in the present disclosure is a method for distinguishing different parts, elements, parts, or assemblies at different levels in a sequential arrangement. However, these terms may be replaced by other expressions if other expressions can achieve the same purpose.
[0044] It should be understood that when a device, unit or module is referred to as being "on," "connected to," or "coupled to" another device, unit or module, it may be directly on, connected to, coupled to, or communicating with other devices, units or modules, or there may be intermediate devices, units or modules, unless the context clearly indicates an exception. For example, the term "and / or" as used in this disclosure includes any and all combinations of one or more of the relevant listed items.
[0045] The terms used in this disclosure are only for describing specific embodiments and are not intended to limit the scope of this disclosure. As shown in the specification and claims of this disclosure, unless the context clearly indicates an exception, the words "one", "a kind" and / or "the" do not specifically refer to the singular, but may also include the plural. Generally speaking, the terms "include" and "comprise" only indicate the inclusion of clearly identified features, wholes, steps, operations, elements and / or components, and such expressions do not constitute an exclusive list, and other features, wholes, steps, operations, elements and / or components may also be included.
[0046] These and other features and characteristics, methods of operation, functions of related elements of the structure, combinations of parts, and economies of manufacture of the present disclosure may be better understood with reference to the following description and drawings, which form a part of the specification. However, it is to be clearly understood that the drawings are for illustration and description purposes only and are not intended to limit the scope of protection of the present disclosure. It is to be understood that the drawings are not drawn to scale.
[0047] Various structural diagrams are used in this disclosure to illustrate various variations of the embodiments of the present disclosure. It should be understood that the above or below structures are not intended to limit the present disclosure. The scope of protection of the present disclosure shall be subject to the claims.
[0048] The key-value store system (KVS) is the basic storage engine for various data-intensive applications and is widely used in various data-intensive applications, such as search engines, distributed data systems, online transaction processing (OLTP) and online analytical processing (OLAP) databases.
[0049] Key-value storage systems must support efficient read and write operations to meet the needs of data-intensive applications. Typically, these systems provide the following main API interfaces:
[0050] PUT: Used to write key-value pairs into the database. If the key already exists, its value is updated; if the key does not exist, a new key-value pair is inserted. The PUT operation requires an efficient writing mechanism to ensure good performance in a high-concurrency environment.
[0051] GET: Used for point query, read the corresponding value according to the key. GET operation needs to quickly and accurately access the data in the storage to meet the real-time query requirements of the application. This is especially important for online transaction processing systems (OLTP), because these systems usually require low-latency read operations.
[0052] SCAN: used for range query, returns all key-value pairs within the specified range. SCAN generally includes Seek and Next. Seek is used to perform equal value query or find the upper and lower limits of the interval, and next is used to obtain the next data within a range. SCAN operation is very common in big data analysis and online analytical processing systems (OLAP), which require the system to efficiently handle the reading of large-scale data and provide fast response time.
[0053] Figure 1 This is a schematic diagram of existing block cache-based key-value cache systems (such as LevelDB and RocksDB). Figure 1As shown in the figure, the existing key-value cache system based on block cache usually saves storage I / O and accelerates read operations by caching data (key-value pairs) from disk to memory (Block Cache). (Some key-value cache systems based on block cache also include key-value cache, RowCache).
[0054] The data stored in the block cache comes from the blocks of the file on the disk. The data is stored in blocks in the form of SST (SortedString Table) on the disk. The typical size of an SST is 64Mb, and the typical size of a block is 16KB. Existing key-value cache systems generally also include a memory table (MemTable) and an immutable memory table (Imutable MemTable). The memory table is an ordered data structure in memory, usually implemented as a skip list (SkipList) or a sequential array (Vector), which supports fast write and search operations. The immutable memory table is located in the memory and cannot be modified. When the memory table is full, it will be converted to an immutable memory table, and another new memory table will be generated for writing. The immutable memory table will be gradually flushed to L0 (layer 0) on the disk in the background.
[0055] The existing block cache-based key-value cache system can perform the following operations:
[0056] 1. Click Get:
[0057] First, the target key is searched in the memory table. If found, the corresponding value is returned directly. The data stored in the memory table is the latest and does not need to access the disk. If it is not found in the memory table, it continues to search in the immutable memory table. The immutable memory table stores the latest data before it is flushed from the memory table to the disk.
[0058] If the key is not found in either the memtable or the immutable memtable, the target key is searched in the block cache. The block cache stores data blocks, index blocks, and Bloom filter blocks.
[0059] Bloom filter check: First check the Bloom filter block, if the Bloom filter indicates that the key does not exist, skip the current data block.
[0060] Index block lookup: If the Bloom filter indicates that the key may exist, the index block is read to determine the location of the data block.
[0061] Data block search: Finally, the target key is found in the data block and the corresponding value is returned.
[0062] If the target key is not found in the block cache, the disk needs to be accessed. Each layer of the ordered string table is searched in order from newest to oldest. During the search, the Bloom filter is checked first, and if the key may exist, the index block and data block are read for search.
[0063] 2. Range query (Seek and Next):
[0064] Range query requires constructing a global merge iterator on each sort of the memory table, immutable memory table, and disk, and traversing all the data blocks therein. If the accessed data block is cached in the block cache, one I / O can be saved. If the block cache does not hit, the disk needs to be accessed, and the merge iterator traverses the data in memory and all sorted ordered string tables to perform range query and return the result.
[0065] 3. Write operation (Put)
[0066] To ensure data consistency and persistence, all write operations are first recorded in the Write-Ahead Log (WAL). The WAL records the order of write operations and can be used to recover data after a system crash. After writing to the log, the data is first written to the memory table. When the memory table reaches its capacity limit, it is converted into an immutable memory table and asynchronously flushed to disk to form a new ordered string table. At the same time, a new memory table is created to continue to receive new write operations.
[0067] When the immutable memory table is flushed to disk, an ordered string table of the L0 layer is formed. As time goes by, the number of ordered string tables of the L0 layer increases, and when the number reaches a certain threshold, a compression operation is triggered.
[0068] The compaction operation merges multiple small ordered string tables into a larger ordered string table and writes it to the next layer (such as L1). This process is repeated to ensure that the number and size of ordered string tables at each layer are within a reasonable range. A layer on the disk is called a sort.
[0069] The compression operation not only merges the ordered string tables, but also deletes duplicate key-value pairs, reclaims the space of deleted data, and keeps the data ordered on the disk.
[0070] In the existing key-value cache system based on block cache, the blocks in the block cache are direct mappings of the blocks of the files stored on the disk. The blocks in the files on the hard disk store data in an ordered manner within the block but unordered between blocks. However, the range query of the key-value storage system needs to return a completely sorted sequence of key-value pairs that meet the query requirements. Therefore, the key-value storage system based on block query needs to traverse and merge multiple data blocks to merge and sort the target data when processing range queries, which involves a large number of I / O operations and computing overhead, resulting in slow query speed. At the same time, when processing point queries, the block cache must cache the entire block even if only a small number of keys in the block are frequently accessed. In this case, the cache space is not fully utilized.
[0071] In view of the shortcomings of the existing technology, this paper proposes a new cache structure - OmniCache. OmniCache optimizes the efficiency of future queries by storing the results of each range query (Seek() and Next()). OmniCache greatly improves the performance of range queries and introduces a dynamically adjusted cache strategy to reduce memory waste and ensure that the cache space is maximized.
[0072] Figure 2 Schematic diagram of OmniCache shown in some embodiments of the present disclosure. Figure 2 As shown:
[0073] The cache area of OmniCache is divided into two parts: Exclusive Area (EA) and Non-Exclusive Area (NA). EA is used to store the results of range queries, and NA is used to store the results of point queries (Get()).
[0074] In addition to the memory table and immutable memory table, OmniCache also includes the following functional components:
[0075] RangeAdjuster: Dynamically manages the distribution and conversion of EA and NA in OmniCache. It records the boundaries of each access, handles the expansion and contraction of EA, and maintains the balance and efficiency of the cache.
[0076] HotnessCalculator: records the number of accesses to each key in OmniCache, which is used to provide a basis for eviction policy. Through heat statistics, it ensures that the most frequently accessed data can be saved in the cache first.
[0077] In some embodiments of the present disclosure, the cache area of OmniCache also includes:
[0078] Non-dedicated cache (NA Cache): stores references to OmniCache in order to improve the performance of Get operations without searching in OmniCache.
[0079] Preferably, OmniCache stores data based on a skip list structure (SkipList). SkipList is a probabilistic data structure that supports efficient search, insertion, and deletion operations. Compared with traditional linked lists, SkipList improves operational efficiency through multi-level indexing, making the search time complexity reach O(logn). This structure is not only simple and easy to implement, but also very efficient when dynamically adjusting cache content. The skip list structure used by OmniCache is referred to as CacheSkipList.
[0080] Figure 3 is a flowchart of a key-value caching method according to some embodiments of the present disclosure. In some embodiments, the key-value caching method is composed of Figure 3 The OmniCache implementation shown, the key-value caching method comprises the following steps:
[0081] S310, initializing a cache area, wherein the cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results.
[0082] Specifically, configure the initial parameters of OmniCache during initialization: set the maximum memory size occupied by OmniCache, set the memory threshold size when the eviction policy takes effect, set the maximum length of EA, and set the size of NA Cache.
[0083] When the system starts up, initialize CacheSkipList and NA Cache in OmniCache to empty, range management information in RangeAdjuster to empty, and record in HotnessCalculator to empty.
[0084] S320, obtaining operations on each of the storage areas constituting the cache area and counting access frequencies of the storage areas, and adjusting distribution of the dedicated area and the non-dedicated area based on the operations on the storage areas and the access frequencies.
[0085] S330, obtaining and executing an operation instruction on the key-value pair, wherein if the operation instruction is a range query instruction, executing the range query instruction in the dedicated area, and if a hit is found, returning a target key-value pair; if a hit is found, continuing to execute the range query instruction in the memory table and / or disk according to a first preset rule, and writing the target key-value pair into the dedicated area after sorting based on the range query instruction.
[0086] Specifically, OmniCache records the number of times each key is accessed, thereby counting the access frequency (heat) of each storage area. If the data stored in OmniCache will exceed a preset threshold after writing data to the cache area, an eviction operation is performed based on the access frequency before a write operation is performed.
[0087] The eviction strategy is based on the LRU (least recently used) algorithm based on heat statistics and is managed by RangeAdjuster. During the eviction process, the score of each storage area is first calculated. The score calculation formula is as follows:
[0088] Score = access frequency / storage capacity
[0089] The region with the lowest score will be evicted first. If the evicted region is EA, some of the hottest key-value pairs in EA are converted to NA and inserted into NA Cache; if the evicted region is NA, it is directly evicted.
[0090] In some embodiments of the present disclosure, the LRU algorithm is also used in the NA Cache for eviction to ensure efficient use of the cache space.
[0091] OmniCache optimizes the implementation of common operations in key-value cache systems.
[0092] 1. Write operation (Put)
[0093] Figure 4 This is the implementation process of the Put operation in some embodiments of the present disclosure.
[0094] like Figure 4 As shown, the process includes:
[0095] (1) When a new key-value pair is written, the data is first written to the write-ahead log (WAL) to ensure data consistency.
[0096] (2) Check whether OmniCache hits the key-value pair. If so, update the data in OmniCache and mark the key-value pair as dirty data.
[0097] (3) If OmniCache misses, the data is written to MemTable. If OmniCache is full, an eviction operation is triggered. During the eviction process, the least accessed and largest area in EA is converted to NA and inserted into NA Cache to ensure efficient use of cache space.
[0098] (4) After the eviction operation is completed, the location of the dirty data is flushed into MemTable and persisted to disk in a subsequent flush operation.
[0099] 2. Click Get
[0100] Figure 5 This is the implementation process of the Get operation in some embodiments of the present disclosure. Figure 5 As shown, the process includes:
[0101] (1) First, search for the target key-value pair in the NA Cache. If a match is found, the data is returned directly.
[0102] (2) If the NA Cache does not hit, continue searching in the OmniCache. If the target key-value pair is found, the data is returned and the reference of the key-value pair is filled in the NA Cache.
[0103] (3) If OmniCache also misses the match, it continues searching in the memory table and / or disk. If a match is found, the target key-value pair is written to OmniCache.
[0104] 3. Range Query (Seek and Next)
[0105] Figure 6 is the implementation process of the Seek operation in some embodiments of the present disclosure, Figure 7 This is the implementation process of the Next operation in some embodiments of the present disclosure. Figure 6 and Figure 7 As shown in the figure, the range query process includes:
[0106] (1) For a Seek operation, a query operation is first performed in OmniCache. If the target key is found, the result is returned and the current position is recorded.
[0107] (2) If there is a miss, the data is read according to the traditional process and the result is written back to OmniCache.
[0108] (3) For the Next operation, first search in OmniCache. If all operations hit in OmniCache, the results are returned directly; if some or all Next operations do not hit, continue reading according to the traditional process and write the results back to OmniCache.
[0109] When point queries and range queries miss in OmniCache but hit in memory and / or disk according to traditional processes, the query results need to be written to the cache area.
[0110] Based on the differences in write operations to OmniCache, RangeAdjuster adjusts the distribution of dedicated and non-dedicated areas. Specifically:
[0111] If the write operation to the cache area is caused by a point query, insert the target key value into CacheSkipList and mark the new NA in RangeAdjuster;
[0112] If the write operation to the cache area is caused by Seek, the target key is inserted into CacheSkipList and the new EA is marked in RangeAdjuster;
[0113] If the write operation to the cache area is caused by Next, the target EA is determined in OmniCache, the target key value is inserted into the target EA, and the length of the target EA is adjusted in RangeAdjuster.
[0114] It can be seen that OmniCache caches the query results of historical queries according to different query types, and gives priority to searching in the cache area when executing query tasks. Because the query results of historical range queries have been sorted according to the query requirements and saved in the same dedicated area, when the query results of the range query to be executed fall within the query results of the historical range query, the sorted target data that meets the query requirements can be directly obtained from the dedicated area, reducing the I / O operations and computing overhead required for merging and sorting the target data, and improving the range query performance.
[0115] OmniCache optimizes the use of cache space by introducing a dynamically adjusted cache strategy. The RangeAdjuster component can dynamically adjust the range of the dedicated area (EA) and non-dedicated area (NA) according to changes in workload, ensuring that the cache space is used to the maximum extent and reducing duplicate storage and memory waste.
[0116] OmniCache uses the SkipList data structure to achieve efficient search, insert, and delete operations. Unlike traditional read-only caches, OmniCache supports dirty write operations, which allows it to maintain efficient performance when processing both point queries (Get) and range queries (Seek and Next). In addition, by storing references to OmniCache in NA Cache, the performance of Get operations is improved and query latency is reduced.
[0117] Through reasonable eviction strategies and heat statistics, OmniCache can effectively reduce the number of I / O operations. During the eviction process, the LRU algorithm based on heat statistics ensures that the most frequently accessed data is stored in the cache first, avoiding unnecessary I / O operations. At the same time, during the compression and compaction process, OmniCache can maintain data consistency and validity, reduce cache invalidation problems, and improve system performance.
[0118] In addition, OmniCache is compatible with existing block cache-based key-value storage systems, such as LevelDB and RocksDB, and is easy to integrate and deploy in existing systems. By minimizing modifications to existing systems, OmniCache can be quickly applied to actual environments, bringing immediate performance improvements. At the same time, the versatility of OmniCache's design enables it to be widely used in key-value storage systems in various big data environments. Whether it is a search engine, a distributed data system, or an online transaction processing (OLTP) and online analytical processing (OLAP) database, OmniCache can provide performance improvements for range queries to meet the needs of different application scenarios.
[0119] One embodiment of the present disclosure tests OmniCache using the YCSB (Yahoo! Cloud Serving Benchmark) data set. The experimental environment is: Intel(R) Xeon(R) Silver4314CPU@2.40GHz processor, 256GB memory, and the operating system used is Debian Linux, kernel version 6.1.0. OmniCache is implemented by modifying the open source key-value storage system RocksDB, and the test database is deployed on a Kingston model A400960GB SATA SSD.
[0120] The test results show:
[0121] The performance of range query has been improved from 4800 queries / second to 12000 queries / second, which significantly improves the efficiency of the system in processing large-scale data queries.
[0122] The point query performance dropped slightly from 14,000 times / second to 13,700 times / second, but still remained at a high level. This slight performance loss is acceptable;
[0123] The write performance dropped from 22,000 times / second to 21,000 times / second, a slight decrease but still maintaining a high performance level.
[0124] It can be seen that OmniCache significantly improves range query performance without significantly reducing point query and write performance.
[0125] Figure 8 is a schematic diagram of a key-value cache device according to some embodiments of the present disclosure. Figure 8 As shown, the key-value cache device 800 includes an initialization module 810, an adjustment module 820 and an execution module 830. Among them:
[0126] An initialization module 810, configured to initialize a cache area, wherein the cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results;
[0127] An adjustment module 820, configured to obtain operations on each of the storage areas constituting the cache area and calculate access frequencies of the storage areas, and adjust distribution of the dedicated area and the non-dedicated area based on the operations on the storage areas and the access frequencies;
[0128] The execution module 830 is used to obtain and execute an operation instruction on a key-value pair, wherein if the operation instruction is a range query instruction, the range query instruction is executed in the cache area, and if a hit is found, a target key-value pair is returned; if a hit is found, the range query instruction is continued to be executed in the memory table and / or disk according to a first preset rule, and the target key-value pair is sorted based on the range query instruction and written into the dedicated area.
[0129] In summary, the key-value cache system, method and device provided by the embodiments of the present disclosure cache the query results of executing historical queries according to different query types, and give priority to searching in the cache area when executing query tasks, because the query results of historical range queries have been sorted according to query requirements and saved in the same dedicated area. Therefore, when the query results of the range query to be executed fall within the query results of the historical range query, the sorted target data that meets the query requirements can be directly obtained from the dedicated area, reducing the I / O operations and computing overhead required for merging and sorting the target data, and improving the range query performance; at the same time, a non-dedicated area is set specifically for caching point query records, because the distribution of dedicated areas and non-dedicated areas is dynamically adjusted according to the heat and operation of the cache area, the dedicated area can also retain the hot key values for point queries through the eviction strategy and release the area for storing other keys, thereby improving the cache efficiency.
[0130] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding descriptions in the aforementioned device embodiments and will not be repeated here.
[0131] Although the subject matter described herein is provided in the general context of being executed in conjunction with the execution of operating systems and application programs on computer systems, it will be appreciated by those skilled in the art that other implementations may also be performed in conjunction with other types of program modules. In general, program modules include routines, programs, components, data structures, and other types of structures that perform specific tasks or implement specific abstract data types. It will be appreciated by those skilled in the art that the subject matter described herein may be practiced using other computer system configurations, including handheld devices, multiprocessor systems, microprocessor-based or programmable consumer electronics, minicomputers, mainframe computers, etc., and may also be used in a distributed computing environment in which tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules may be located in both local and remote memory storage devices.
[0132] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this disclosure.
[0133] It should be understood that the above specific embodiments of the present disclosure are only used to illustrate or explain the principles of the present disclosure, and do not constitute a limitation of the present disclosure. Therefore, any modifications, equivalent substitutions, improvements, etc. made without departing from the spirit and scope of the present disclosure should be included in the protection scope of the present disclosure. In addition, the claims attached to the present disclosure are intended to cover all changes and modifications that fall within the scope and boundaries of the attached claims, or the equivalent forms of such scope and boundaries.
Claims
1. A key-value caching method, applied to a key-value caching system, wherein the key-value caching system includes a cache area, characterized in that: include: Initializing the cache area, wherein the cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results; Acquire operations on each storage area constituting the cache area and count access frequencies of the storage areas, and adjust the distribution of the dedicated area and the non-dedicated area based on the operations on the storage areas and the access frequencies; Obtain and execute an operation instruction for a key-value pair, wherein, if the operation instruction is a range query instruction, the range query instruction is executed in the dedicated area, and if a hit is found, a target key-value pair is returned; if a hit is found, the range query instruction is continued to be executed in a memory table and / or a disk according to a first preset rule, and the target key-value pair is sorted based on the range query instruction and written into the dedicated area; wherein, The key-value cache system includes a cache area, a heat statistics component and a range adjustment component, wherein: The cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results; The heat statistics component is used to count the number of accesses to each key in the key-value pair data stored in each storage area constituting the cache area; The range adjustment component is used to record the start and end positions of the storage area corresponding to each query, and adjust the distribution of the dedicated area and the non-dedicated area based on the operation and access frequency of the storage area; The adjusting the distribution of the dedicated area and the non-dedicated area based on the operation on the cache area and the access frequency comprises: If the operation is a write operation of writing the target key-value pair into the cache area caused by a range query, writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area; Writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area comprises: If the write operation is caused by a "Seek" operation in a range query, the target key-value pair is written into the cache area according to a second preset rule, and the cache area is marked as a dedicated area; If the write operation is caused by a "Next" operation in a range query, a dedicated area is determined according to a second preset rule, the target key-value pair is written into the dedicated area, and the length of the dedicated area is updated.
2. The method according to claim 1, characterized in that The adjusting the distribution of the dedicated area and the non-dedicated area based on the operation on the cache area and the access frequency comprises: If the operation is a write operation of writing the target key-value pair into the cache area caused by a point query, writing the target key-value pair into the non-dedicated area according to a second preset rule; and / or If the data stored in the cache area after the write operation is performed will exceed a first preset threshold, an eviction operation is performed based on the access frequency before performing the write operation.
3. The method according to claim 2, characterized in that The performing the eviction operation based on the access frequency comprises: Based on the ratio of the access frequency to the capacity of the storage area, it is determined whether the storage area is an area to be released; if so and the area to be released is the dedicated area, the storage area of the key-value pair in the area to be released whose number of accesses to the key exceeds a second preset threshold is marked as a non-dedicated area, and the storage address is saved in the non-dedicated cache, and the dedicated area in the area to be released is released; if the area to be released is the non-dedicated area, the area to be released is directly released.
4. The method according to claim 1, characterized in that The obtaining and executing the operation instruction on the key-value pair also includes: If the operation instruction is a "Put" operation on a key-value pair, a search is performed in the cache area using the key in the key-value pair. If found, the query result is updated based on the key value in the key-value pair, and the query result is marked as dirty data; if not found, the key-value pair is written to the memory table.
5. The method according to claim 1, characterized in that The obtaining and executing the operation instruction on the key-value pair also includes: The key-value cache system includes a non-dedicated cache. If the operation instruction is a point query instruction, the non-dedicated cache is first queried. If not found, the cache area is continued to be searched. If found in the cache area, the target key-value pair is returned, and the storage area of the target key-value pair is marked as a non-dedicated area. The storage address is saved in the non-dedicated cache. If not found, the query instruction is continued to be executed in the memory table and / or disk according to the first preset rule, and the target key-value pair is written to the non-dedicated area.
6. The method according to claim 2, characterized in that Writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area comprises: If the write operation is caused by a "Seek" operation in a range query, the target key-value pair is written into the cache area according to a second preset rule, and the cache area is marked as a dedicated area; If the write operation is caused by a "Next" operation in a range query, a dedicated area is determined according to a second preset rule, the target key-value pair is written into the dedicated area, and the length of the dedicated area is updated.
7. A key-value cache device, applied to a key-value cache system, wherein the key-value cache system comprises a cache area, characterized in that: include: An initialization module, used to initialize the cache area, wherein the cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results; an adjustment module, configured to obtain operations on each storage area constituting the cache area and count access frequencies of the storage areas, and adjust the distribution of the dedicated area and the non-dedicated area based on the operations on the storage areas and the access frequencies; An execution module is used to obtain and execute an operation instruction for a key-value pair, wherein if the operation instruction is a range query instruction, the range query instruction is executed in the cache area, and if a hit is found, a target key-value pair is returned; if a hit is found, the range query instruction is continued to be executed in a memory table and / or a disk according to a first preset rule, and the target key-value pair is sorted based on the range query instruction and written into the dedicated area; wherein, The key-value cache system includes a cache area, a heat statistics component and a range adjustment component, wherein: The cache area includes a dedicated area for storing range query results and a non-dedicated area for storing point query results; The heat statistics component is used to count the number of accesses to each key in the key-value pair data stored in each storage area constituting the cache area; The range adjustment component is used to record the start and end positions of the storage area corresponding to each query, and adjust the distribution of the dedicated area and the non-dedicated area based on the operation and access frequency of the storage area; The adjusting the distribution of the dedicated area and the non-dedicated area based on the operation on the cache area and the access frequency comprises: If the operation is a write operation of writing the target key-value pair into the cache area caused by a range query, writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area; Writing the target key-value pair into the dedicated area according to a second preset rule and updating the length of the dedicated area comprises: If the write operation is caused by a "Seek" operation in a range query, the target key-value pair is written into the cache area according to a second preset rule, and the cache area is marked as a dedicated area; If the write operation is caused by a "Next" operation in a range query, a dedicated area is determined according to a second preset rule, the target key-value pair is written into the dedicated area, and the length of the dedicated area is updated.