Data reading and writing method, device, equipment and computer-readable storage medium

By hierarchically processing the cache pool and efficiently managing cache blocks, the problems of low cache space utilization and reuse rate are solved, and efficient use of cache space and improvement of middleware performance are achieved.

CN119248198BActive Publication Date: 2025-09-26INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411379824.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-09-26
Estimated Expiration
2044-09-30

AI Technical Summary

Technical Problem

In the existing technology, cache space utilization and reuse rates are low, resulting in cache space waste and low cache block recovery efficiency. Especially in mixed read and write scenarios, the fixed-length cache block design makes cache block reuse difficult and wastes space.

Method used

By hierarchically processing the cache pool, different levels of sub-cache pools are divided according to the capacity of the cache data, and the target sub-cache pool and cache block are determined according to the capacity of the message, the message is written to the corresponding cache block, and the cache block is released according to the reading situation to achieve efficient reuse of the cache block.

Benefits of technology

It improves the utilization and reuse rate of cache space, simplifies the cache block recovery process, avoids the situation where cache blocks store multiple messages, and improves the performance of the middleware.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248198B_ABST
    Figure CN119248198B_ABST
Patent Text Reader

Abstract

The present invention discloses a data reading and writing method, apparatus, device, and computer-readable storage medium, applicable to the field of data caching. The method comprises: determining the target sub-cache pool corresponding to each message in the cached data based on the capacity of each message; determining the target cache block corresponding to each message based on the capacity of the cache block in the target sub-cache pool; and writing each message into the target cache block; determining the released cache block based on the reading status of the message, and placing the released cache block into the sub-cache pool of the corresponding level. The present invention solves the problems of low cache space utilization and reuse rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data caching, and in particular to a data reading and writing method, device, equipment and computer-readable storage medium. Background Art

[0002] The rapid development of computer and network technologies has led to higher demands on memory capacity. In extreme scenarios involving continuous mixed reading and writing of large amounts of data, the capacity of the cache pool consisting of direct memory and persistent memory is relatively limited compared to the size of the messages being written. Therefore, the cache is inevitably reused during subsequent writes and reads.

[0003] Because cache speed and latency are far superior to those of solid-state drives (SSDs), it's crucial to fully utilize the limited cache space. Therefore, improving cache utilization and reuse is a pressing issue. Summary of the Invention

[0004] In view of this, an object of the present invention is to provide a data reading and writing method, apparatus, device and computer-readable storage medium, which solve the problem of poor cache space utilization and reuse rate in the prior art.

[0005] To solve the above technical problems, the present invention provides a data reading and writing method, comprising:

[0006] Determine the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, determine the target cache block corresponding to each message according to the capacity of the cache block in the target sub-cache pool, and write each message into the target cache block corresponding to each message;

[0007] The released cache blocks are determined according to the reading situation of the messages, and the released cache blocks are placed in the sub-cache pool of the corresponding level.

[0008] On the one hand, before determining the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, the following steps are also included:

[0009] Determining the number of division levels according to the capacity of the cache data and the capacity of the cache pool;

[0010] Divide the cache pool according to the number of division levels to obtain sub-cache pools at each level;

[0011] The sub-cache pools of each level are divided according to the capacity of each message in the cache data to obtain cache blocks.

[0012] On the one hand, before determining the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, the method further includes:

[0013] When the capacity of the cached data is greater than the free space capacity of the cache pool, the cached data is filtered to obtain filtered messages;

[0014] Accordingly, determining the target sub-cache pool corresponding to each message in the cache data according to its capacity includes:

[0015] The corresponding target sub-buffer pool is determined according to the capacity of each filtered message.

[0016] On the one hand, the cache pool includes direct memory and persistent memory, and both the direct memory and the persistent memory contain sub-cache pools of multiple levels. The cache priority of the direct memory is higher than that of the persistent memory.

[0017] On the one hand, it also includes:

[0018] Get the free capacity of the cache pool at the current moment in real time;

[0019] Calculating a cache rate based on the free capacity of the cache pool at the current moment and the capacity of the cached data;

[0020] The read and write efficiency is determined according to the cache rate.

[0021] On the one hand, determining the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, determining the target cache block corresponding to each message according to the capacity of the cache block in the target sub-cache pool, and writing each message into the target cache block corresponding to each message includes:

[0022] Determine the capacity of the current message; the current message is each of the messages;

[0023] Determining an initial sub-buffer pool according to the capacity of the current message; the initial sub-buffer pool includes cache blocks larger than the capacity of the current message and also includes cache blocks smaller than or equal to the capacity of the current message;

