Data caching method and device, cluster, storage medium and program product
By cached the key-value pair data of metadata type and other types of key-value pair data in different memory spaces, and setting an independent eviction strategy, the problem of high-frequency data being evicted in Redis data persistence is solved, and the cache hit rate and system computing efficiency are improved.
Patent Information
- Application Number
- CN202410118003.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-26
- Publication Date
- 2025-07-29
AI Technical Summary
In the prior art, during the Redis data persistence process, high-frequency data is frequently expelled from memory, resulting in a low cache hit rate, affecting the system's computing efficiency.
The key-value pair data of metadata type is cached in the first memory space, and other types of key-value pair data are cached in the second memory space. The cache location is distinguished according to the data structure, and an independent eviction strategy is set to ensure that high-frequency data resides in memory.
Improves cache hit rate and memory space utilization rate, and improves the computing efficiency of the system.
Smart Images

Figure CN120386796A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a data caching method, apparatus, cluster, storage medium, and program product. Background Art
[0002] As a memory-based key-value database, the remote dictionary server (Redis) has advantages such as supporting multiple data structures, excellent performance, simple structure, and complete related tools. This has made Redis, which is widely used, become a de facto standard for caching. And the requirements for Redis have gradually extended from the original pure memory to a key-value database that supports data persistence.
[0003] Currently, generally, by grafting an embeddable key-value storage system that supports persistence at the bottom layer, such as the RocksDB storage engine, to implement Redis data persistence. The way RocksDB implements data persistent storage can be to use a storage service that is compatible with the Redis protocol based on RocksDB, such as storage services like Kvrocks and Pika. This method has a single caching strategy. When reading larger data from the storage system into memory, a large number of high-frequency data in memory will be evicted, resulting in a low cache hit rate and thus affecting the computing efficiency of the system. Summary of the Invention
[0004] Embodiments of this application provide a data caching method, apparatus, cluster, storage medium, and program product, which can implement different caching strategies for data of different data structures, improve the cache hit rate, and thus improve the computing efficiency of the system.
[0005] In a first aspect, embodiments of this application provide a data caching method, which includes: obtaining target data; the target data includes key-value pair data; if the key-value pair data includes key-value pair data of the metadata type, caching the key-value pair data of the metadata type in a first memory space; caching the other types of key-value pair data in the key-value pair data except for the metadata type in a second memory space.
[0006] It can be understood that, according to the different data types in the target data, caching the key-value pair data of the metadata type and other types of key-value pair data in different memory spaces respectively can achieve that different types of data do not affect each other during reading and writing, solve the problem that the key-value pair data of the metadata type is frequently evicted, improve the rationality of memory space allocation, improve the cache hit rate, and thus improve the computing efficiency of the system.
[0007] In a possible implementation, if the key-value pair data includes key-value pair data of the metadata type, caching the key-value pair data of the metadata type in the first memory space includes: determining the data structure of the target data; if the key-value pair data includes key-value pair data of the metadata type, caching the key-value pair data of the metadata type in the first memory space corresponding to the data structure of the target data.
[0008] It can be understood that caching the key-value pair data of the metadata type in the first memory space corresponding to its data structure according to the data structure of the target data can further distinguish the caching locations of the key-value pair data of the metadata type with different data structures, ensure that the key-value pair data of the metadata type with different data structures will not be evicted from each other during reading and writing, improve the stability and normativity of the data in the memory space, and improve the cache hit rate.
[0009] In a possible implementation, caching the key-value pair data of other types except the metadata type in the key-value pair data in the second memory space includes: caching the key-value pair data of other types in the second memory space corresponding to the data structure of the target data.
[0010] It can be understood that caching the key-value pair data of other types in the second memory space corresponding to its data structure according to the data structure of the target data can further distinguish the caching locations of the key-value pair data of other types with different data structures, ensure that the key-value pair data of other types with different data structures will not be evicted from each other during reading and writing, improve the stability and normativity of the data in the memory space, and improve the cache hit rate.
[0011] In a possible implementation, caching the key-value pair data of other types except the metadata type in the key-value pair data in the second memory space includes: if the data structure of the target data is a hash type, caching the field value in the key-value pair data in the second memory space corresponding to the hash type; if the data structure of the target data is a list type, caching the element value in the key-value pair data in the second memory space corresponding to the list type; if the data structure of the target data is a string type, caching the character data in the key-value pair data in the second memory space corresponding to the string type; if the data structure of the target data is a set type, caching the set element value in the key-value pair data in the second memory space corresponding to the set type; if the data structure of the target data is an ordered set type, caching the ordered set element value in the key-value pair data in the second memory space corresponding to the ordered set type.
[0012] It can be understood that caching different data in their corresponding second memory spaces according to the different data structures of the target data can implement caching specific data according to the characteristics of different data structures, ensure the consistency of the data granularity in the memory space and the storage system, and reduce the retrieval cost.
[0013] In a possible implementation, the first memory space and the second memory space corresponding to the key-value pair data of each data structure respectively perform data eviction according to their respective eviction policies; the eviction policy is used to indicate the target eviction data and the triggering condition for evicting the target eviction data.
[0014] It can be understood that setting independent eviction policies for different first memory spaces and second memory spaces can achieve eviction according to data characteristics, improve the independence of data in different memory spaces, ensure the residence of high-frequency data in the memory space, improve the utilization rate and hit rate of the memory space, and improve the computing efficiency of the system.
[0015] In a possible implementation, if the eviction policy is used to indicate the triggering condition for data eviction, the triggering condition includes triggering the eviction of the target eviction data in the memory space when the size of the available memory space is less than or equal to the specified threshold.
[0016] It can be understood that by setting the triggering threshold of the eviction policy, the triggering timing of the eviction policy can be flexibly controlled, the problem of memory overflow can be effectively solved, and the accuracy of controlling the utilization rate of the memory space can be improved.
[0017] In a possible implementation, if the eviction policy is used to indicate the target eviction data, the eviction policy at least includes: if there is an importance level parameter for the cached data in the memory space, determining the target eviction data in ascending order of the importance level indicated by the importance level parameter; and / or, obtaining the access frequency of each cached data in the memory space in a preset time period, and determining the target eviction data among the other cached data except the cached data with the highest access frequency; and / or, obtaining the access records of each cached data in the memory space in a preset time period, and determining the cached data with the earliest time corresponding to the most recent access record in the preset time period as the target eviction data.
[0018] It can be understood that setting multiple different eviction rules in the eviction policy can improve the rationality of the eviction policy, optimize the eviction effect, reduce the eviction frequency of high-frequency data while increasing the eviction frequency of low-frequency data, and improve the cache hit rate.
[0019] In a possible implementation, obtain the access frequencies of the first memory space and the second memory space in a preset time period; determine the ratio of the access frequency to the capacity of the corresponding memory space; the larger the value of the ratio, the greater the required capacity of the corresponding memory space; adjust the capacities of the first memory space and the second memory space according to the respective ratios.
[0020] It can be understood that by dynamically adjusting the capacities of the respective memory spaces according to the ratio of the access frequencies and their capacities of the first memory space and the second memory space within a preset time period, it is possible to reduce the capacity of the memory space occupied by low-frequency data while allocating a larger memory space for high-frequency data, improving the rationality and flexibility of the memory space capacity allocation and the cache hit rate.
[0021] In a possible implementation manner, the method further includes: the minimum cache unit of the target data in the memory space and its minimum storage unit in the storage system are both key-value pair data.
[0022] It can be understood that maintaining the consistency of the data granularity of the target data in the memory space and the storage system can reduce the fetch cost of caching the target data from the storage system to the memory space and the write cost of writing the target data from the memory space to the storage system, improving the computing efficiency of the system.
[0023] In a possible implementation manner, the method further includes: in response to a data reading instruction, reading key-value pair data of the metadata type from the first memory space; determining whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type; if the key-value pair data of other types has not expired, reading the key-value pair data of other types from the second memory space.
[0024] It can be understood that when processing a data reading instruction, determining whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type and reading the unexpired key-value pair data of other types can improve the speed and accuracy of the system response.
[0025] In a possible implementation manner, after determining whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type, the method further includes: if the key-value pair data of other types has expired, deleting the key-value pair data of other types.
[0026] It can be understood that deleting the expired key-value pair data of other types can save memory space and improve the effective utilization rate of the memory.
[0027] In a second aspect, an embodiment of the present application provides a data caching device, and the data caching device is used to execute any one of the data caching methods provided in the first aspect above.
[0028] In a possible implementation manner, the embodiments of the present application may divide the function modules of the data caching device according to the method provided in the first aspect above. For example, each function module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. Exemplarily, the embodiments of the present application may divide the data caching device into an acquisition module, a first caching module, a second caching module, etc. according to functions. The descriptions of the possible technical solutions and beneficial effects executed by each of the above-divided function modules may refer to the technical solutions provided in the first aspect above or its corresponding possible implementation manners, and will not be elaborated herein.
[0029] In a third aspect, the embodiments of the present application provide a computing device, which includes a processor and a memory, and the processor is coupled to the memory; the memory is used to store computer instructions, and the computer instructions are loaded and executed by the processor so that the computing device implements the data caching method as described in the above aspect.
[0030] In a fourth aspect, the embodiments of the present application provide a computing device cluster, which includes at least one computing device, and each computing device includes a processor and a memory, and the processor is coupled to the memory; the processors of at least one computing device are used to execute the computer instructions stored in the memories of at least one computing device, so that the computing device cluster executes the data caching methods provided in various alternative implementation manners of the first aspect above.
[0031] In a fifth aspect, the embodiments of the present application provide a computer program product, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computing device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computing device executes the data caching methods provided in various alternative implementation manners of the first aspect above.
[0032] In a sixth aspect, the embodiments of the present application provide a computer-readable storage medium, in which at least one computer program instruction is stored, and the computer program instruction is loaded and executed by the processor to implement the data caching method as described in the above aspect.
[0033] For the specific descriptions of the second to sixth aspects and their various implementation manners in the present application, reference may be made to the detailed descriptions in the first aspect and its various implementation manners; and, for the beneficial effects of the second to sixth aspects and their various implementation manners, reference may be made to the analysis of the beneficial effects in the first aspect and its various implementation manners, and will not be elaborated herein.
[0034] These aspects or other aspects of the present application will be more clearly understood in the following description. Description of the Drawings
[0035] Figure 1 It is a schematic diagram of an application scenario provided by an exemplary embodiment of the present application;
[0036] Figure 2 It is a schematic diagram of the hash type data structure supported by Redis provided by an exemplary embodiment of the present application;
[0037] Figure 3 It is a schematic diagram of the data structure after the Redis-hash data is split provided by an exemplary embodiment of the present application;
[0038] Figure 4 It is a schematic diagram of a method for implementing a storage-type Redis based on grafting RocksDB at the KeyDB bottom layer provided by an exemplary embodiment of the present application;
[0039] Figure 5 It is a schematic diagram of a method for implementing a storage-type Redis based on multi-key-value pair encoding methods such as Kvrocks and pika provided by an exemplary embodiment of the present application;
[0040] Figure 6 It is a schematic diagram of a computing device provided by an exemplary embodiment of the present application;
[0041] Figure 7 It is a schematic diagram of the process of a data caching method provided by an embodiment of the present application;
[0042] Figure 8 It is a schematic diagram of a partitioned pool cache provided by an exemplary embodiment of the present application;
[0043] Figure 9 It is a schematic diagram of an eviction policy setting involved in an embodiment of the present application;
[0044] Figure 10 It is a schematic diagram of an eviction policy setting involved in an embodiment of the present application;
[0045] Figure 11 It is a schematic diagram of an eviction policy application setting involved in an embodiment of the present application;
[0046] Figure 12 It is a schematic diagram of a dynamic adjustment of the memory space capacity involved in an embodiment of the present application;
[0047] Figure 13 It is a schematic diagram of a dynamic adjustment switch setting involved in an embodiment of the present application;
[0048] Figure 14 It is a schematic diagram of a dynamic adjustment parameter setting involved in an embodiment of the present application;
[0049] Figure 15It is a schematic diagram of a data reading process provided by an embodiment of the present application;
[0050] Figure 16 It is a schematic diagram of a data writing process provided by an embodiment of the present application;
[0051] Figure 17 It is a schematic diagram of a data cache device provided by an exemplary embodiment of the present application;
[0052] Figure 18 It is a schematic diagram of a computing device provided by an exemplary embodiment of the present application;
[0053] Figure 19 It is a schematic diagram of a computing device cluster provided by an exemplary embodiment of the present application;
[0054] Figure 20 It is a schematic diagram of the connection method between computing device clusters provided by an exemplary embodiment of the present application. Detailed implementation manners
[0055] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the accompanying drawings.
[0056] As used herein, "a plurality of" means two or more. "And / or" describes the association relationship of associated objects and indicates that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0057] Moreover, in the description of the embodiments of the present application, unless otherwise specified, "a plurality of" means two or more than two. "At least one (item)" or its similar expression refers to any combination of these items, including any combination of single item (item) or plural items (items). For example, at least one (item) of a, b, or c may represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, c may be single or multiple.
[0058] In addition, for the convenience of clearly describing the technical solutions of the embodiments of the present application, in the embodiments of the present application, terms such as "first" and "second" are used to distinguish identical or similar items with basically the same functions and effects. Those skilled in the art can understand that terms such as "first" and "second" do not limit the quantity and execution order, and "first", "second", etc. do not necessarily mean different. At the same time, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design solution described as "exemplary" or "for example" in the embodiments of the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of words such as "exemplary" or "for example" is intended to present relevant concepts in a specific manner for easy understanding.
[0059] First, an exemplary introduction to the application scenarios of the embodiments of the present application is provided.
[0060] Figure 1 FIG. shows a schematic diagram of an application scenario provided by an embodiment of the present application. The relationships and attributes of each storage component in a computer system are as Figure 1 shown. Specifically, when a central processing unit (CPU) processes data and executes instructions, it usually first looks for relevant data in the memory. When the relevant data does not exist in the memory, it then looks for it in the hard disk. Among them, as a component that communicates directly with the CPU, the memory has a much faster read / write speed than the hard disk. Therefore, the memory is usually used to store data with a relatively high access frequency.
[0061] In contrast, although the read / write speed of the hard disk is not as fast as that of the memory, its storage capacity is usually much larger than that of the memory. And the CPU cannot directly use the data in the hard disk and needs to cache the data in the hard disk into the memory first. Therefore, the hard disk is usually suitable for storing data with a large volume and a relatively low access frequency.
[0062] Among them, Redis can be used to cache hot data with a relatively high access frequency into the memory and perform a series of operations such as management, reading, and writing. Specifically, Redis is a memory-based storage system that is mainly used as a high-performance cache server. It can also be used as a message middleware, etc. The key-value pairs in Redis can support rich data structure types, such as strings, hashes, lists, sets, etc., unlike other storage systems that require both keys and values to be strings. And since Redis is memory-based, it is not affected by the disk read / write speed, so its read / write performance is extremely high.
[0063] Redis is widely used due to its excellent performance and has now become the de facto standard for in-memory databases. However, since all the data in Redis is stored in memory, when unexpected situations such as system failures and crashes occur, all the data in memory will be lost, which seriously affects the normal operation of the business. Therefore, the requirements for Redis have gradually extended from being completely memory-based to being able to support data persistence. The current relatively common solution is to graft the RocksDB storage engine at the bottom layer to achieve data persistence.
[0064] Specifically, RocksDB is a persistent storage engine that only supports pure key-value pairs. It can persistently store a large number of key-value pairs and can further build complex systems such as inverted indexes, document databases, SQL databases, cache systems, and message brokers based on this simple key-value pair data model. Therefore, RocksDB is commonly used as the underlying storage engine for other database systems. Among them, since the in-memory database Redis can support a variety of different data structures, but RocksDB does not fully support the data structures supported by Redis, the data in Redis cannot be directly stored on the hard disk through the RocksDB storage engine, and the data structure needs to be adjusted first.
[0065] Currently, generally according to the characteristics of various data structures supported by Redis, the original data is split into multiple key-value pairs and then data persistence is achieved through RocksDB. Here, the data of the hash type is used as an example for introduction:
[0066] As Figure 2 shown, Figure 2 is a schematic diagram of the hash type data structure supported by Redis. One hash key can correspond to multiple fields, and each field corresponds to its own field value.
[0067] Exemplarily, such as Figure 2 the hash key A in corresponds to multiple fields such as field 1, field 2, and field 3. Among them, field 1 corresponds to field value 1, field 2 corresponds to field value 2, field 3 corresponds to field value 3, and so on.
[0068] When performing data mapping from Redis to RocksDB, as Figure 3 shown, Figure 3 is a schematic diagram of the data structure after splitting Redis-hash data. The above-mentioned hash type keys, fields, and field values can be split into two types of pure key-value pairs, specifically including:
[0069] 1) Metadata key-value pairs: The meta key can be a hash key inherited from the original hash, and the value corresponding to the meta key can include some metadata such as flag bits, expiration times, versions, sizes, etc.
[0070] 2) Sub-key value pairs: The sub key can be composed of the field key in the original hash, the version in the metadata, and the hash key, and the value corresponding to the sub key is the field value originally corresponding to the field.
[0071] Similarly, based on the above data mapping method, the data corresponding to other data structures supported by Redis, such as strings, lists, sets, etc., can be converted into pure key-value pairs supported by RocksDB. Among them, the pure key-value pair refers to a simple corresponding relationship composed only of a key and a value. For example, the metadata key-value pairs and sub-key value pairs formed after the above splitting can solve the data flow problem between Redis and RocksDB, and thus initially realize the transformation from in-memory Redis to storage-type Redis.
[0072] Among them, within the same time, the access frequency of metadata key-value pairs is generally much higher than that of sub-key value pairs. That is to say, compared with sub-key value pairs, metadata key-value pairs are the hot data in the system and should stay in memory for a long time to ensure a high cache hit rate and system computing efficiency.
[0073] The cache scheme of the storage-type Redis based on the above encoding scheme can be currently divided into two types:
[0074] 1) As Figure 4 shown, Figure 4 is a schematic diagram of a method for implementing storage-type Redis by grafting RocksDB on the bottom layer of KeyDB. Among them, KeyDB is a high-performance branch of Redis. In this scheme, the complete Redis data structure is still in memory. For example, hash structure data such as hash key01-f1-v1 and hash key01-f2-v2 can be stored in memory, while the data structure stored in the hard disk by RocksDB is a pure key-value pair. For example, key-value pair data such as key01-v1. In this scheme, the data structures of the same data in memory and on the hard disk are different, that is, the granularities of the memory model and the storage model are different. In this way, when retrieving data from the hard disk back to memory, a large number of unnecessary sub-key value pairs need to be retrieved together to ensure that Redis can smoothly read the target data, resulting in a high cost of data retrieval and a low cache hit rate due to a large number of meta key data being evicted from memory.
[0075] 2) As Figure 5 shown, Figure 5It is a schematic diagram of a method for implementing a storage-type Redis based on multi-key-value pair encoding methods such as Kvrocks and pika. Among them, Kvrocks is a storage system that is compatible with the Redis protocol based on RocksDB, and pika is a Redis-like storage system that uses the Redis protocol and is compatible with most Redis commands. In this solution, it is necessary to rely on the block cache in RocksDB as the cache for data reading and writing to read and write to RocksDB. However, the same caching strategy is adopted for the data of different data structures and the data of each meta-key sub-key in the block cache, ignoring the differences between different data structures and the differences in the reading frequencies of different types of data. In this way, when reading a large amount of sub-key value pairs, a large amount of meta-key data will be evicted, resulting in a low memory hit rate.
[0076] In view of this, the following embodiments of the present application provide a data caching method, which can cache key-value pair data of the metadata type and key-value pair data of other types except the metadata type into different memory spaces respectively, realizing that different types of data do not affect each other during reading and writing, solving the problem that key-value pair data of the metadata type is frequently evicted, improving the rationality of memory space allocation, increasing the cache hit rate, and thus improving the computing efficiency of the system.
[0077] Secondly, an exemplary introduction to the system architecture of the embodiments of the present application is given.
[0078] Figure 6 A schematic diagram of a computing device provided by an embodiment of the present application is shown. In terms of hardware, the computing device 100 may include a processor 101 and a memory 102. Among them, the memory 102 includes a non-persistent memory 1021, a persistent memory 1022, etc. In terms of software, the computing device 100 may have the function of caching the data in the persistent memory 1022 into the non-persistent memory 1021, that is, the computing device 100 can obtain target data; the target data includes key-value pair data; if the key-value pair data includes key-value pair data of the metadata type, the key-value pair data of the metadata type is cached in the first memory space; the key-value pair data of other types except the metadata type in the key-value pair data is cached in the second memory space. Among them, the first memory space is a part of the storage space set in the non-persistent memory 1021, and the second memory space is another part of the storage space set in the non-persistent memory 1021. The storage spaces of the above two parts are independent of each other, and the computing device 100 can cache the data in the persistent memory 1022 into the non-persistent memory 1021 through the bus.
[0079] Among them, the computing device may be a server, a computer device or a terminal.
[0080] It should be noted that for the computing device 100 described in the following embodiments to execute a certain step (such as S101 to S103 below), it can be understood that: the processor 101 executes this step.
[0081] Among them, the memory 102 may store the logic code corresponding to the computing device 100 described in the following embodiments to execute a certain step.
[0082] It should be noted that the system architecture and application scenarios described in the embodiments of the present application are for more clearly explaining the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those of ordinary skill in the art know that with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
[0083] For ease of understanding, the data caching method provided by the present application is exemplarily introduced below in conjunction with the accompanying drawings. This data caching method is applicable to Figure 6 the computing device shown.
[0084] Figure 7 The flowchart of a data caching method provided by an embodiment of the present application is shown. This data caching method includes the following steps:
[0085] Before step S101, the computing device may receive a data read / write instruction from the client, or may receive a data read / write request sent by other running programs. The present application does not limit the triggering condition of step S101. After parsing the received data read / write instruction or data read / write request, the computing device can determine the target data to be obtained.
[0086] S101, the computing device obtains the target data.
[0087] Among them, the target data includes key-value pair data.
[0088] When the computing device executes the above step S101, the target data may be obtained by the computing device from a storage medium in the storage system, such as a solid-state drive. Among them, the above storage system refers to a storage system running based on Figure 6 the persistent memory 1022 in the memory 102.
[0089] S102, if the key-value pair data includes key-value pair data of the metadata type, the computing device caches the key-value pair data of the metadata type in the first memory space.
[0090] In a possible implementation, when the computing device caches the key-value pair data of the metadata type in the first memory space, it can first determine the data structure of the target data. If the key-value pair data includes the key-value pair data of the metadata type, the computing device can cache the key-value pair data of the metadata type in the first memory space corresponding to the data structure of the target data.
[0091] Exemplarily, when the computing device determines that the data structure of the target data is of the hash type, it caches the key-value pair data of the metadata type in the target data of the hash type in the first memory space corresponding to the hash type; when the computing device determines that the data structure of the target data is of the list type, it caches the key-value pair data of the metadata type in the target data of the list type in the first memory space corresponding to the list type; when the computing device determines that the data structure of the target data is of the set type, it caches the key-value pair data of the metadata type in the target data of the set type in the first memory space corresponding to the set type; when the computing device determines that the data structure of the target data is of the sorted set type, it caches the key-value pair data of the metadata type in the target data of the sorted set type in the first memory space corresponding to the sorted set type.
[0092] Based on the above implementation, the computing device can cache the key-value pair data of the metadata type included in the target data of different data structures in the first memory space corresponding to their data structures. In this way, it can ensure that the key-value pair data of the metadata type of each different data structure will not be evicted from each other during reading and writing, improving the residence time of the key-value pair data of the metadata type in the first memory space and increasing the cache hit rate.
[0093] S103. The computing device caches the key-value pair data of other types except the metadata type in the key-value pair data in the second memory space.
[0094] Similar to the above possible implementation, when the computing device executes step S103, it can cache the key-value pair data of other types in the second memory space corresponding to the data structure of the target data.
[0095] Exemplarily, when the computing device determines that the data structure of the target data is of the list type, it caches the key-value pair data of other types except the metadata type in the target data of the list type in the second memory space corresponding to the list type.
[0096] Based on the above implementation, the computing device can cache the key-value pair data of other types included in the target data of different data structures in the second memory space corresponding to their data structures. In this way, it can ensure that the key-value pair data of other types of each different data structure will not be evicted from each other during reading and writing, improving the stability of the data in the second memory space and increasing the cache hit rate.
[0097] In a possible implementation, the computing device can cache different data for data of different data structures, specifically including:
[0098] 1) If the data structure of the target data is a hash type, cache the field value in the key-value pair data in the second memory space corresponding to the hash type.
[0099] 2) If the data structure of the target data is a list type, cache the element value in the key-value pair data in the second memory space corresponding to the list type.
[0100] 3) If the data structure of the target data is a string type, cache the character data in the key-value pair data in the second memory space corresponding to the string type.
[0101] 4) If the data structure of the target data is a set type, cache the set element value in the key-value pair data in the second memory space corresponding to the set type.
[0102] 5) If the data structure of the target data is an ordered set type, cache the ordered set element value in the key-value pair data in the second memory space corresponding to the ordered set type.
[0103] Specifically, as Figure 8 shown, Figure 8 FIG. is a schematic diagram of a partitioned cache provided by an embodiment of the present application. Among them, in the embodiment of the present application, the computing device can cache the list type metadata separately in the first memory space corresponding to the list type, and cache the list elements separately in the second memory space corresponding to the list type; cache the hash type metadata separately in the first memory space corresponding to the hash type, and cache the field value separately in the second memory space corresponding to the hash type; cache the string type metadata separately in the first memory space corresponding to the string type; cache the set type metadata separately in the first memory space corresponding to the set type, and cache the set elements separately in the second memory space corresponding to the set type; cache the ordered set type metadata separately in the first memory space corresponding to the ordered set type, and cache the ordered set elements separately in the second memory space corresponding to the ordered set type.
[0104] In this way, the computing device caches the data corresponding to each data type in independent memory spaces, so that the reading and writing of each data do not affect each other. In particular, data with a high access frequency will not be evicted due to reading a large amount of low-frequency data, improving the cache hit rate.
[0105] Moreover, as shown by the dashed boxes of the set and the ordered set in Figure 8 , there may be a situation where only one or more data structures have corresponding first memory spaces and / or second memory spaces. For another example, Figure 8As shown by the string data in , there may be a situation where only the second memory space has data while the first memory space has no data; in addition, there may also be a situation where only the first memory space has data while the second memory space has no data. Generally speaking, the settings of each memory space can vary according to actual requirements.
[0106] Based on the above implementation method, specific data in different data structures is cached in the second memory space corresponding to its data structure, realizing that the reading and writing of low-frequency data will not affect high-frequency data, thereby increasing the residence time and residence rate of high-frequency data in the memory space and improving the cache hit rate.
[0107] It should be noted that in the embodiments of the present application, the minimum cache unit of the target data in the memory space and its minimum storage unit in the storage system are both key-value pair data.
[0108] In this way, it is ensured that the memory model and its storage model granularity of the same data are consistent, avoiding the need for the computing device to retrieve other unnecessary data when retrieving data from the storage system, and reducing the retrieval cost.
[0109] When the computing device executes the above steps S102 and S103 and related possible implementation methods, the following problem may be faced: the memory space required by the target data to be processed is larger than the remaining free space in the memory space.
[0110] In the embodiments of the present application, a possible implementation method is also provided for this problem. The computing device respectively performs data eviction according to the eviction policies of the first memory space and the second memory space corresponding to the key-value pair data of each data structure, where the eviction policy is used to indicate the target eviction data and the trigger condition for evicting the target eviction data.
[0111] As Figure 9 shown, Figure 9 is a schematic diagram of the setting of an eviction policy involved in the embodiments of the present application. Among them, the first memory space A with a capacity of 500 megabytes is set with an eviction policy A, the second memory space B with a capacity of 300 megabytes is set with an eviction policy B, and the second memory space C with a capacity of 200 megabytes is set with an eviction policy C.
[0112] Exemplarily, when the computing device caches the key-value pair data of the metadata type in a target data of the hash type in the first memory space A, when the computing device determines that the trigger condition of the eviction policy A set in the first memory space A is satisfied, it determines the target eviction data according to the indication of the eviction policy A and performs data eviction.
[0113] Based on the above implementation, the computing device performs data eviction according to the independent eviction policies in each memory space, which can achieve eviction according to the data characteristics, improve the independence of data in different memory spaces, ensure the residence of key-value pair data of the metadata type in the first memory space, and improve the computing efficiency of the system.
[0114] Further, if the eviction policy is used to indicate the trigger condition for data eviction, the trigger condition includes triggering the eviction of target eviction data in the memory space when the size of the available memory space is less than or equal to a specified threshold.
[0115] Exemplarily, it is set in the eviction policy that when the size of the available memory space is less than or equal to 100 megabytes, the target eviction data in the memory space is triggered to be evicted.
[0116] In a possible implementation, if the eviction policy is used to indicate the trigger condition for data eviction, the trigger condition may further include triggering the eviction of target eviction data in the memory space at a preset time interval.
[0117] Exemplarily, it is set in the eviction policy that the target eviction data in the memory space is triggered to be evicted every 100 milliseconds.
[0118] Based on the above implementation, the accuracy and flexibility of the trigger timing of the eviction policy can be improved, so that there is sufficient available space in the memory space, ensuring the smooth writing of target data and improving the computing efficiency of the system.
[0119] Further, if the eviction policy is used to indicate the target eviction data, the eviction policy may include:
[0120] 1) If there is an importance level parameter for the cached data in the memory space, determine the target eviction data in the order of increasing importance level indicated by the importance level parameter.
[0121] Exemplarily, there are two key-value pair attributes of the metadata type in the first memory space A, namely metadata A and metadata B. The importance level parameter corresponding to metadata A is 5, and the importance level parameter corresponding to metadata B is 1. If the larger the importance level parameter, the higher the importance level, then when the computing device determines the target eviction data, it preferentially determines metadata B as the target eviction data.
[0122] In this way, it is possible to preferentially evict unimportant data, reduce the occupied degree of the memory space, and ensure the residence of important data in the memory space, improving the cache hit rate.
[0123] 2) Obtain the access frequencies of each cached data in the memory space during a preset time period, and determine the target eviction data among the other cached data except the cached data with the highest access frequency.
[0124] Exemplarily, there are two key-value pair attributes of other types in the second memory space B, namely other data B and other data C. Among them, the access frequency of other data B within a preset 1 minute is 500 times, and the access frequency of other data C within a preset 1 minute is 200 times. Then, when the computing device determines the target eviction data, other data B will not be determined as the target eviction data.
[0125] In this way, it can ensure that the highest-frequency data in the memory space stays in the memory space without being evicted, improving the cache hit rate.
[0126] 3) Obtain the access records of each cached data in the memory space within a preset time period, and determine the cached data with the earliest time corresponding to the most recent access record within the preset time period as the target eviction data.
[0127] Exemplarily, there are two key-value pair attributes of metadata types in the first memory space C, namely metadata D and metadata E. Among them, within the preset current date from 10:00 am to 18:00 pm, the time corresponding to the most recent access record of metadata D is 17:01:06, and the time corresponding to the most recent access frequency record of metadata E is 17:05:11. Then, when the computing device determines the target eviction data, it preferentially determines metadata D as the target eviction data.
[0128] It can be understood that the data with an earlier time corresponding to the most recent access record within the preset time period may have a lower importance level and access frequency compared to other data. In this way, it can achieve preferentially evicting the above-mentioned unimportant low-frequency data, ensuring the residence of more important high-frequency data in the memory space, and improving the cache hit rate.
[0129] It should be noted that according to different actual requirements, the above 3 eviction rules can be arbitrarily combined and used. In addition, new eviction rules can also be formulated and combined according to actual requirements. Among them, as Figure 10 shown, Figure 10 is a schematic diagram of an eviction policy setting involved in an embodiment of the present application. The user can input the name of the eviction policy and check the eviction rules used in the eviction policy, such as eviction rule A, eviction rule B, etc. After setting, it can be saved by clicking the "Save" control.
[0130] Exemplarily, the user inputs and names the eviction policy as: Hash the First Memory Space, and only checks eviction rule A, and then clicks the save control. In this way, an eviction policy named "Hash the First Memory Space" and adopting eviction rule A is saved.
[0131] Furthermore, based on the saved eviction policy, the user can perform eviction policy application settings for each memory space, as Figure 11 shown,Figure 11 It is a schematic diagram of the application setting of an eviction policy involved in an embodiment of the present application. In the column of "data structure type", the user can select from the following options: hash type, list type, string type, set type, sorted set type; in the column of "memory space type", the user can select from the following options: first memory space, second memory space; in the column of "eviction policy", the user can select from the saved eviction policies.
[0132] The options involved in the application setting of the eviction policy are set according to actual needs. For example, if the first memory space and the second memory space are not set for the set type in the current system, then in the column of data structure type in the application setting of the eviction policy, the option may not include the set type, or a prompt may be given after the user selects the set type to reduce misoperations.
[0133] To further improve the rationality of memory space allocation, the computing device can also dynamically adjust the capacity of each memory space, such as Figure 12 shown Figure 12 It is a schematic diagram of the dynamic adjustment of the memory space capacity involved in an embodiment of the present application.
[0134] Specifically, the computing device can perform the following steps, including:
[0135] 1) Obtain the access frequencies of the first memory space and the second memory space within a preset time period.
[0136] Among them, the computing device can regularly obtain the access frequencies of the first memory space and the second memory space within a preset time period at a preset time interval.
[0137] Exemplarily, as Figure 12 shown, the computing device can obtain the access frequencies of the first memory space A, the second memory space B, and the second memory space C in the past 1 minute every 1 minute, and the corresponding results are 600 times, 200 times, and 200 times.
[0138] 2) Determine the ratio of the access frequency to the capacity of the corresponding memory space; the larger the value of the ratio, the greater the required capacity of the corresponding memory space.
[0139] Exemplarily, as Figure 12 shown, the ratio of the access frequency of the first memory space A in the past 1 minute to its memory space capacity is 1.2, the ratio of the second memory space B is 0.67, and the ratio of the second memory space C is 1. It can be understood that among the above 3 memory spaces, according to the sorting results of the ratio sizes, obviously the first memory space A requires a larger capacity, and the capacity of the second memory space B can be reduced.
[0140] 3) Adjust the capacities of the first memory space and the second memory space according to the respective ratios.
[0141] In a possible implementation, the computing device adjusts the capacities of the first memory space and the second memory space according to the respective ratios and a preset adjustment range.
[0142] Exemplarily, as Figure 12 shown, according to the respective ratios, it can be determined that the capacity of the first memory space A needs to be increased and the capacity of the second memory space B needs to be decreased. According to the preset adjustment range of 10 megabytes, the capacity of the first memory space A is adjusted from the original 500 megabytes to 510 megabytes; the capacity of the second memory space B is adjusted from the original 300 megabytes to 290 megabytes; the second memory space C remains unchanged at 200 megabytes. Among them, the adjustment range can be preset by the user according to actual needs. For example, when the capacities of all memory spaces are in the range of 1 - 10 megabytes, the adjustment range can be set to 1 megabyte. In this way, when dynamically adjusting each memory space, the set capacity of the memory space will not be greater than the actual capacity, avoiding data read and write errors.
[0143] Based on the above implementation, the computing device can dynamically adjust the memory space according to the ratio of the access frequency of each memory space within a preset time period and the corresponding memory space capacity, allocate a larger capacity to the memory space with a higher access frequency, and improve the rationality of the memory space capacity allocation.
[0144] For the above dynamic adjustment process of the memory space, refer to Figure 13 , Figure 13 which is a schematic diagram of the setting of a dynamic adjustment switch involved in an embodiment of the present application. In the column of "Data Structure Type", the user can select from the following options: hash type, list type, string type, set type, ordered set type; in the column of "Memory Space Type", the user can select from the following options: first memory space, second memory space; in the column of "Whether to Enable Dynamic Adjustment", the user can select from the following options: yes, no. After the user sets the above parameters, the user can click the "Apply" control to make the current settings take effect.
[0145] In a possible implementation, the computing device dynamically adjusts the memory space according to the dynamic adjustment parameters set by the user.
[0146] After the user clicks the "Apply" control, an interface as Figure 14 shown can be further displayed. Figure 14It is a schematic diagram of dynamically adjusting parameter settings involved in an embodiment of the present application. Among them, in the column of "Dynamic Adjustment Frequency", the user can select from the following options: adjust once every 1 minute, adjust once every 5 minutes, adjust once every 30 minutes, etc. The above options can be configured according to actual needs. In the column of "Dynamic Adjustment Range", the user can select from the following options: 1 megabyte, 10 megabytes, 50 megabytes, 100 megabytes, etc. The above options can also be configured according to actual needs.
[0147] Exemplarily, if the user selects to enable the dynamic adjustment of the first memory space of the hash type and the first memory space of the list type, and the user selects to adjust once every 1 minute in the column of "Dynamic Adjustment Frequency", and selects 10 megabytes in the column of "Dynamic Adjustment Frequency", the computing device will obtain the access times of the first memory spaces of the hash type and the list type every 1 minute respectively, and calculate the ratio with their capacities respectively. When the corresponding ratio of the first memory space of the hash type is 1.5 and the corresponding ratio of the first memory space of the list type is 0.6, the capacity of the first memory space of the hash type will be increased by 10 megabytes, and the capacity of the first memory space of the list type will be decreased by 10 megabytes.
[0148] In a possible implementation manner, the computing device responds to a data reading instruction, reads key-value pair data of the metadata type from the first memory space; determines whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type; if the key-value pair data of other types has not expired, reads the key-value pair data of other types from the second memory space.
[0149] In a possible implementation manner, if the key-value pair data of other types has expired, the computing device deletes the key-value pair data of other types.
[0150] Specifically, as Figure 15 shown, Figure 15 It is a schematic diagram of a data reading process provided by an embodiment of the present application, specifically including the following steps:
[0151] S201, receive a data reading instruction.
[0152] In this step, the computing device can receive a data reading instruction from the client through Redis, and determine the target data to be obtained according to the data reading instruction.
[0153] S202, obtain metadata from the first memory space.
[0154] In this step, the access efficiency of the memory space is much higher than that of the storage system. Therefore, the computing device first obtains the metadata corresponding to the target data from the first memory space. If the metadata exists in the first memory space, S203 is skipped; otherwise, the computing device executes S203.
[0155] S203. Obtain the metadata from the storage system.
[0156] In this step, when the computing device cannot obtain the metadata corresponding to the target data from the first memory space, it obtains the metadata from the storage system and caches it in the first memory space. Here, the storage system can be a file storage system based on Rocksdb and running on a persistent storage medium such as a solid-state drive.
[0157] In a possible implementation, the computing device can first determine the data structure of the target data, and then cache the metadata read from the storage system in the first memory space corresponding to the data structure.
[0158] S204. Return the metadata.
[0159] In this step, the computing device returns the metadata in the first memory space to Redis, so that it can determine whether the corresponding other type of key-value pair has expired through the attribute information in the metadata, and determine its location in the second memory space.
[0160] S205. Obtain other type of key-value pairs from the second memory space.
[0161] Similar to the above step S202, in this step, the computing device first obtains other type of key-value pairs from the second memory space. If the metadata exists in the second memory space, S206 is skipped; otherwise, the computing device executes S206.
[0162] S206. Obtain other type of key-value pairs from the storage system.
[0163] In this step, when the computing device cannot obtain the other type of key-value pairs corresponding to the target data from the second memory space, it obtains the other type of key-value pairs from the storage system and caches them in the second memory space.
[0164] S207. Return other type of key-value pairs.
[0165] In this step, the computing device returns the other type of key-value pairs in the second memory space to Redis, so that it can complete the response operation to the data reading instruction.
[0166] S208. Return other type of key-value pairs.
[0167] In this step, the computing device can return other types of key-value pairs to the client through Redis.
[0168] Based on the above steps S201 - S208, the computing device has successfully completed a response operation for the received data reading instruction, and in this process, it has implemented the partitioned caching of metadata and other types of key-value pairs, solved the problem that key-value pairs of the metadata type are frequently evicted from the memory space, and improved the cache hit rate.
[0169] In a possible implementation, the computing device can respond to a data writing instruction, read the key-value pair data of the metadata type from the first memory space; determine whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type; if the key-value pair data of other types has not expired, read the key-value pair data of other types from the second memory space, and sequentially modify the key-value pair data in the storage system, the key-value pair data of the metadata type in the first memory space, and the key-value pair data of other types in the second memory space; the computing device returns a modification completion signal to the client.
[0170] Exemplarily, as Figure 16 shown, Figure 16 is a schematic diagram of a data writing process provided by an embodiment of the present application, which specifically includes the following steps:
[0171] S301, Receive a data reading instruction.
[0172] S302, Obtain metadata from the first memory space.
[0173] S303, Obtain metadata from the storage system.
[0174] S304, Return metadata.
[0175] S305, Obtain other types of key-value pairs from the second memory space.
[0176] S306, Obtain other types of key-value pairs from the storage system.
[0177] S307, Return other types of key-value pairs.
[0178] It should be noted that steps S301 - S307 are similar to the above steps S201 - S207, and their specific functions and explanations will not be elaborated here.
[0179] S308, Modify the metadata and other types of key-value pairs in the storage system.
[0180] In this step, the computing device modifies the metadata and other types of key-value pairs in the storage system.
[0181] S309, Modify the metadata.
[0182] In this step, the computing device modifies the metadata and other types of key-value pairs in the first memory space.
[0183] S310, Modify other types of key-value pairs.
[0184] In this step, the computing device modifies the metadata and other types of key-value pairs in the second memory space.
[0185] Through the above steps S308 - S310, the computing device can complete the synchronous modification of the memory space and the storage system, avoiding the situation of errors in the same data.
[0186] S311, Return the modification completion signal.
[0187] In this step, the computing device returns the modification completion signal to the client through Redis.
[0188] Based on the above steps S301 - S311, the computing device successfully completes a response operation for the received data write instruction, and realizes the partitioned caching of metadata and other types of key-value pairs during this process, solves the problem that key-value pairs of the metadata type are frequently evicted from the memory space, and improves the cache hit rate.
[0189] In summary, according to the different data types in the target data, the key-value pair data of the metadata type and the key-value pair data of other types are respectively cached in different memory spaces, which can achieve that different types of data do not affect each other during reading and writing, solves the problem that the key-value pair data of the metadata type is frequently evicted, improves the rationality of memory space allocation, improves the cache hit rate, and thus improves the computing efficiency of the system.
[0190] The above mainly introduces the solution of the embodiment of the present application from the perspective of the method. It can be understood that in order to implement the above functions, the data caching device includes at least one of the corresponding hardware structures and software modules for executing each function. Those skilled in the art should easily realize that, combining the units and algorithm steps of each example described in the embodiments disclosed in this article, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the way of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present application.
[0191] Embodiments of the present application can divide the functional units of the data caching device according to the above method examples. For example, each functional unit can be divided corresponding to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. It should be noted that the division of units in the embodiments of the present application is illustrative, only a logical function division, and there may be other division methods in actual implementation.
[0192] Exemplarily, Figure 17 FIG. 5 shows a schematic structural diagram of a data caching device 1300 provided by an exemplary embodiment of the present application. The data caching device 1300 is applied to a computing device, or the data caching device 1300 can be a computing device. The data caching device 1300 includes:
[0193] An acquisition module 1310, configured to acquire target data; the target data includes key-value pair data;
[0194] A first caching module 1320, configured to cache the key-value pair data of the metadata type in a first memory space if the key-value pair data includes key-value pair data of the metadata type;
[0195] A second caching module 1330, configured to cache the key-value pair data of other types except the metadata type in the key-value pair data in a second memory.
[0196] Among them, the acquisition module 1310, the first caching module 1320, and the second caching module 1330 can all be implemented by software or can be implemented by hardware. Exemplarily, next, taking the acquisition module 1310 as an example, the implementation manner of the acquisition module 1310 is introduced. Similarly, the implementation manners of the first caching module 1320 and the second caching module 1330 can refer to the implementation manner of the acquisition module 1310.
[0197] As an example of a software functional unit, the obtaining module 1310 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above computing instance may be one or more. For example, the obtaining module 1310 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers for running the code may be distributed in the same region or in different regions. Further, the multiple hosts / virtual machines / containers for running the code may be distributed in the same availability zone (AZ) or in different AZs, and each AZ includes one data center or multiple geographically proximate data centers. Usually, one region may include multiple AZs.
[0198] Similarly, the multiple hosts / virtual machines / containers for running the code may be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, one VPC is set within one region. For cross-region communication between two VPCs within the same region and between VPCs in different regions, a communication gateway needs to be set in each VPC, and the interconnection between VPCs is realized through the communication gateway.
[0199] As an example of a hardware functional unit, the obtaining module 1310 may include at least one computing device, such as a server, etc. Alternatively, the obtaining module 1310 may also be a device implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The above PLD may be implemented by a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0200] The multiple computing devices included in the obtaining module 1310 may be distributed in the same region or in different regions. The multiple computing devices included in the obtaining module 1310 may be distributed in the same availability zone (AZ) or in different AZs. Similarly, the multiple computing devices included in the obtaining module 1310 may be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Among them, the multiple computing devices may be any combination of computing devices such as servers, application-specific integrated circuits (ASICs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), and generic array logic (GALs).
[0201] It should be noted that in other embodiments, the obtaining module 1310 may be used to execute any step in the data caching method, the first caching module 1320 may be used to execute any step in the data caching method, and the second caching module 1330 may be used to execute any step in the data caching method. The steps to be implemented by the obtaining module 1310, the first caching module 1320, and the second caching module 1330 can be specified as needed. The entire function of the data caching device is realized by implementing different steps in the data caching method through the obtaining module 1310, the first caching module 1320, and the second caching module 1330 respectively.
[0202] In a possible implementation manner, the first caching module 1320 is further configured to determine the data structure of the target data; if the key-value pair data includes the key-value pair data of the metadata type, cache the key-value pair data of the metadata type in the first memory space corresponding to the data structure of the target data.
[0203] In a possible implementation manner, the second caching module 1330 is further configured to cache the key-value pair data of other types in the second memory space corresponding to the data structure of the target data.
[0204] In a possible implementation manner, the second caching module 1330 is further configured to, if the data structure of the target data is a hash type, cache the field values in the key-value pair data in the second memory space corresponding to the hash type;
[0205] if the data structure of the target data is a list type, cache the element values in the key-value pair data in the second memory space corresponding to the list type;
[0206] if the data structure of the target data is a string type, cache the character data in the key-value pair data in the second memory space corresponding to the string type;
[0207] if the data structure of the target data is a set type, cache the set element values in the key-value pair data in the second memory space corresponding to the set type;
[0208] If the data structure of the target data is an ordered set type, cache the ordered set element values in the key-value pair data in the second memory space corresponding to the ordered set type.
[0209] In a possible implementation, the first memory space and the second memory space corresponding to the key-value pair data of each data structure perform data eviction according to their respective eviction policies; the eviction policy is used to indicate the target eviction data and the trigger condition for evicting the target eviction data.
[0210] In a possible implementation, if the eviction policy is used to indicate the trigger condition for data eviction, the trigger condition includes triggering the eviction of the target eviction data in the memory space when the size of the available memory space is less than or equal to a specified threshold.
[0211] In a possible implementation, if the eviction policy is used to indicate the target eviction data, the eviction policy at least includes:
[0212] If there is an importance level parameter for the cached data in the memory space, determine the target eviction data in the order of increasing importance level indicated by the importance level parameter; and / or,
[0213] Obtain the access frequencies of each cached data in the memory space in a preset time period, and determine the target eviction data among the cached data other than the cached data with the highest access frequency; and / or,
[0214] Obtain the access records of each cached data in the memory space in a preset time period, and determine the cached data with the earliest time corresponding to the most recent access record in the preset time period as the target eviction data.
[0215] In a possible implementation, it further includes an adjustment module 1340, and the adjustment module 1340 is used to obtain the access frequencies of the first memory space and the second memory space in a preset time period;
[0216] Determine the ratio of the access frequency to the capacity of the corresponding memory space; the larger the value of the ratio, the greater the required capacity of the corresponding memory space;
[0217] Adjust the capacities of the first memory space and the second memory space according to each of the ratios.
[0218] In a possible implementation, the minimum cache unit of the target data in the memory space and its minimum storage unit in the storage system are both key-value pair data.
[0219] In a possible implementation, it further includes a processing module 1350, which is configured to read the key-value pair data of the metadata type from the first memory space in response to a data reading instruction;
[0220] Determine whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type;
[0221] If the key-value pair data of other types has not expired, read the key-value pair data of other types from the second memory space.
[0222] In a possible implementation, after the processing module 1350 determines whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type, the method further includes:
[0223] If the key-value pair data of other types has expired, delete the key-value pair data of other types.
[0224] This application also provides a computing device 100. As Figure 18 shown, the computing device 100 includes: a bus 102, a processor 104, a memory 106, and a communication interface 108. The processor 104, the memory 106, and the communication interface 108 communicate with each other through the bus 102. The computing device 100 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 100.
[0225] The bus 102 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, Figure 18 only one line is shown herein, but it does not mean that there is only one bus or one type of bus. The bus 104 can include a path for transmitting information between various components of the computing device 100 (such as the memory 106, the processor 104, and the communication interface 108).
[0226] The processor 104 may include any one or more of processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0227] The memory 106 may include volatile memory, such as random access memory (RAM). The processor 104 may also include non-volatile memory, such as read-only memory (ROM), flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0228] The memory 106 stores executable program code, and the processor 104 executes the executable program code to respectively implement the functions of the foregoing acquisition module, first cache module, and second cache module, thereby implementing the data caching method. That is, the memory 106 stores instructions for executing the data caching method.
[0229] The embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device may be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device may also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.
[0230] As Figure 19 shown, the computing device cluster includes at least one computing device 100. The memory 106 in one or more of the computing devices 100 in the computing device cluster may store the same instructions for executing the data caching method.
[0231] In some possible implementation manners, the memory 106 in one or more of the computing devices 100 in the computing device cluster may also respectively store partial instructions for executing the data caching method. In other words, a combination of one or more computing devices 100 may jointly execute the instructions for executing the data caching method.
[0232] It should be noted that the memories 106 in different computing devices 100 in the computing device cluster may store different instructions, which are respectively used to execute partial functions of the data caching device. That is to say, the instructions stored in the memories 106 in different computing devices 100 can implement the functions of one or more of the acquisition module, the first caching module, and the second caching module.
[0233] In some possible implementation manners, one or more computing devices in the computing device cluster may be connected through a network. Among them, the network may be a wide area network or a local area network, etc. Figure 20 A possible implementation manner is shown. As Figure 20 shown, two computing devices 100A and 100B are connected through a network. Specifically, they are connected to the network through the communication interfaces in each computing device. In this type of possible implementation manner, the memory 106 in the computing device 100A stores instructions for executing the function of the acquisition module. At the same time, the memory 106 in the computing device 100B stores instructions for executing the functions of the first caching module and the second caching module.
[0234] Figure 20 The connection manner between the computing device clusters shown may be considered that since the data caching method provided in this application requires a large amount of data caching, the functions implemented by the first caching module and the second caching module are considered to be executed by the computing device 100B.
[0235] It should be understood that Figure 20 the function of the computing device 100A shown in
[0236] This application embodiment also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions that can run on a computing device or be stored in any available medium. When the computer program product runs on at least one computing device, it causes at least one computing device to execute the data caching method, or the data caching method.
[0237] This application embodiment also provides a computer-readable storage medium. The computer-readable storage medium may be any available medium that a computing device can store or a data storage device such as a data center containing one or more available media. The available medium may be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid-state drive), etc. The computer-readable storage medium includes instructions, and the instructions instruct the computing device to execute the data caching method, or instruct the computing device to execute the data caching method.
[0238] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data caching method, characterized in that, The method includes: Obtaining target data; the target data includes key-value pair data; If the key-value pair data includes key-value pair data of the metadata type, caching the key-value pair data of the metadata type in a first memory space; Caching the key-value pair data of other types except the metadata type in the key-value pair data in a second memory space.
2. The method according to claim 1, characterized in that, The step of if the key-value pair data includes key-value pair data of the metadata type, caching the key-value pair data of the metadata type in a first memory space includes: Determining the data structure of the target data; If the key-value pair data includes the key-value pair data of the metadata type, caching the key-value pair data of the metadata type in the first memory space corresponding to the data structure of the target data.
3. The method according to claim 1 or 2, characterized in that, The step of caching the key-value pair data of other types except the metadata type in the key-value pair data in a second memory space includes: Caching the key-value pair data of other types in the second memory space corresponding to the data structure of the target data.
4. The method according to any one of claims 1 to 3, characterized in that, The step of caching the key-value pair data of other types except the metadata type in the key-value pair data in a second memory space includes: If the data structure of the target data is a hash type, caching the field values in the key-value pair data in the second memory space corresponding to the hash type; If the data structure of the target data is a list type, caching the element values in the key-value pair data in the second memory space corresponding to the list type; If the data structure of the target data is a string type, caching the character data in the key-value pair data in the second memory space corresponding to the string type; If the data structure of the target data is a set type, caching the set element values in the key-value pair data in the second memory space corresponding to the set type; If the data structure of the target data is an ordered set type, caching the ordered set element values in the key-value pair data in the second memory space corresponding to the ordered set type.
5. The method according to any one of claims 1 to 4, characterized in that, The first memory space and the second memory space corresponding to the key-value pair data of each data structure perform data eviction according to their respective eviction policies; the eviction policy is used to indicate the target eviction data and the trigger condition for evicting the target eviction data.
6. The method according to claim 5, wherein If the eviction policy is used to indicate the trigger condition for data eviction, the trigger condition includes triggering the eviction of the target eviction data in the memory space when the size of the available memory space is less than or equal to a specified threshold.
7. The method according to claim 5 or 6, characterized in that, If the eviction policy is used to indicate the target eviction data, the eviction policy at least includes: If there is an importance level parameter for the cached data in the memory space, determining the target eviction data in the order of increasing importance level indicated by the importance level parameter; and / or, Obtaining the access frequencies of the cached data in the memory space in a preset time period, and determining the target eviction data among the cached data other than the cached data with the highest access frequency; and / or, Obtain the access records of each cached data in the memory space within a preset time period, and determine the cached data with the earliest time corresponding to the most recent access record within the preset time period as the target eviction data.
8. The method according to any one of claims 1-7, characterized in that, The method further includes: Obtain the access frequencies of the first memory space and the second memory space within a preset time period; Determine the ratio of the access frequency to the capacity of the corresponding memory space; the larger the value of the ratio, the greater the required capacity of the corresponding memory space; Adjust the capacities of the first memory space and the second memory space according to each of the ratios.
9. The method according to claim 1, characterized in that, The minimum cache unit of the target data in the memory space and its minimum storage unit in the storage system are both key-value pair data.
10. The method according to any one of claims 1-9, characterized in that, The method further includes: In response to a data read instruction, read the key-value pair data of the metadata type from the first memory space; Determine whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type; If the key-value pair data of other types has not expired, read the key-value pair data of other types from the second memory space.
11. The method according to claim 10, characterized in that, After determining whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type, the method further includes: If the key-value pair data of other types has expired, delete the key-value pair data of other types.
12. A data caching device, characterized in that, The device includes: An acquisition module, configured to acquire target data; the target data includes key-value pair data; A first cache module, configured to cache the key-value pair data of the metadata type in the first memory space if the key-value pair data includes the key-value pair data of the metadata type; A second cache module, configured to cache the key-value pair data of other types except the metadata type in the key-value pair data in the second memory space.
13. The data caching device according to claim 12, wherein When caching the key-value pair data of the metadata type in the first memory space if the key-value pair data includes the key-value pair data of the metadata type, the first cache module is used for: Determine the data structure of the target data; If the key-value pair data includes the key-value pair data of the metadata type, cache the key-value pair data of the metadata type in the first memory space corresponding to the data structure of the target data.
14. The data caching device according to claim 12 or 13, characterized in that, When caching the key-value pair data of other types except the metadata type in the key-value pair data in the second memory space, the second cache module is used for: Cache the key-value pair data of other types in the second memory space corresponding to the data structure of the target data.
15. The data caching device according to any one of claims 12-14, characterized in that, When caching the key-value pair data of other types except the metadata type in the key-value pair data in the second memory space, the second cache module is used for: If the data structure of the target data is a hash type, cache the field values in the key-value pair data in the second memory space corresponding to the hash type; If the data structure of the target data is a list type, cache the element values in the key-value pair data in the second memory space corresponding to the list type; If the data structure of the target data is of string type, cache the character data in the key-value pair data in the second memory space corresponding to the string type; If the data structure of the target data is of set type, cache the set element values in the key-value pair data in the second memory space corresponding to the set type; If the data structure of the target data is of sorted set type, cache the sorted set element values in the key-value pair data in the second memory space corresponding to the sorted set type.
16. The data caching device according to any one of claims 12-15, characterized in that, The first memory space and the second memory space corresponding to the key-value pair data of each data structure perform data eviction according to their respective eviction policies; the eviction policy is used to indicate the target evicted data and the triggering condition for evicting the target evicted data.
17. The data caching device according to claim 16, wherein If the eviction policy is used to indicate the triggering condition for data eviction, the triggering condition includes triggering the eviction of the target evicted data in the memory space when the size of the available memory space is less than or equal to the specified threshold.
18. The data caching device according to claim 16 or 17, wherein If the eviction policy is used to indicate the target evicted data, the eviction policy at least includes: If there is an importance level parameter for the cached data in the memory space, determine the target evicted data in the order of increasing importance level indicated by the importance level parameter; and / or, Obtain the access frequencies of the cached data in the memory space in a preset time period, and determine the target evicted data among the cached data other than the cached data with the highest access frequency; and / or, Obtain the access records of the cached data in the memory space in a preset time period, and determine the cached data with the earliest time corresponding to the most recent access record in the preset time period as the target evicted data.
19. The data caching device according to any one of claims 12-18, characterized in that, It further includes an adjustment module, and the adjustment module is used for: Obtain the access frequencies of the first memory space and the second memory space in a preset time period; Determine the ratio of the access frequency to the capacity of the corresponding memory space; The larger the value of the ratio, the greater the required capacity of the corresponding memory space; Adjust the capacities of the first memory space and the second memory space according to each ratio.
20. The data caching device according to claim 12, wherein The minimum cache unit of the target data in the memory space and its minimum storage unit in the storage system are both key-value pair data.
21. The data caching device according to any one of claims 12-20, characterized in that, It further includes a processing module, and the processing module is used for: In response to a data reading instruction, read the key-value pair data of the metadata type from the first memory space; Determine whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type; If the key-value pair data of other types has not expired, read the key-value pair data of other types from the second memory space.
22. The data caching device according to claim 21, wherein After determining whether the corresponding key-value pair data of other types has expired according to the attribute information included in the key-value pair data of the metadata type, the processing module is further used for: If the key-value pair data of other types has expired, delete the key-value pair data of other types.
23. A cluster of computing devices, characterized in that, including at least one computing device, each computing device including a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the data caching method according to any one of claims 1 to 11.
24. A computer program product, characterized in that, The computer program product includes instructions that, when run by a computing device cluster, cause the computing device cluster to execute the data caching method according to any one of claims 1 to 11.
25. A computer-readable storage medium, characterized in that, including computer program instructions that, when executed by a computing device cluster, cause the computing device cluster to execute the data caching method according to any one of claims 1 to 11.