Data caching method, device, electronic device and computer readable medium
By prioritizing the replacement of data blocks or pages with the least disk access time in the cache, the problem that existing caching strategies cannot effectively reduce the cost of disk access is solved, resulting in more efficient data throughput and lower latency.
Patent Information
- Application Number
- CN201911261824.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-10
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2039-12-10
AI Technical Summary
In existing technologies, LRU and LFU caching strategies cannot effectively reduce the time cost of database or storage system accessing disk, resulting in performance degradation.
By using information about data blocks or pages in the cache, we can determine which data blocks or pages take the least time to access the disk, and then prioritize replacing these data blocks or pages from the cache, using the freed-up cache space to cache new data.
It effectively reduces the time cost of database or storage system accessing disk, increases data throughput, and reduces data latency.
Smart Images

Figure CN112948286B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data storage, and in particular to a data caching method, device, electronic device, and computer-readable medium. Background Art
[0002] In databases or storage systems, cache technology plays a very important role. When a user initiates a data query request to a database or storage system, the database or storage system will first access the cache. If the cache stores the data queried by the user, the database or storage system will directly return the data queried by the user to the user. If the cache does not store the data queried by the user, the database or storage system needs to access the disk (such as a non-volatile storage medium such as a mechanical disk or a solid-state drive) to obtain the data queried by the user. Since the data latency of the disk is high and the data throughput is low, if the cache cannot effectively improve the data throughput of the database or storage system and reduce the data latency of the database or storage system, the performance of the database or storage system will be greatly reduced.
[0003] In the prior art, based on LRU (Least Rcently Used) or LFU (Least Frequently Used), the data pages to be replaced in the cache are selected, and the replaced cache space is used to cache the data. Specifically, the data read from the disk is maintained in a data structure in units of a fixed size (such as a 4KB data page). Using LRU, the data page that has not been used for the longest time is selected from the cache for replacement, or using LFU, the data page with the lowest frequency of use is selected from the cache for replacement. Then, the replaced cache space is used to cache the data. However, whether it is LRU or LFU, the data structure it maintains is aimed at maximizing the hit rate of the data page, but it cannot effectively reduce the time cost of the database or storage system accessing the disk, thereby failing to effectively improve the data throughput of the database or storage system and reduce the data latency of the database or storage system.
[0004] Therefore, how to effectively reduce the time cost of a database or storage system accessing a disk has become a technical problem that needs to be solved urgently. Summary of the invention
[0005] The purpose of the present application is to propose a data caching method, device, electronic device and computer-readable medium to solve the problem existing in the prior art of how to effectively reduce the time cost of a database or storage system accessing a disk.
[0006] According to a first aspect of an embodiment of the present application, a data caching method is provided. The method comprises: determining, based on block information of a first data block in a cache, the time saved by the first data block to avoid a database or storage system accessing a disk; determining, based on the time, a second data block to be replaced from the cache; and caching data based on the cache space of the second data block to be replaced.
[0007] According to a second aspect of an embodiment of the present application, a data caching method is provided. The method comprises: determining, based on page information of a first data page in a cache, the time saved by the first data page to avoid a database or storage system accessing a disk; determining, based on the time, a second data page to be replaced from the cache; and caching data based on the cache space of the second data page to be replaced.
[0008] According to a third aspect of an embodiment of the present application, a data cache device is provided. The device includes: a first determination module, used to determine the time saved by the first data block in the cache to avoid the database or storage system from accessing the disk based on the block information of the first data block in the cache; a second determination module, used to determine the second data block replaced from the cache based on the time; a first cache module, used to cache data based on the cache space of the second data block replaced.
[0009] According to a fourth aspect of an embodiment of the present application, a data cache device is provided. The device includes: a third determination module, for determining, based on page information of a first data page in a cache, the time saved by the first data page to avoid a database or storage system accessing a disk; a fourth determination module, for determining, based on the time, a second data page to be replaced from the cache; and a second cache module, for caching data based on the cache space of the second data page to be replaced.
[0010] According to the fifth aspect of the embodiments of the present application, an electronic device is provided, comprising: one or more processors; a computer-readable medium configured to store one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method as described in the first aspect or the second aspect of the above-mentioned embodiments.
[0011] According to a sixth aspect of an embodiment of the present application, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the data caching method described in the first aspect or the second aspect of the above embodiment is implemented.
[0012] According to the technical solution provided in the embodiment of the present application, based on the block information of the first data block in the cache, the time saved by the first data block to avoid the database or storage system accessing the disk is determined; based on the time, the second data block to be replaced from the cache is determined; based on the cache space of the second data block to be replaced, data is cached. Compared with the existing LRU scheme or LFU scheme, based on the time saved by the first data block to avoid the database or storage system accessing the disk, the second data block to be replaced from the cache is determined, and data is cached based on the cache space of the second data block to be replaced, so that the database or storage system can make full use of the cache space and effectively reduce the time cost of the database or storage system accessing the disk, thereby not only effectively improving the data throughput of the database or storage system, but also effectively reducing the data delay of the database or storage system. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0014] Figure 1 This is a flowchart of the steps of the data caching method in Embodiment 1 of the present application;
[0015] Figure 2A This is a flowchart of the steps of the data caching method in Embodiment 2 of the present application;
[0016] Figure 2B A schematic diagram of a cache space provided according to Embodiment 2 of the present application;
[0017] Figure 2C A schematic diagram of swapping out a data page cache according to Embodiment 2 of the present application;
[0018] Figure 2D A schematic diagram of swapping out a data page cache according to Embodiment 2 of the present application;
[0019] Figure 3 This is a schematic diagram of the structure of the data cache device in the third embodiment of the present application;
[0020] Figure 4 This is a schematic diagram of the structure of the data cache device in the fourth embodiment of the present application;
[0021] Figure 5 This is a schematic diagram of the structure of the data cache device in Embodiment 5 of the present application;
[0022] Figure 6 This is a structural diagram of a data cache device in Embodiment 6 of the present application;
[0023] Figure 7 This is a schematic diagram of the structure of an electronic device in Embodiment 7 of the present application;
[0024] Figure 8 This is the hardware structure of the electronic device in Example 8 of the present application. DETAILED DESCRIPTION
[0025] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only configured to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0026] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] In the prior art, based on LRU or LFU, the data page to be replaced in the cache is selected, and the replaced cache space is used to cache data. Among them, the data structure maintained by LRU or LFU is aimed at the highest hit rate of data pages. However, in many application scenarios, the highest hit rate of data pages does not mean that the database or storage system has the lowest time cost for accessing the disk. In other words, when ensuring the highest hit rate of data pages, the time cost of accessing the disk by the database or storage system cannot be effectively reduced.
[0028] Before explaining why the highest hit rate of data pages does not mean that the database or storage system has the lowest time cost for accessing the disk, the following assumptions are made: 1. Similar to most data caching methods, it is assumed that the future access pattern of the database or storage system is similar to the historical access pattern; 2. In order to more clearly explain why the highest hit rate of data pages does not mean that the database or storage system has the lowest time cost for accessing the disk, assume the following simplified access scenario: 2.1. The database or storage system has two disk access modes, one disk access mode is to continuously access 4KB data blocks on the disk, and the other disk access mode is to continuously access 16KB data blocks on the disk; 2.2. It takes 1ms for the database or storage system to access a 4KB data block on the disk, and it also takes approximately 1ms to access a 16KB data block on the disk; 2.3. The access popularity of 4KB data blocks on the disk and 16KB data blocks on the disk is always similar; 2.4. The cache size is 640KB, which contains 80 4KB data blocks and 20 16KB data blocks.
[0029] In the current access scenario, if a data block in the cache needs to be replaced, the cache system will randomly select 4KB data in the cache for replacement because the access popularity of the two sizes of data blocks is similar. If the cache system selects a 4KB data block that will be accessed independently, only 4KB of cache space will be freed in the cache. The next time the database or storage system accesses this 4KB data block again, it needs to access the disk to read the 4KB data block, which consumes 1ms more time. If the cache system selects 4KB data in a 16KB data block, 4KB of cache space will also be freed in the cache. The next time the database or storage system accesses this 16KB data block again, it needs to access the disk to read the 16KB data block, which also consumes 1ms more time. If a 4KB data block is replaced in the cache and then a 4KB data block is replaced, the cache system needs to replace a 4KB data block in the cache again. Similarly, a 4KB data block in the cache will also be randomly selected for swapping out. If the next time the database or storage system needs to read the 4KB data block that has been swapped out, it will also take 1ms more time. By analogy, each time the database or storage system needs to read the data that has been swapped out, it will generally take 1ms more time, and the cache system will free up 4KB of cache space. However, there is a better solution: if the 16KB data block in the cache is swapped out first, the database or storage system will only need to spend 1ms more time when it needs to read the 16KB data block that has been swapped out. However, the cache can free up 16KB of cache space. This 16KB cache space can cache more 4KB data blocks with similar access popularity, greatly improving the cache utilization and reducing the time cost of the database or storage system accessing the disk. It can be seen that the highest hit rate of data pages does not mean that the database or storage system has the lowest time cost of accessing the disk.
[0030] Based on the above explanation that the highest hit rate of data pages does not mean that the time cost of the database or storage system accessing the disk is the lowest, an embodiment of the present application proposes a data caching method. By introducing the time cost saved by avoiding the database or storage system accessing the disk, the database or storage system can make full use of the cache space and effectively reduce the time cost of the database or storage system accessing the disk, thereby effectively improving the data throughput of the database or storage system and effectively reducing the data delay of the database or storage system.
[0031] It should be noted that the data caching method provided in Example 1 of the present application is based on the following assumption: the granularity at which the data blocks in the cache are accessed will not change over time. For example, if a data block is accessed in units of 16KB, it will always be accessed in units of 16KB. If another data block is accessed in units of 4KB, then similarly, it will always be accessed in units of 4KB. In actual applications, this assumption has certain application scenarios. For example, data blocks storing user data are accessed in a fixed size of 4KB, while metadata in the database is accessed in another size that does not change. For another example, the SSTable table in the LevelDB database and RocksDB database, which are now widely used, contains data blocks and metadata. In point-to-point read operations, data blocks of user data are accessed in a fixed size such as 4KB, and metadata is also read out in full in a fixed size. The data caching method provided in Example 1 of the present application is described in detail below:
[0032] Reference Figure 1 , shows a step flow chart of the data caching method of embodiment 1 of the present application.
[0033] Specifically, the data caching method of this embodiment includes the following steps:
[0034] In step S101, based on block information of a first data block in a cache, the time saved by the first data block in avoiding a database or storage system from accessing a disk is determined.
[0035] In an embodiment of the present application, the first data block in the cache maintains block information. The block information includes at least one of the following: the size of the first data block, the access frequency of the first data block in the cache, and the access time of the first data block in the disk. Among them, the access frequency can be understood as the number of times the first data block is accessed in the cache per unit time. The access time can be understood as the time required for the database or storage system to read the first data block once in the disk. The time saved by the first data block to avoid the database or storage system accessing the disk can be understood as the fact that since the first data block is stored in the cache, the database or storage system does not need to access the disk to read the first data block, thereby saving the time for the database or storage system to access the disk. It can be understood that the above description is only exemplary, and the embodiment of the present application does not impose any limitation on this.
[0036] In some optional embodiments, when the block information includes the access frequency of the first data block in the cache and the access time of the first data block in the disk, the determination of the time saved by the first data block to avoid the database or storage system accessing the disk based on the block information of the first data block in the cache includes: calculating the time saved by the first data block to avoid the database or the storage system accessing the disk based on the access frequency and the access time of the first data block in the cache. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0037] In a specific example, when calculating the time saved by the first data block to avoid the database or the storage system accessing the disk, the multiplication result of the access frequency of the first data block in the cache and the access time of the first data block in the cache is calculated; and the multiplication result is determined as the time saved by the first data block to avoid the database or the storage system accessing the disk. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0038] In some optional embodiments, when the block information includes the access frequency of the first data block in the cache, the access time of the first data block in the disk, and the size of the first data block, the calculation of the time saved by the first data block to avoid the database or the storage system accessing the disk based on the access frequency and the access time of the first data block in the cache includes: calculating the average time saved by the data pages in the first data block to avoid the database or the storage system accessing the disk based on the size, the access frequency, and the access time of the first data block in the cache. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0039] In a specific example, when calculating the average time saved by the data pages in the first data block to avoid the database or the storage system accessing the disk, the time saved by the first data block to avoid the database or the storage system accessing the disk is calculated based on the access frequency and the access time of the first data block in the cache; the size of the first data block is divided by the size of the data page to obtain the number of data pages contained in the first data block; the time saved by the first data block to avoid the database or the storage system accessing the disk is divided by the number of data pages contained in the first data block to obtain the average time saved by the data pages in the first data block to avoid the database or the storage system accessing the disk. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0040] In step S102, based on the time, a second data block to be replaced from the cache is determined.
[0041] In some optional embodiments, when determining the second data block to be replaced from the cache based on the time, the first data block with the shortest time is determined as the second data block to be replaced from the cache. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0042] In a specific example, as shown in Table 1, there are currently six data blocks in the cache, and the size of each data block may be different.
[0043] Block size (Si) 4KB 4KB 4KB 16KB 16KB 64KB Access frequency (Fi) 5 20 40 40 160 320 Time required to access the disk once (Ti) 1.0 1.0 1.0 1.1 1.1 1.3 The time cost saved by swapping into the cache (Fi*Ti) 5 20 40 44 176 384 Average time saved per page (Fi*Ti / (Si / 4KB)) 5 20 40 11 44 26
[0044] Table 1
[0045] When selecting the data block to be replaced in the cache, first calculate the time saved by the data block in the cache to avoid the database or storage system accessing the disk, which is Fi*Ti. Then, calculate the average time saved by each data page in the data block for the database or storage system to access the disk, which is Fi*Ti / (Si / 4KB). Finally, select the data block with the smallest "average time saved by each data page in the data block for the database or storage system to access the disk" for replacement. As shown in Table 1, the first data block to be replaced is the first data block of size 4KB, and the average time saved by its data page for the database or storage system to access the disk is 5; the second data block that needs to be replaced is the first data block of size 16KB, and the average time saved by its data page for the database or storage system to access the disk is 11. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0046] In step S103, data is cached based on the cache space of the replaced second data block.
[0047] In the embodiment of the present application, the cache system caches related data based on the cache space of the second data block that is replaced, such as user data, metadata, etc. It is understandable that the above description is only exemplary and the embodiment of the present application does not impose any limitation on this.
[0048] In actual applications, the data caching method provided in the first embodiment of the present application organizes access information in units of accessed data blocks, rather than organizing access information in units of fixed data page sizes like the existing caching methods, and at the same time binds the time cost saved to avoid the database or storage system accessing the disk to the data block, and replaces the data block with the data page that saves the least average time for the database or storage system to access the disk. In the specific implementation process, a sorted array is maintained, and each element of the sorted array stores a pointer to the actual data block, the access frequency of the data block in the cache, and the access time of the data block in the disk. If the data block in the cache needs to be replaced, the data block with the least average time saved for the data page to access the disk by the database or storage system can be replaced. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitations on this.
[0049] Through the data caching method provided in the embodiment of the present application, based on the block information of the first data block in the cache, the time saved by the first data block to avoid the database or storage system accessing the disk is determined; based on the time, the second data block to be replaced from the cache is determined; and data is cached based on the cache space of the second data block to be replaced. Compared with the existing LRU scheme or LFU scheme, the second data block to be replaced from the cache is determined based on the time saved by the first data block to avoid the database or storage system accessing the disk, and data is cached based on the cache space of the second data block to be replaced, so that the database or storage system can make full use of the cache space and effectively reduce the time cost of the database or storage system accessing the disk, thereby not only effectively improving the data throughput of the database or storage system, but also effectively reducing the data delay of the database or storage system.
[0050] The data caching method of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted devices, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, Gear VR), etc.
[0051] It should be noted that the data caching method provided in Example 1 of the present application is based on the following assumption: the granularity at which the data blocks in the cache are accessed will not change over time. Therefore, the data caching method provided in Example 1 of the present application has certain application scenarios, but is still not general enough. In many application scenarios, the size of a data block accessed will still change over time. For example, a data block of size 64KB is accessed at a granularity of 64KB for part of the time, and is accessed multiple times at a granularity of 4KB for another part of the time. In order not to be bound by the above assumptions and to make the data caching method more general, Example 2 of the present application further proposes a data caching method. The data caching method provided in Example 2 of the present application is described in detail below:
[0052] Reference Figure 2A , shows a step flow chart of the data caching method of embodiment 2 of the present application.
[0053] Specifically, the data caching method of this embodiment includes the following steps:
[0054] In step S201, based on page information of a first data page in a cache, the time saved by the first data page in order to avoid a database or storage system from accessing a disk is determined.
[0055] In an embodiment of the present application, the page information includes a plurality of pointers for pointing to a data block containing the first data page. The time saved by the first data page to avoid the database or storage system from accessing the disk can be understood as the first data page is stored in the cache, so the database or storage system does not need to access the disk to read the first data page, thereby saving the time of the database or storage system accessing the disk. It can be understood that the above description is only exemplary, and the embodiment of the present application does not impose any limitation on this.
[0056] In some optional embodiments, when determining the time saved by the first data page to avoid the database or storage system accessing the disk based on the page information of the first data page in the cache, the time saved by the first data page to avoid the database or the storage system accessing the disk is determined based on the average time saved by the third data page in the data block pointed to by the multiple pointers to avoid the database or the storage system accessing the disk. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0057] In a specific example, when determining the time saved by the first data page to avoid the database or the storage system accessing the disk, the average time saved by the third data pages in the data blocks pointed to by the multiple pointers to avoid the database or the storage system accessing the disk is added to obtain the time saved by the first data page to avoid the database or the storage system accessing the disk. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0058] In some optional embodiments, before determining the time saved by the first data page to avoid the database or the storage system accessing the disk based on the average time saved by the third data page in the data block pointed to by the multiple pointers, the method further includes: determining the average time saved by the third data page in the data block to avoid the database or the storage system accessing the disk based on the block information of the data block. The block information includes at least one of the following: the access frequency of the data block in the cache, the access time of the data block in the disk, and the size of the data block. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0059] In a specific example, when determining the average time saved by the third data page in the data block to avoid the database or the storage system accessing the disk, the average time saved by the third data page in the data block to avoid the database or the storage system accessing the disk is calculated based on the access frequency of the data block in the cache, the access time of the data block in the disk, and the size of the data block. Among them, the specific implementation method of calculating the average time saved by the third data page in the data block to avoid the database or the storage system accessing the disk is similar to the specific implementation method of calculating the average time saved by the data page in the first data block to avoid the database or the storage system accessing the disk in the above-mentioned embodiment 1, and will not be repeated here. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0060] In a specific example, when a data block is read into the cache, it is cached in units of data pages (assuming the size is 4KB), but the block information for accessing the data block is still retained. Figure 2BAs shown, there are a total of 7 data pages in the cache at the current moment, which have been accessed by five access modes: the first access mode is to continuously access data page 1, data page 2, data page 3, and data page 4; the second access mode is to continuously access data page 3, data page 4, and data page 5; the third access mode is to continuously access data page 3, data page 4, data page 5, and data page 6; the fourth access mode is to access data page 6; and the fifth access mode is to access data page 7. Each access mode corresponds to a data block. Specifically, the first access mode corresponds to a data block composed of data page 1, data page 2, data page 3, and data page 4, the second access mode corresponds to a data block composed of data page 3, data page 4, and data page 5, the third access mode corresponds to a data block composed of data page 3, data page 4, data page 5, and data page 6, the fourth access mode corresponds to a data block composed of data page 6, and the fifth access mode corresponds to a data block composed of data page 7. Each data block records three parameters: the access frequency of the data block in the cache, the access time of the data block in the disk, and the size of the data block. The information maintained by each data page includes multiple pointers, each pointer pointing to the data block containing the data page. The time saved by each data page in the data block to avoid the database or the storage system accessing the disk is the sum of the average time saved by the third data page in all data blocks pointed to by the pointer to avoid the database or the storage system accessing the disk. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0061] In step S202, based on the time, a second data page to be replaced from the cache is determined.
[0062] In some optional embodiments, when determining the second data page to be replaced from the cache based on the time, the first data page with the shortest time is determined as the second data page to be replaced from the cache. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0063] In step S203, data is cached based on the cache space of the second data page that is replaced.
[0064] In the embodiment of the present application, the cache system caches relevant data based on the cache space of the second data page that is replaced, such as user data, metadata, etc. It is understandable that the above description is only exemplary and the embodiment of the present application does not impose any limitation on this.
[0065] In some optional embodiments, after determining the second data page to be replaced from the cache based on the time, the method further includes: deleting the access mode corresponding to the data block pointed to by the multiple pointers of the second data page to be replaced. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0066] In a specific example, when a data page needs to be selected in the cache for swapping out, the data page that saves the least time to avoid the database or storage system from accessing the disk is selected for swapping out, and the access modes corresponding to the data blocks pointed to by multiple pointers of the data page are deleted at the same time after swapping out. For example, when data page 1 is swapped out in the cache, the data pages and access modes still contained in the cache are as follows: Figure 2C As another example, when data page 6 is replaced in the cache, the cache still contains data pages and access patterns, such as Figure 2D As shown. In this way, when a data page needs to be swapped out next time, the data page that belongs to the same access mode as the data page swapped out last time has a greater probability of being swapped out. Therefore, it takes into account the advantages of using the accessed data block as the unit, which can fully reduce the time cost of the database or storage system accessing the disk, and is not constrained by the assumption that "the granularity of a certain data block being accessed will not change over time." It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0067] Through the data caching method provided in the embodiment of the present application, based on the page information of the first data page in the cache, the time saved by the first data page to avoid the database or storage system accessing the disk is determined; based on the time, the second data page to be replaced from the cache is determined; based on the cache space of the second data page to be replaced, data is cached. Compared with the existing LRU scheme or LFU scheme, based on the time saved by the first data page to avoid the database or storage system accessing the disk, the second data page to be replaced from the cache is determined, and data is cached based on the cache space of the second data page to be replaced, so that the database or storage system can make full use of the cache space and effectively reduce the time cost of the database or storage system accessing the disk, thereby not only effectively improving the data throughput of the database or storage system, but also effectively reducing the data delay of the database or storage system.
[0068] The data caching method of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted devices, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, Gear VR), etc.
[0069] Reference Figure 3 , shows a schematic diagram of the structure of the data cache device in Example 3 of the present application.
[0070] The data caching device of this embodiment includes: a first determination module 301, which is used to determine the time saved by the first data block in the cache to avoid the database or storage system accessing the disk based on the block information of the first data block; a second determination module 302, which is used to determine the second data block to be replaced from the cache based on the time; and a first cache module 303, which is used to cache data based on the cache space of the second data block to be replaced.
[0071] The data caching device of this embodiment is used to implement the corresponding data caching methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0072] Reference Figure 4 , shows a schematic diagram of the structure of the data cache device in Example 4 of the present application.
[0073] The data caching device of this embodiment includes: a first determination module 401, which is used to determine the time saved by the first data block in the cache to avoid the database or storage system accessing the disk based on the block information of the first data block; a second determination module 402, which is used to determine the second data block to be replaced from the cache based on the time; and a first cache module 403, which is used to cache data based on the cache space of the second data block to be replaced.
[0074] Optionally, the block information includes an access frequency of the first data block in the cache and an access time of the first data block in the disk, and the first determination module 401 includes: a first determination submodule 4011, used to calculate the time saved by the first data block to avoid the database or the storage system accessing the disk based on the access frequency and the access time of the first data block in the cache.
[0075] Optionally, the block information also includes the size of the first data block, and the first determination submodule 4011 includes: a determination unit 4012, used to calculate the average time saved by the data pages in the first data block to avoid the database or the storage system accessing the disk based on the size of the first data block in the cache, the access frequency and the access time.
[0076] Optionally, the second determining module 402 is specifically configured to determine that the first data block with the shortest time is the second data block to be replaced from the cache.
[0077] The data caching device of this embodiment is used to implement the corresponding data caching methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0078] Reference Figure 5 , shows a schematic diagram of the structure of the data cache device in Example 5 of the present application.
[0079] The data caching device of this embodiment includes: a third determination module 501, used to determine the time saved by the first data page in the cache to avoid the database or storage system accessing the disk based on the page information of the first data page; a fourth determination module 502, used to determine the second data page to be replaced from the cache based on the time; a second cache module 503, used to cache data based on the cache space of the second data page to be replaced.
[0080] The data caching device of this embodiment is used to implement the corresponding data caching methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0081] Reference Figure 6 , shows a schematic diagram of the structure of the data cache device in Example 6 of the present application.
[0082] The data caching device of this embodiment includes: a third determination module 601, which is used to determine the time saved by the first data page in the cache to avoid the database or storage system accessing the disk based on the page information of the first data page; a fourth determination module 602, which is used to determine the second data page to be replaced from the cache based on the time; and a second cache module 603, which is used to cache data based on the cache space of the second data page to be replaced.
[0083] Optionally, the page information includes multiple pointers for pointing to data blocks containing the first data page, and the third determination module 601 includes: a second determination sub-module 6012, used to determine the time saved by the first data page to avoid the database or the storage system accessing the disk based on the average time saved by the third data page in the data blocks pointed to by the multiple pointers to avoid the database or the storage system accessing the disk.
[0084] Optionally, before the second determination submodule 6012, the third determination module 601 also includes: a third determination submodule 6011, used to determine the average time saved by the third data page in the data block to avoid the database or the storage system accessing the disk based on the block information of the data block.
[0085] Optionally, the block information includes at least one of the following: an access frequency of the data block in the cache, an access time of the data block in the disk, and a size of the data block.
[0086] Optionally, the fourth determination module 602 is specifically configured to: determine that the first data page with the shortest time is the second data page to be replaced from the cache.
[0087] Optionally, after the fourth determining module 602, the device further includes: a deleting module 604, configured to delete the access mode corresponding to the data blocks pointed to by the multiple pointers of the replaced second data page.
[0088] The data caching device of this embodiment is used to implement the corresponding data caching methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0089] Figure 7 This is a schematic diagram of the structure of an electronic device in Embodiment 7 of the present application; the electronic device may include:
[0090] One or more processors 701;
[0091] The computer readable medium 702 may be configured to store one or more programs,
[0092] When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method as described in the above-mentioned embodiment 1 or embodiment 2.
[0093] Figure 8 The hardware structure of the electronic device in the eighth embodiment of the present application; Figure 8As shown, the hardware structure of the electronic device may include: a processor 801, a communication interface 802, a computer readable medium 803 and a communication bus 804;
[0094] The processor 801, the communication interface 802, and the computer readable medium 803 communicate with each other via a communication bus 804;
[0095] Optionally, the communication interface 802 may be an interface of a communication module, such as an interface of a GSM module;
[0096] The processor 801 can be specifically configured to: determine the time saved by the first data block in the cache to avoid the database or storage system from accessing the disk based on the block information of the first data block in the cache; determine the second data block to be replaced from the cache based on the time; and cache data based on the cache space of the second data block that was replaced. In addition, the processor 801 can also be configured to: determine the time saved by the first data page in the cache to avoid the database or storage system from accessing the disk based on the page information of the first data page in the cache; determine the second data page to be replaced from the cache based on the time; and cache data based on the cache space of the second data page that was replaced.
[0097] The processor 801 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0098] The computer readable medium 803 can be, but is not limited to, a random access memory medium (RAM), a read-only memory medium (ROM), a programmable read-only memory medium (PROM), an erasable read-only memory medium (EPROM), an electrically erasable read-only memory medium (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0099] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code configured to execute the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through a communication part, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), the above functions defined in the method of the present application are executed. It should be noted that the computer-readable medium described in the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access storage medium (RAM), a read-only storage medium (ROM), an erasable programmable read-only storage medium (EPROM or flash memory), an optical fiber, a portable compact disk read-only storage medium (CD-ROM), an optical storage medium, a magnetic storage medium, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, an apparatus or a device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program configured to be used by or in combination with an instruction execution system, an apparatus or a device. The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0100] Computer program code configured to perform the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0101] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment, or a part of a code, and the module, program segment, or a part of the code contains one or more executable instructions configured to implement the specified logical function. There are specific sequential relationships in the above-mentioned specific embodiments, but these sequential relationships are only exemplary. When the specific implementation is implemented, these steps may be less, more, or the execution order may be adjusted. That is, in some implementations as replacements, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0102] The modules involved in the embodiments described in the present application may be implemented by software or by hardware. The modules described may also be set in a processor, for example, may be described as: a processor includes a first determination module, a second determination module and a first cache module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the first determination module may also be described as "a module for determining the time saved by the first data block in the cache to avoid the database or storage system accessing the disk based on the block information of the first data block".
[0103] As another aspect, the present application further provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the data caching method described in the first or second embodiment above is implemented.
[0104] As another aspect, the present application also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by the device, the device: determines the time saved by the first data block to avoid the database or storage system accessing the disk based on the block information of the first data block in the cache; determines the second data block to be replaced from the cache based on the time; and caches data based on the cache space of the second data block to be replaced. In addition, the device can also: determine the time saved by the first data page to avoid the database or storage system accessing the disk based on the page information of the first data page in the cache; determines the second data page to be replaced from the cache based on the time; and caches data based on the cache space of the second data page to be replaced.
[0105] The expressions "first", "second", "the first" or "the second" used in various embodiments of the present disclosure may modify various components regardless of order and / or importance, but these expressions do not limit the corresponding components. The above expressions are only configured for the purpose of distinguishing an element from other elements. For example, a first user device and a second user device represent different user devices, although both are user devices. For example, a first element may be referred to as a second element, and similarly, a second element may be referred to as a first element without departing from the scope of the present disclosure.
[0106] When one element (e.g., a first element) is referred to as being "(operably or communicatively) coupled" or "(operably or communicatively) coupled to" or "connected to" another element (e.g., a second element), it is understood that the one element is directly connected to the other element or the one element is indirectly connected to the other element via yet another element (e.g., a third element). Conversely, it is understood that when an element (e.g., a first element) is referred to as being "directly connected" or "directly coupled" to another element (the second element), no element (e.g., a third element) is interposed between the two.
[0107] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A data caching method, characterized in that: The method comprises: Determining, based on block information of the first data block in the cache, time saved by the first data block for avoiding a database or storage system from accessing a disk; Based on the time, determining the first data block with the shortest time as the second data block to be replaced from the cache; caching data based on the cache space of the second data block that is replaced; The block information includes an access frequency of the first data block in the cache and an access time of the first data block in the disk; The determining, based on the block information of the first data block in the cache, the time saved by the first data block in order to avoid the database or storage system from accessing the disk comprises: The time saved by the first data block for avoiding the database or the storage system from accessing the disk is calculated based on the product of the access frequency and the access time of the first data block in the cache.
2. The method according to claim 1, characterized in that The block information also includes the size of the first data block, The calculating, based on the access frequency and the access time of the first data block in the cache, the time saved by the first data block in order to avoid the database or the storage system accessing the disk comprises: Based on the size of the first data block in the cache, the access frequency, and the access time, an average time saved by data pages in the first data block for avoiding the database or the storage system from accessing the disk is calculated.
3. A data caching method, characterized in that: The method comprises: Determine, based on page information of the first data page in the cache, time saved by the first data page in order to avoid a database or storage system from accessing a disk; Based on the time, determining the first data page with the shortest time as the second data page to be replaced from the cache; caching data based on the cache space of the second data page that is replaced; The page information includes a plurality of pointers for pointing to data blocks including the first data page; The determining, based on the page information of the first data page in the cache, the time saved by the first data page in order to avoid the database or storage system from accessing the disk comprises: The time saved by the first data page in avoiding the database or the storage system from accessing the disk is determined based on the average time saved by the third data page in the data blocks pointed to by the multiple pointers in avoiding the database or the storage system from accessing the disk.
4. The method according to claim 3, characterized in that Before determining the time saved by the first data page for avoiding the database or the storage system from accessing the disk based on the average time saved by the third data page in the data blocks pointed to by the multiple pointers for avoiding the database or the storage system from accessing the disk, the method further comprises: The average time saved by the third data page in the data block to avoid the database or the storage system from accessing the disk is determined based on the block information of the data block.
5. The method according to claim 4, characterized in that The block information includes at least one of the following: The access frequency of the data block in the cache, the access time of the data block in the disk, and the size of the data block.
6. The method according to any one of claims 3 to 5, characterized in that: After determining the second data page to be replaced from the cache based on the time, the method further includes: The access mode corresponding to the data blocks pointed to by the multiple pointers of the replaced second data page is deleted.
7. A data cache device, characterized in that: The device comprises: A first determination module, configured to determine, based on block information of a first data block in a cache, time saved by the first data block in order to avoid a database or storage system from accessing a disk; A second determining module, configured to determine, based on the time, that the first data block with the shortest time is a second data block to be replaced from the cache; A first cache module, configured to cache data based on the cache space of the second data block that is replaced; The block information includes an access frequency of the first data block in the cache and an access time of the first data block in the disk; The first determining module includes: The first determining submodule is used to calculate the time saved by the first data block to avoid the database or the storage system accessing the disk based on the product of the access frequency and the access time of the first data block in the cache.
8. The device according to claim 7, characterized in that The block information also includes the size of the first data block, The first determining submodule includes: A determination unit is configured to calculate, based on the size of the first data block in the cache, the access frequency, and the access time, an average time saved by data pages in the first data block to avoid the database or the storage system accessing the disk.
9. A data cache device, characterized in that: The device comprises: A third determination module, configured to determine, based on the page information of the first data page in the cache, the time saved by the first data page in order to avoid the database or storage system from accessing the disk; A fourth determining module, configured to determine, based on the time, that the first data page with the shortest time is the second data page to be replaced from the cache; A second cache module, used for caching data based on the cache space of the second data page that is replaced; The page information includes a plurality of pointers for pointing to data blocks including the first data page; The third determining module comprises: The second determination submodule is used to determine the time saved by the first data page to avoid the database or the storage system accessing the disk based on the average time saved by the third data page in the data blocks pointed to by multiple pointers to avoid the database or the storage system accessing the disk.
10. The device according to claim 9, characterized in that Before the second determination submodule, the third determination module further includes: The third determining submodule is used to determine, based on the block information of the data block, the average time saved by the third data page in the data block to avoid the database or the storage system accessing the disk.
11. The device according to claim 10, characterized in that The block information includes at least one of the following: The access frequency of the data block in the cache, the access time of the data block in the disk, and the size of the data block.
12. The device according to any one of claims 9 to 11, characterized in that: After the fourth determining module, the device further includes: The deletion module is used to delete the access mode corresponding to the data block pointed to by the multiple pointers of the second data page that is replaced.
13. An electronic device comprising: one or more processors; A computer readable medium configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method as described in any one of claims 1 to 2, or implement the data caching method as described in any one of claims 3 to 6.
14. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the data caching method as described in any one of claims 1 to 2, or implements the data caching method as described in any one of claims 3 to 6.
Citation Information
Patent Citations
HDFS small file cache management method based on ARC replacement algorithm
CN107368608A
Cache control device and cache control method
JP2013174997A