[0024] If the initial sub-cache pool is the highest-level sub-cache pool and there are free cache blocks in the highest-level sub-cache pool, the free cache blocks are filled with the current message, and excess data in the current message that is not written into the free cache blocks is written into other memory; the highest-level sub-cache pool is the sub-cache pool with the largest cache space;

[0025] If the initial sub-cache pool is not the highest-level sub-cache pool, the sub-cache pool at the previous level of the initial sub-cache pool is used as the target sub-cache pool, and the current message is written into the free cache block with the smallest space in the target sub-cache pool.

[0026] On the one hand, the cache blocks to be released are determined based on the message reading situation, including:

[0027] When the read message is the Nth message in the message queue, the cache blocks occupied by the first N-1 messages in the message queue are released;

[0028] Record the number of times each message topic is read in real time, and determine the message topic with 0 message read times within a preset time period as a topic to be released;

[0029] Release the cache blocks where all messages under the subject to be released are located.

[0030] The present invention also provides a data reading and writing device, comprising:

[0031] a writing module, configured to determine a corresponding target sub-cache pool according to the capacity of each message in the cache data, determine a corresponding target cache block according to the capacity of the cache block in the corresponding target sub-cache pool, and write each message into the corresponding target cache block;

[0032] The reading module is used to determine the released cache blocks according to the reading situation of the message, and place the released cache blocks in the sub-cache pool of the corresponding level.

[0033] The present invention also provides a data reading and writing device, comprising:

[0034] Memory for storing computer programs;

[0035] A processor is used to implement the steps of the above-mentioned data reading and writing method when executing the computer program.

[0036] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data reading and writing method described above are implemented.

[0037] The present invention also provides a computer program product, comprising a computer program / instruction, which implements the steps of the data reading and writing method described in the claims when executed by a processor.

[0038] As can be seen from the above technical solution, the target sub-cache pool corresponding to each message in the cache data is determined according to the capacity of the cache block in the target sub-cache pool, and the target cache block corresponding to each message is determined according to the capacity of the cache block in the target sub-cache pool. Each message is written into the target cache block corresponding to each message; the released cache block is determined according to the reading situation of the message, and the released cache block is placed in the sub-cache pool of the corresponding level. The beneficial effect of the present invention is that by pre-dividing the cache pool, the cache blocks are graded according to the capacity, and the sub-cache pools of different levels store cache blocks of a certain size space range. In this way, when writing a message, it can be written into the cache block of the corresponding sub-cache pool, without wasting cache space. When reading a message, the cache space can be released in time, thereby improving the reuse rate of the cache pool. This further allows the reading and writing of middleware messages to make greater use of the cache, thereby improving the performance of the middleware.

[0039] In addition, the present invention also provides a data reading and writing device, equipment and computer-readable storage medium, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0041] Figure 1 A schematic diagram of a logical address of a message;

[0042] Figure 2 A partition diagram of an existing data cache block;

[0043] Figure 3 A flowchart of a data reading and writing method provided by an embodiment of the present invention;

[0044] Figure 4 A schematic diagram of a hierarchical cache pool provided by an embodiment of the present invention;

[0045] Figure 5 A schematic diagram of data reading and writing provided by an embodiment of the present invention;

[0046] Figure 6 A schematic diagram of a message writing method provided by an embodiment of the present invention;

[0047] Figure 7 A schematic diagram of a cache block release provided by an embodiment of the present invention;

[0048] Figure 8A schematic structural diagram of a data reading and writing device provided by an embodiment of the present invention;

[0049] Figure 9 A schematic structural diagram of a data reading and writing device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0050] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0051] The message itself is designed with attributes such as topic, queue number (queueId), offset, etc. Topic refers to a collection of messages of the same type, and Queue is the physical entity that stores messages. A Topic can contain multiple Queues, each Queue has its own ID number, namely queueId, and each Queue stores multiple messages of the Topic. The unique Queue is determined by Topic and queueId. Each Queue stores multiple messages, and the specific message is determined by offset. Queue is a two-dimensional array. Once the topic and queueId are determined, the unique queue can be determined. What is stored in the queue is not individual messages, but the index of each message. The offset can be used to uniquely determine the index of the message, so that the message can be found. The logical address of the message is as follows Figure 1 As shown in the figure, each topic has multiple queues, and each queue has its own queueId. After uniquely identifying the queue through the topic and queueId, the specific message in the queue is found based on the offset.

[0052] With the rapid development of computing and networking technologies, in extreme scenarios involving continuous, mixed read and write of large amounts of data, the capacity of the cache pool comprised of direct memory (DRAM) and persistent memory (PMem) is relatively limited compared to the size of the messages being written. Consequently, messages will inevitably reuse the cache during subsequent writes and reads. Because cache speed and latency far surpass those of SSDs, it's crucial to fully utilize the limited cache, maximizing cache pool utilization and reuse. This allows middleware message reads and writes to utilize more cache memory, improving middleware performance. Message-based middleware is a software system based on queuing and messaging technologies that provides synchronous or asynchronous, reliable message transmission for application systems in a network environment.

[0053] Current cache block designs typically use fixed-length cache blocks, which divide the cache block granularity into specific sizes. Each queue has a linked list of cache blocks, which are used to store multiple messages under this topic and queueId. However, the current fixed-length cache block design introduces the following issues:

[0054] (1) Cache block recycling becomes complicated and inefficient. Figure 2 The large outer block represents the cache block, which is of fixed size. The inner leftmost block represents the message that has been read, and the remaining inner blocks represent the messages that have not been read. Since the recycling strategy of the message middleware is that the cache containing the messages that have been read can be recycled for reuse, if a fixed-length cache block design is adopted, because the size of the message is non-fixed and random, this will cause a cache block to store multiple messages. Since the current cache block stores part of the unread message, the current cache block cannot be released in time for cache block recycling. During recycling, it is necessary to simultaneously determine whether all messages in the current cache block have been read, making the recycling mechanism more complicated and inefficient.

[0055] (2) Increased coding complexity and difficulty. Since a cache block stores multiple messages, more indexes are required to maintain the message status of each cache block, which will greatly increase the difficulty of code writing and the complexity of maintenance.

[0056] (3) The last cache block in the linked list of the same queue has low utilization. A pair of topic and queueId can identify a unique queue. Each queue maintains a linked list of cache blocks to store these messages. However, due to the fixed-length cache block design, the last cache block in the linked list has low utilization, resulting in wasted space.

[0057] To address these issues, this paper designs a cache (data read / write) solution that improves cache reuse and fully utilizes cache space. It also simplifies cache block recycling, preventing the storage of multiple messages in the same cache block, making message index maintenance simpler and more efficient. It also eliminates the space waste associated with the last cache block in the linked list. This method classifies cache blocks by capacity. Cache pools of different levels store cache blocks of a certain size range. This ensures that when a cache block is reused, it can be retrieved from the corresponding sub-cache pool, further improving cache block reuse efficiency.

[0058] Please refer to Figure 3 , Figure 3 This is a flow chart of a data reading and writing method provided by an embodiment of the present invention. The method may include:

[0059] S101: Determine the corresponding target sub-cache pool according to the capacity of each message in the cache data, determine the corresponding target cache block according to the capacity of the cache block in the corresponding target sub-cache pool, and write each message into the corresponding target cache block.

[0060] In this embodiment, the cached data includes a large number of messages. When writing messages to the cache pool, the size of the cached data and the capacity of the cache pool need to be considered. First, the target sub-cache pool is determined based on the size of each message in the cached data. Then, the target cache block is determined based on the capacity of the cache blocks in the target sub-cache pool. It will be appreciated that the target cache block is the smallest cache block capable of writing the message. This avoids space waste caused by storing messages across multiple blocks and also prevents cache block reclaim difficulties caused by multiple messages stored in a single cache block.

[0061] Furthermore, in order to improve the utilization of the cache space, before determining the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, the following steps may be further included:

[0062] Step 21: Determine the number of division levels according to the capacity of the cache data and the capacity of the cache pool;

[0063] Step 22: Divide the cache pool according to the number of division levels to obtain sub-cache pools at each level;

[0064] Step 23: Divide the sub-cache pools of each level according to the capacity of each message in the cache data to obtain each cache block.

[0065] This embodiment divides the cache pool into sub-cache pools with different capacities. Such hierarchical division can make full use of the limited cache space. To better understand the above steps, please refer to Figure 4. For example, if the message capacity in the cache data is between 0-20KB, the cache pool can be divided into 20 levels, and sub-cache pools from level 0 to level 19 are obtained: the cache block capacity in the sub-cache pool of level 0 is between 0-1KB, the cache block capacity in the sub-cache pool of level 1 is between 1-2KB, and so on. The above steps are to first divide the cache pool into levels, and then divide the cache blocks into each sub-cache pool; or you can first divide the cache blocks into various capacities, and then put the cache blocks into the sub-cache pool of the corresponding level according to the capacity of the cache blocks.

[0066] Furthermore, in order to write the critical data into the buffer pool, before determining the target sub-buffer pool corresponding to each message according to the capacity of each message in the buffer data, the following steps may be further included:

[0067] When the capacity of the cached data is greater than the free space in the cache pool, the cached data is filtered to obtain the filtered message;

[0068] Accordingly, the target sub-cache pools corresponding to the messages in the cached data are determined according to their respective capacity, including:

[0069] The corresponding target sub-buffer pool is determined according to the capacity of each filtered message.

[0070] This step is to solve the problem of a large amount of cached data, which cannot be satisfied by the current cache pool capacity. By filtering the cached data, the key data (i.e. filtered messages, also called hot data) in the SSD solid-state drive can be written to the cache pool.

[0071] It should be noted that the cache pool is composed of direct memory and persistent memory, so the direct memory and persistent memory will also be operated according to the above steps. For example, direct memory and persistent memory will be divided into cache blocks of different or equal capacity, and placed in the sub-cache pool of the corresponding level according to their own capacity. In the specific implementation, the cache block division is managed through the LinkedBlockingQueue array of the CacheRecyclePool class, that is, the thread-safe queue data structure. Because the cache priority of direct memory is higher than that of persistent memory, during the data writing process, the data is first written to the direct memory, and when the direct memory is full, the data is written to the persistent memory. Specifically, the hot data in the cache data is written to the direct memory of the cache pool; when the capacity of the direct memory is insufficient, the remaining hot data is written to the persistent memory of the cache pool. In order to better understand the above content, you can refer to the following Figure 5Message data in the SSD is separated into hot and cold data, with hot data placed in the cache pool. Under normal circumstances, hot data is written to the cache pool's direct memory. When direct memory is full, it is written to persistent memory. Alternatively, when direct memory space is insufficient for hot data storage, hot data can be partitioned into primary hot data and secondary hot data (also called secondary hot data). Primary hot data is written to direct memory, while secondary hot data is written to persistent memory. The hot and cold data separation is based on the frequency and timeliness of data access. Specifically, newly written messages and messages in the message queue being read are classified as hot data and placed in the cache pool.

[0072] This embodiment does not limit the method for determining the target sub-cache pool and target cache block; as long as the target cache block can write messages, it can be used. Furthermore, to improve cache efficiency, during the process of writing cache data into the cache pool, the corresponding target sub-cache pool is determined based on the capacity of each message in the cache data, and the corresponding target cache block is determined based on the capacity of the cache block in the corresponding target sub-cache pool. Writing each message into the corresponding target cache block may include the following steps:

[0073] Step 31: Determine the capacity of the current message; the current message is each message;

[0074] Step 32: Determine an initial sub-buffer pool based on the capacity of the current message. The initial sub-buffer pool includes cache blocks that are larger than the capacity of the current message and also includes cache blocks that are smaller than or equal to the capacity of the current message.

[0075] Step 33: If the initial sub-cache pool is the highest-level sub-cache pool and there are free cache blocks in the highest-level sub-cache pool, the free cache blocks are filled with the current message, and the excess data in the current message that is not written to the free cache blocks is written to other memories; the highest-level sub-cache pool is the sub-cache pool with the largest cache space.

[0076] Step 34: If the initial sub-cache pool is not the highest-level sub-cache pool, the sub-cache pool at the previous level of the initial sub-cache pool is used as the target sub-cache pool, and the current message is written into the free cache block with the smallest space in the target sub-cache pool.

[0077] To better understand steps 31 to 34, refer to the following example: Figure 6As shown, when a message is written, for example, if the current message size is 2.5KB, to ensure that the cache block can accommodate the message, the message will go to the next-level sub-cache pool, namely the 3-4KB level 3 sub-cache pool, to obtain a cache block. This ensures that any cache block in the pool has sufficient capacity to accommodate the message, without wasting too much space. In specific implementation, based on the size of the current message being written, cache blocks are obtained from the next-level sub-cache by calling the allocateDramBufferMore and allocatePMemBufferMore methods.

[0078] During grading, if the cache block space size in the highest-level sub-cache pool is 19-20KB, then using the above method, when the current message size is 19.5KB, there is no cache block of 20-21KB to store the message, so only the cache pool with a capacity of 19-20KB can be used. At this time, the cache may be insufficient, for example, there is only 19.2KB of free cache blocks. At this time, off-heap direct memory (i.e., other memory) can be used to make up for the insufficient space, that is, the 19.2KB data in the message is written to the cache block in the sub-cache pool, and the remaining 0.3KB of data is written to the off-heap direct memory; or the cache block in the lowest-level sub-cache pool can be used to store 0.3KB of data.

[0079] Off-heap direct memory, also known as "other memory," is used to store data that cannot fit into the cache. When reading data, if the off-heap direct memory is not empty, it will be used. When a cache block is released, the off-heap direct memory is also released, conserving on-heap memory and reducing the number and time of garbage collection. As shown in the above example, off-heap direct memory is only used when the message size matches the capacity of the highest-level sub-cache pool. For other messages, cache blocks are searched in the next-level sub-cache pool, preventing insufficient cache block space.

[0080] This embodiment achieves rapid writes and improves data read and write efficiency by obtaining cache blocks from the next-level sub-cache pool. It also ensures sufficient capacity for the message without excessive space waste. Furthermore, if the message size corresponds to the highest-level sub-cache pool, the lowest-level sub-cache pool or off-heap direct memory is used to store excess data. Similarly, when reusing and reading from the cache, this off-heap direct memory is also reused and read.

[0081] To further reduce space waste, during the process of writing cache data into the cache pool, determining the corresponding target sub-cache pools based on the capacity of each message in the cache data, determining the corresponding target cache blocks based on the capacity of the cache blocks in the corresponding target sub-cache pools, and writing each message into the corresponding target cache blocks may include the following steps:

[0082] Step 41: During the message writing process, the capacity of the current message is determined; the current message is each message;

[0083] Step 42: Determine the target sub-cache pool based on the capacity of the current message using a matching algorithm;

[0084] Step 43: Determine the target cache block according to the capacity of the cache blocks in the target sub-cache pool using a matching algorithm, and write the current message into the target cache block. The capacity of the target cache block is greater than or equal to the capacity of the current message.

[0085] This embodiment uses a matching method to determine the target sub-cache pool based on capacity, and then further determines the target cache block. This embodiment does not limit the matching algorithm; matching algorithms with the same or different matching accuracy can be used. To better understand the above, refer to the following example: If the current message size is 14.8 KB, the matching method is used to determine the target sub-cache pool to be a level 15 sub-cache pool, where the cache block size is 14-15 KB. The matching algorithm is then used to determine a 14.8 KB cache block within the sub-cache pool. If a 14.8 KB cache block does not currently exist, the next-best 14.9 KB cache block can be used as the target cache block. This method uses the matching method to select the optimal target cache block that can precisely accommodate the message write. This progressive matching method gradually narrows the range of target cache blocks to select, resulting in a more accurate target cache block and maximizing cache pool space utilization.

[0086] S102: Determine the released cache blocks according to the message reading situation, and place the released cache blocks in the sub-cache pool of the corresponding level.

[0087] Since the reading and writing of messages is often a mixed read-write scenario, this embodiment does not limit the execution order of steps S101 and S102. Because the capacity of the cache pool is limited, it is necessary to recycle and reuse cache blocks. For all cache blocks, they can be released, recycled, and reused after the message in which the cache block is located is read. When a cache block is released and recycled, it is recycled to the sub-cache pool of the corresponding level according to its own capacity. This is only used for grading and does not involve sorting, so this can save a lot of time.

[0088] Furthermore, in order to improve the recovery speed, the above-mentioned determination of the released cache blocks based on the message reading situation may include the following steps:

[0089] Step 51: When the read message is the Nth message in the message queue, the cache blocks occupied by the first N-1 messages in the message queue are released;

[0090] Step 52: Record the number of times each message topic is read in real time, and determine the message topic with a message reading number of 0 within a preset time period as a topic to be released;

[0091] Step 53: Release the cache blocks containing all messages under the topic to be released.

[0092] This embodiment provides two methods for determining the release of cache blocks. The first method is to determine the message that has been read or is currently being read before the message in the message queue. Figure 7 As shown in the figure, in a message queue, the location indicated by the arrow indicates the message currently being read. The data on the left represents previously read messages or messages no longer needed, and the data on the right represents unread messages. The cache block eviction strategy involves reclaiming all cache blocks containing the message indicated by the arrow and the data messages to its left, placing them into the corresponding sub-cache pool within the cache pool for reuse when subsequent messages are written. Since reading from a message queue is often sequential, cache blocks can be reclaimed and reused while reading messages, accelerating the elimination of unused cache blocks. This allows the small-capacity direct memory and persistent memory to provide more cache hits, speeding up message reading and writing. Secondly, messages from certain message topics that have not been accessed recently are removed from the cache pool, effectively freeing up cache space. Specifically, to ensure that messages corresponding to topics that have not been read recently release the cache blocks occupied by them, an array is designed in the ThreadController class to count each message topic. The program is responsible for filtering out message topics that have not been accessed in the past 10 minutes. Every time the middleware reads a message, the program automatically adds 1 to the count array of the message topic. The ThreadController class also implements a timer that executes a task every 10 minutes to reclaim the cache blocks of all messages in the message topic corresponding to the count array being 0.

[0093] Furthermore, this embodiment also provides a performance determination method, which may specifically include the following steps:

[0094] Get the free capacity of the cache pool at the current moment in real time;

[0095] The cache rate is calculated based on the free capacity of the cache pool and the capacity of the cached data at the current moment;

[0096] Determine the read and write efficiency based on the cache ratio.

[0097] This embodiment uses the cache rate to measure the read and write efficiency / reuse efficiency of the data read and write method. The specific calculation formula is: cache rate = (free capacity of persistent memory + free capacity of direct memory) / total message size = free capacity of cache pool / cache data size. When the cache rate tends to be stable over a period of time, it means that the data reading and writing are stable; the size of the cache rate that tends to be stable can directly indicate the data reading and writing efficiency. If the cache rate is higher, it means that the recycling and reuse of cache blocks are more efficient. The above process can be specifically implemented in the ThreadController class. There is a polling thread in the ThreadController class, which will dynamically obtain the current direct memory margin and persistent memory margin, and calculate the cache rate according to the above cache rate calculation formula.

[0098] The data reading and writing method provided by the embodiments of the present invention determines the target sub-cache pool corresponding to each message in the cache data based on its capacity, determines the target cache block corresponding to each message based on the capacity of the cache block in the corresponding target sub-cache pool, and writes each message into its corresponding target cache block. The released cache block is determined based on the message reading status and is placed in the sub-cache pool of the corresponding level. The beneficial effects of the present invention are that by dividing the cache pool and hierarchically processing the cache blocks according to their capacity, sub-cache pools of different levels store cache blocks of a certain size range. Thus, when writing a message, it can be written into the cache block of the corresponding sub-cache pool, thus avoiding wasting cache space. When reading a message, cache space can be released in a timely manner, thereby improving the reuse rate of the cache pool. It also avoids the situation where multiple messages are stored in the same cache block, thus simplifying cache block recycling and making message index maintenance simpler and more efficient. It also avoids the problem of wasted space in the last cache block in the linked list. This further allows the reading and writing of middleware messages to make greater use of the cache, thereby improving the performance of the middleware. In addition, due to the limited capacity of the cache pool, cache blocks need to be reused, and message data needs to be separated into hot and cold. Hot data is first stored in the direct memory with the smallest capacity, the second hottest data is stored in the persistent memory with a larger capacity, and cold data is only stored in the solid-state drive. In this way, the relatively small cache pool can be fully and effectively used.

[0099] The data reading and writing device provided by an embodiment of the present invention is introduced below. The data reading and writing device described below and the data reading and writing method described above can be referred to each other.

[0100] Please refer to Figure 8 , Figure 8 A schematic structural diagram of a data reading and writing device provided in an embodiment of the present invention may include:

[0101] The writing module 100 is configured to determine the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, determine the target cache block corresponding to each message according to the capacity of the cache block in the target sub-cache pool, and write each message into the target cache block corresponding to each message;

[0102] The reading module 200 is configured to determine a released cache block according to a message reading condition, and place the released cache block in a sub-cache pool of a corresponding level.

[0103] Based on the above embodiment, the data reading and writing device may further include:

[0104] A division level determination module is used to determine the division level according to the capacity of the cache data and the capacity of the cache pool;

[0105] The cache pool partitioning module is used to partition the cache pool according to the number of partition levels to obtain sub-cache pools at each level;

[0106] The sub-cache pool division module is used to divide the sub-cache pools of different levels according to the capacity of each message in the cache data to obtain each cache block.

[0107] Based on the above embodiment, the data reading and writing device may further include:

[0108] a data screening module, configured to screen the cached data to obtain a screened message when the capacity of the cached data is greater than the free space capacity of the cache pool;

[0109] Accordingly, the writing module 100 may include:

[0110] The writing unit is used to determine the corresponding target sub-buffer pool according to the capacity of each filtered message.

[0111] Based on the above embodiment, the cache pool includes direct memory and persistent memory, and both the direct memory and the persistent memory contain sub-cache pools of multiple levels. The cache priority of the direct memory is higher than that of the persistent memory.

[0112] Based on the above embodiment, the data reading and writing device may further include:

[0113] The free capacity acquisition module is used to obtain the free capacity of the cache pool at the current moment in real time;

[0114] A cache rate calculation module, configured to calculate a cache rate based on the free capacity of the cache pool at the current moment and the capacity of the cached data;

[0115] The read / write efficiency determination module is configured to determine the read / write efficiency according to the cache rate.

[0116] Based on the above embodiment, the writing module 100 may include:

[0117] a message capacity determination unit, configured to determine the capacity of a current message; the current message being each of the messages;

[0118] an initial sub-buffer pool determining unit, configured to determine an initial sub-buffer pool according to the capacity of the current message; the initial sub-buffer pool including cache blocks larger than the capacity of the current message and cache blocks smaller than or equal to the capacity of the current message;

[0119] a third writing unit, configured to, if the initial sub-cache pool is a highest-level sub-cache pool and there are free cache blocks in the highest-level sub-cache pool, fill the free cache blocks with the current message and write excess data in the current message that is not written into the free cache blocks into another memory; the highest-level sub-cache pool is the sub-cache pool with the largest cache space;

[0120] a fourth writing unit configured to, if the initial sub-cache pool is not the highest-level sub-cache pool, use the sub-cache pool at the previous level of the initial sub-cache pool as the target sub-cache pool, and write the current message into the free cache block with the smallest space in the target sub-cache pool.

[0121] Based on the above embodiment, the reading module 200 may include:

[0122] A first releasing unit is configured to release the cache blocks occupied by the first N-1 messages in the message queue when the read message is the Nth message in the message queue;

[0123] A reading count recording unit is used to record the number of message reads of each message topic in real time, and determine a message topic with a message reading count of 0 within a preset time period as a topic to be released;

[0124] The second releasing unit is used to release the cache blocks where all messages under the to-be-released topic are located.

[0125] It should be noted that the order of the modules and units in the above-mentioned data reading and writing device can be changed without affecting the logic.

[0126] The data reading and writing device provided by the embodiment of the present invention comprises a writing module 100 for determining the target sub-cache pool corresponding to each message in the cache data based on the capacity of each message, determining the target cache block corresponding to each message based on the capacity of the cache block in each target sub-cache pool, and writing each message into the target cache block. A reading module 200 is used to determine the released cache block based on the message reading status and place the released cache block into the sub-cache pool of the corresponding level. The beneficial effect of this device is that by dividing the cache pool, the cache blocks are hierarchically processed according to capacity. Sub-cache pools of different levels store cache blocks of a certain size range. Thus, when writing a message, it can be written to the cache block of the corresponding sub-cache pool, eliminating cache space waste. When reading a message, cache space can be released in a timely manner, thereby improving the reuse rate of the cache pool. It also avoids storing multiple messages in the same cache block, simplifying cache block recycling, making message index maintenance simpler and more efficient, and avoiding the problem of wasted space in the last cache block in the linked list. This further allows the reading and writing of middleware messages to make greater use of the cache, thereby improving the performance of the middleware. In addition, when writing messages, due to the limited capacity of the cache pool, cache blocks need to be reused, and message data is separated into hot and cold. Hot data is first stored in the direct memory with the smallest capacity, the second hottest data is stored in the persistent memory with a larger capacity, and cold data is only stored in the solid-state drive. In this way, the relatively small cache pool can be fully and effectively used.

[0127] Figure 9 A structural diagram of a data reading and writing device provided by an embodiment of the present invention is shown in FIG. Figure 9 As shown, the data reading and writing device includes:

[0128] Memory 60, for storing computer programs;

[0129] The processor 61 is configured to implement the steps of the data reading and writing method in the above embodiment when executing a computer program.

[0130] The data reading and writing device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.

[0131] The processor 61 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 61 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 61 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing content required to be displayed on the display screen. In some embodiments, the processor 61 may also include an artificial intelligence (AI) processor for handling computational operations related to machine learning.

[0132] The memory 60 may include one or more computer-readable storage media, which may be non-transitory. The memory 60 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 60 is at least used to store the following computer program 601, wherein, after the computer program is loaded and executed by the processor 61, it can implement the relevant steps of the data reading and writing method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 60 may also include an operating system 602 and data 603, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 602 may include Windows, Unix, Linux, etc. The data 603 may include but is not limited to data of the data reading and writing method, etc.

[0133] In some embodiments, the data reading and writing device may further include a display screen 62 , an input and output interface 63 , a communication interface 64 , a power supply 65 , and a communication bus 66 .

[0134] Those skilled in the art will understand that Figure 9 The structure shown in the figure does not constitute a limitation to the data reading and writing device, and may include more or fewer components than shown in the figure.

[0135] It is understandable that if the data reading and writing method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the current technology, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and executes all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk, etc. Various media that can store program code.

[0136] Based on this, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned data reading and writing method are implemented.

[0137] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.

[0138] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0139] Finally, it should be noted that, in this document, relationships such as first and second, etc., are used solely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0140] The above is a detailed introduction to a data reading and writing method, device, equipment and computer-readable storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core ideas. At the same time, for those skilled in the art, according to the ideas of the present invention, there may be changes in the specific implementation methods and application scopes. In summary, the contents of this specification should not be understood as limiting the present invention.

Claims

1. A data reading and writing method, characterized in that: include: Determine the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, determine the target cache block corresponding to each message according to the capacity of the cache block in the target sub-cache pool, and write each message into the target cache block corresponding to each message; Determine the released cache blocks according to the message reading situation, and place the released cache blocks in the sub-cache pool of the corresponding level; Determining the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages, determining the target cache blocks corresponding to the messages according to the capacity of the cache blocks in the target sub-cache pools, and writing the messages into the target cache blocks corresponding to the messages, including: Determine the capacity of the current message; the current message is each of the messages; Determining an initial sub-buffer pool according to the capacity of the current message; the initial sub-buffer pool includes cache blocks larger than the capacity of the current message and also includes cache blocks smaller than or equal to the capacity of the current message; If the initial sub-cache pool is the highest-level sub-cache pool and there are free cache blocks in the highest-level sub-cache pool, the free cache blocks are filled with the current message, and excess data in the current message that is not written into the free cache blocks is written into other memory; the highest-level sub-cache pool is the sub-cache pool with the largest cache space; If the initial sub-cache pool is not the highest-level sub-cache pool, the sub-cache pool at the previous level of the initial sub-cache pool is used as the target sub-cache pool, and the current message is written into the free cache block with the smallest space in the target sub-cache pool.

2. The data reading and writing method according to claim 1, wherein: Before determining the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, the following is also included: Determining the number of division levels according to the capacity of the cache data and the capacity of the cache pool; Divide the cache pool according to the number of division levels to obtain sub-cache pools at each level; The sub-cache pools of each level are divided according to the capacity of each message in the cache data to obtain cache blocks.

3. The data reading and writing method according to claim 1, wherein: Before determining the target sub-cache pool corresponding to each message in the cache data according to the capacity of each message, the following is also included: When the capacity of the cached data is greater than the free space capacity of the cache pool, the cached data is filtered to obtain filtered messages; Accordingly, determining the target sub-cache pool corresponding to each message in the cache data according to its capacity includes: The corresponding target sub-buffer pool is determined according to the capacity of each filtered message.

4. The data reading and writing method according to claim 1, wherein: The cache pool includes direct memory and persistent memory. Both the direct memory and the persistent memory contain sub-cache pools of multiple levels. The cache priority of the direct memory is higher than that of the persistent memory.

5. The data reading and writing method according to claim 1, wherein: Also includes: Get the free capacity of the cache pool at the current moment in real time; Calculating a cache rate based on the free capacity of the cache pool at the current moment and the capacity of the cached data; The read and write efficiency is determined according to the cache rate.

6. The data reading and writing method according to claim 1, wherein: The cache blocks to be released are determined based on the message reading situation, including: When the read message is the Nth message in the message queue, the cache blocks occupied by the first N-1 messages in the message queue are released; Record the number of times each message topic is read in real time, and determine the message topic with 0 message read times within a preset time period as a topic to be released; Release the cache blocks where all messages under the subject to be released are located.

7. A data reading and writing device, characterized in that: include: a writing module, configured to determine a corresponding target sub-cache pool according to the capacity of each message in the cache data, determine a corresponding target cache block according to the capacity of the cache block in the corresponding target sub-cache pool, and write each message into the corresponding target cache block; A reading module, configured to determine a released cache block according to a reading condition of a message, and place the released cache block in a sub-cache pool of a corresponding level; Write modules, including: a message capacity determination unit, configured to determine the capacity of a current message; the current message being each of the messages; an initial sub-buffer pool determining unit, configured to determine an initial sub-buffer pool according to the capacity of the current message; the initial sub-buffer pool including cache blocks larger than the capacity of the current message and cache blocks smaller than or equal to the capacity of the current message; a third writing unit, configured to, if the initial sub-cache pool is a highest-level sub-cache pool and there are free cache blocks in the highest-level sub-cache pool, fill the free cache blocks with the current message and write excess data in the current message that is not written into the free cache blocks into another memory; the highest-level sub-cache pool is the sub-cache pool with the largest cache space; a fourth writing unit configured to, if the initial sub-cache pool is not the highest-level sub-cache pool, use the sub-cache pool at the previous level of the initial sub-cache pool as the target sub-cache pool, and write the current message into the free cache block with the smallest space in the target sub-cache pool.

8. A data reading and writing device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the data reading and writing method according to any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data reading and writing method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Data processing method, device and system, system-level SOC chip and computer equipment

    CN115481054A

  • Cache disk space allocation method and device, computer equipment and storage medium

    CN117311621A