Data read-write method, device and equipment and computer readable storage medium

By hierarchically processing the cache pool, the target sub-cache pool and cache block are determined according to the capacity of the message for writing and freeing, solving the problem of low cache space utilization and reuse rate and improving the performance of the middleware.

CN119248198AActive Publication Date: 2025-01-03INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

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

AI Technical Summary

Technical Problem

In the prior art, the cache space utilization and reuse rate are low, resulting in a waste of cache space and low reuse efficiency when reading and writing data in extreme scenarios.

Method used

By dividing multi-level sub-cache pools and cache blocks according to the capacity size of cache data, determining the target sub-cache pools and cache blocks according to the capacity size of the message for writing, and releasing cache blocks according to the read situation, improving the reuse of cache pools Rate.

Benefits of technology

It effectively improves the utilization and reuse rate of cache space, reduces the complexity of cache block recycling, avoids space waste, and improves the performance of middleware.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248198A_ABST
    Figure CN119248198A_ABST
Patent Text Reader

Abstract

The invention discloses a data read-write method, device and equipment and a computer readable storage medium, which are applied to the field of data caching, and comprise the following steps: determining respective corresponding target sub-cache pools according to the capacity of each message in cached data, determining respective corresponding target cache blocks according to the capacities of the cache blocks in the respective corresponding target sub-cache pools, and writing the messages into the respective corresponding target cache blocks; and determining the released cache block according to the reading condition of the message, and placing the released cache block in the sub-cache pool of the corresponding level. According to the invention, the problems of low utilization rate and reuse rate of the cache space are solved.
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] With the rapid development of computer and network technology, higher requirements are placed on memory capacity. In extreme scenarios where large amounts of data are continuously read and written, the capacity of the cache pool composed of direct memory and persistent memory is relatively limited compared to the size of the message to be written, so the cache will inevitably be reused during subsequent writing and reading.

[0003] Since the speed and latency of cache are much better than those of SSD (Solid State Disk), it is necessary to make full use of the limited cache space. Therefore, how to improve the utilization and reuse rate of cache space is an urgent problem to be solved. Summary of the invention

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

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

[0006] Determine the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages, determine the target cache blocks corresponding to the messages according to the capacity of the cache blocks in the target sub-cache pools corresponding to the messages, and write the messages into the target cache blocks corresponding to the messages;

[0007] The released cache blocks are determined according to the reading situation of the message, 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 pools corresponding to the messages in the cache data according to the capacity of the messages, the method further includes:

[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-buffer pools of each level are divided according to the capacity of each message in the cache data to obtain each cache block.

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

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

[0014] Correspondingly, the step of determining the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages includes:

[0015] The corresponding target sub-buffer pools are determined according to the capacity of each of the filtered messages.

[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 different levels, and 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] The cache rate is calculated according to the free capacity of the cache pool at the current moment and the capacity of the cache data;

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

[0021] On the one hand, determining the corresponding target sub-cache pools according to the capacity of each message in the cache data, determining the corresponding target cache blocks according to the capacity of the cache blocks in the corresponding target sub-cache pools, and writing the messages into the corresponding target cache blocks, including:

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

[0023] Determine an initial sub-buffer pool according to the capacity of the current message; the initial sub-buffer pool includes a cache block larger than the capacity of the current message, and also includes a cache block 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 the redundant data in the current message that is not written into the free cache blocks is written into other memories; the highest-level sub-cache pool is the sub-cache pool with the largest cache space;

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

[0026] On the one hand, the cache blocks to be released are determined according to the reading situation of the message, 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 a number of times of reading 0 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, used to 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;

[0032] The reading module is used to determine the released cache block according to the reading situation of the message, and place the released cache block 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 as 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 claim when executed by a processor.

[0038] It can be seen from the above technical scheme that the target sub-cache pools corresponding to each other are determined according to the capacity of each message in the cache data, the target cache blocks corresponding to each other are determined according to the capacity of the cache blocks in the target sub-cache pools corresponding to each other, and each message is written into the target cache blocks corresponding to each other; the released cache blocks are determined according to the reading situation of the message, and the released cache blocks are placed in the sub-cache pools of the corresponding level. The beneficial effect of the present invention is that by dividing the cache pools in advance, 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, so that when the message is written, it can be written into the cache block of the corresponding sub-cache pool, without wasting the cache space, and the cache space can be released in time when the message is read, thereby improving the reuse rate of the cache pool. In this way, the reading and writing of the middleware messages can further use the high-speed cache more, so that the performance of the middleware can be improved.

[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 drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying 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 flow chart 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 in 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 diagram of the structure of a data reading and writing device provided by an embodiment of the present invention;

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

[0050] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the 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 creative work are 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 a 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. The queue is a two-dimensional array. Once the topic is determined, the queueId can determine the unique queue. 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 and thus find the message. 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 the queue is uniquely identified by topic and queueId, the specific message in the queue can be found according to the offset.

[0052] With the rapid development of computer and network technology, in extreme scenarios where large amounts of data are continuously read and written, the capacity of the cache pool composed of direct memory (DRAM memory) and persistent memory (PMem persistent memory) is relatively limited compared to the size of the message to be written, so messages will inevitably reuse the cache when written and read later. Since the speed and latency of the cache are much better than SSD, it is necessary to make full use of the limited cache and increase the utilization and reuse rate of the cache pool as much as possible, so that the middleware's message reading and writing can use more cache and improve the performance of the middleware. Message middleware is a supporting software system based on queue and message passing technology that provides synchronous or asynchronous, reliable message transmission for application systems in a network environment.

[0053] The current cache block design is generally a fixed-length cache block, which divides the cache block granularity into a specific size. Each queue has a linked list of cache blocks, which is used to store multiple messages under this topic and queueId. However, the current fixed-length cache block design will bring the following problems:

[0054] (1) Cache block recycling becomes complicated and inefficient. Figure 2 The large square outside represents the cache block, which is of fixed size. The leftmost square inside represents the message that has been read, and the remaining squares inside 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 the 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 to recycle the cache block. When recycling, it is necessary to determine whether all messages in the current cache block have been read at the same time, and the recycling mechanism becomes 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 utilization rate of the last cache block in the linked list of the same queue is low. 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 design of fixed-length cache blocks, the utilization rate of the last cache block in the linked list is low, resulting in a waste of space.

[0057] Therefore, in order to solve the above problems, this paper designs a cache (data reading and writing) solution to improve the reuse rate of the cache, make full use of the cache space, simplify the recovery of cache blocks, avoid the situation where the same cache block stores multiple messages, make the maintenance of message indexes simpler and more efficient, and avoid the problem of space waste of the last cache block in the linked list. This method classifies cache blocks according to their capacity. Cache pools of different levels store cache blocks of a certain size range, ensuring that cache blocks can be reused in the corresponding sub-cache pools when they are reused, thereby better improving the reuse efficiency of cache blocks.

[0058] Please refer to Figure 3 , Figure 3 A flowchart 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 cache data includes a large number of messages. In the process of writing the messages into the cache pool, the size of the cache data and the capacity of the cache pool need to be considered. First, the target sub-cache pool is determined according to the size of each message in the cache data, and then the target cache block is determined according to the capacity of the cache block in the target sub-cache pool. It can be understood that the target cache block is the minimum capacity cache block that can write the message, which avoids the waste of space caused by storing messages across blocks; it also avoids the problem of difficulty in reclaiming cache blocks due to the situation where multiple messages are stored in one cache block.

[0061] Furthermore, in order to improve the utilization of the cache space, before determining the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages, the following steps may be 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 0-1KB, the cache block capacity in the sub-cache pool of level 1 is 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 to obtain cache blocks of various capacities, and then put the cache blocks into the sub-cache pools of the corresponding level according to the capacity of the cache blocks.

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

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

[0068] Accordingly, the target sub-cache pools corresponding to the respective messages in the cache data are determined according to the capacity of the respective messages, 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 that the amount of cached data is large and the capacity of the current cache pool cannot meet the needs. The cached data can be filtered and the key data (that is, the 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 accordingly. For example, direct memory and persistent memory will be divided into cache blocks of different or equal capacity, and placed in sub-cache pools of corresponding levels 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 5, separate the message data in the SSD into hot and cold data, and put the hot data into the cache pool. Under normal circumstances, the hot data is written to the direct memory of the cache pool, and then written to the persistent memory when the direct memory is full. Alternatively, when the direct memory space does not meet the storage requirements of hot data, the hot data can be divided into primary hot data and secondary hot data (also called secondary hot data), and the primary hot data is written to the direct memory, and the secondary hot data is written to the persistent memory. The separation of hot and cold data is based on the frequency and timeliness of data access. Specifically, the messages that have just been written and the messages on the message queue that are being read are classified as hot data and put into the cache pool.

[0072] This embodiment does not limit the method for determining the target sub-cache pool and the target cache block, as long as the target cache block can write messages. Further, in order to improve cache efficiency, in the process of writing cache data into the cache pool, the corresponding target sub-cache pool is determined according to the capacity of each message in the cache data, the corresponding target cache block is determined according to the capacity of the cache block in the corresponding target sub-cache pool, and each message is written into the corresponding target cache block, which 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 according to 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 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 redundant data in the current message that is not written into the free cache blocks is written into 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, the current message size is 2.5KB, to ensure that the cache block can hold the message, the message will go to the upper level sub-cache pool, that is, the 3rd level sub-cache pool with a size of 3-4KB to obtain the cache block, so that any cache block in the space can ensure that there is enough capacity to hold the message, and will not cause too much space waste. In specific implementation, according to the size of the current written message, the cache block is obtained from the higher 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. In this case, the cache may be insufficient, such as only 19.2KB of free cache blocks. At this time, off-heap direct memory (that is, other memory) can be used to make up for the insufficient space, that is, 19.2KB of 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 sub-cache pool of the lowest level can be used to store 0.3KB of data.

[0079] Off-heap direct memory is other memory, which is used to store some data that cannot be stored. When reading data, if the off-heap direct memory is not empty, the off-heap direct memory will be read. When the cache block is released, the off-heap direct memory will also be released at the same time, which can save on-heap memory and reduce the number and time of garbage collection. From the above example, it can be seen that the off-heap direct memory may be used only when the message size corresponds to the capacity of the highest-level sub-cache pool. Other messages will go to the upper-level sub-cache pool to find the cache block, and there will be no shortage of cache block space.

[0080] This embodiment can complete fast writing and improve data reading and writing efficiency by obtaining cache blocks from the upper-level sub-cache pool. It can also ensure that there is enough capacity to hold the message without causing too much space waste. In addition, 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 the cache is reused and read, the off-heap direct memory will also be reused and read.

[0081] In order to further reduce space waste, in the process of writing cache data into the cache pool, the corresponding target sub-cache pools are determined according to the capacity of each message in the cache data, the corresponding target cache blocks are determined according to the capacity of the cache blocks in the corresponding target sub-cache pools, and the messages are written into the corresponding target cache blocks, which may include the following steps:

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

[0083] Step 42: Determine the target sub-buffer pool according to 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, write the current message into the target cache block, and 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 according to the capacity size, and further determines the target cache block. This embodiment does not limit the matching algorithm, and can use matching algorithms with the same matching accuracy or matching algorithms with different matching accuracy. In order to better understand the above content, you can refer to the following example: if the current message size is 14.8kb, the matching method is used to determine that the target sub-cache pool is a sub-cache pool of level 15, and the cache block size in the cache pool is 14-15KB. In this way, the matching algorithm is used to determine a 14.8KB cache block in the sub-cache pool, or if there is no 14.8KB cache block at present, the second-best 14.9KB cache block can be used as the target cache block. This method can select the best target cache block by using the matching method, so that the cache block can just meet the writing of the message; and this progressive matching method gradually narrows the selection range of the target cache block, so that the target cache block obtained is more accurate, so that the space utilization rate of the cache pool is the highest.

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

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

[0088] Furthermore, in order to improve the recovery speed, the above-mentioned determination of the cache block to be released according to the reading situation of the message 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 whose number of times of message reading is 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 before the message in the message queue. Figure 7 As shown in the figure, in a message queue, the position pointed by the arrow indicates the message currently being read, the data on the left indicates the message that has been read before or is no longer needed, and the data on the right indicates the message that has not been read. The cache block recycling strategy is to recycle all the cache blocks where the message at the position pointed by the arrow and the data message on its left are located, and put them into the sub-cache pool of the corresponding level in the cache pool, so that subsequent messages can be reused when writing. For a message queue, the reading is often sequential, so the cache blocks can be recycled and reused while reading the messages, speeding up the elimination process of useless cache blocks, allowing small-capacity direct memory and persistent memory to provide more cache hits, and speeding up the message reading and writing speed. The second type is that messages of certain message topics that have not been accessed recently will be removed from the cache pool, which effectively releases the cache space of the cache pool. Specifically, in order to allow the messages corresponding to those message topics that have not been read recently to release the occupied cache blocks in time, 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 where the message is located. The ThreadController class also implements a timer that executes a task every 10 minutes to recycle the cache blocks where all messages under the message topic corresponding to the count array being 0 are located.

[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 rate.

[0097] This embodiment uses the cache rate to measure the read-write efficiency / reuse efficiency of the data read-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 at last can directly indicate the data reading and writing efficiency. If the cache rate is higher, the recycling and reuse of the cache block 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 embodiment of the present invention is applied, by determining the corresponding target sub-cache pool according to the capacity size of each message in the cache data, determining the corresponding target cache block according to the capacity size of the cache block in the corresponding target sub-cache pool, and writing each message into the corresponding target cache block; determining the released cache block according to the reading situation of the message, and placing the released cache block in the sub-cache pool of the corresponding level. The beneficial effect of the present invention is that: by dividing the cache pool, the cache block is graded according to the capacity size, and the sub-cache pools of different levels store cache blocks of a certain size space range, so that when the message is written, it can be written into the cache block of the corresponding sub-cache pool, without wasting the cache space, and the cache space can be released in time when the message is read, so as to improve the reuse rate of the cache pool. At the same time, it also avoids the situation that the same cache block stores multiple messages, thus simplifying the recovery of the cache block, making the maintenance of the message index simpler and more efficient, and at the same time, there will be no problem of space waste of the last cache block in the linked list. In this way, the reading and writing of the middleware message further uses the high-speed cache, so that the performance of the middleware can be improved. In addition, due to the limited capacity of the cache pool, cache blocks need to be reused, and message data must 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 the 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 diagram of the structure of a data reading and writing device provided by an embodiment of the present invention may include:

[0101] The writing module 100 is used to 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;

[0102] The reading module 200 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.

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

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

[0105] A 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 various 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, used for screening the cached data to obtain a screened message when the capacity of the cached data is larger 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 of the filtered messages.

[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 different 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, used to calculate the cache rate according to the free capacity of the cache pool at the current moment and the capacity of the cache data;

[0115] The read / write efficiency determination module is used 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, used to determine the capacity of a current message; the current message is 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 includes a cache block larger than the capacity of the current message, and also includes a cache block smaller than or equal to the capacity of the current message;

[0119] a third writing unit, configured to fill up the free cache blocks with the current message and write the redundant data in the current message that is not written into the free cache blocks into other memories 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 highest-level sub-cache pool is the sub-cache pool with the largest cache space;

[0120] The fourth writing unit is used to use the sub-cache pool of the previous level of the initial sub-cache pool as the target sub-cache pool if the initial sub-cache pool is not the highest-level 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, 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, used to record the number of message readings of each message topic in real time, and determine the 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 subject to be released are located.

[0125] It should be noted that the order of the modules and units in the above 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 is applied, through the writing module 100, used to determine the corresponding target sub-buffer pool according to the capacity size of each message in the cache data, determine the corresponding target cache block according to the capacity size of the cache block in the corresponding target sub-buffer pool, and write the messages into the corresponding target cache block; the reading module 200 is used to determine the released cache block according to the reading situation of the message, and place the released cache block in the corresponding level of the sub-buffer pool. The beneficial effect of this device is that: by dividing the cache pool, the cache block is graded according to the capacity size, and the sub-buffer pools of different levels store cache blocks of a certain size space range, so that when the message is written, it can be written into the cache block of the corresponding sub-buffer pool, without wasting the cache space, and the cache space can be released in time when the message is read, so as to improve the reuse rate of the cache pool. At the same time, it also avoids the situation that multiple messages are stored in the same cache block, so that the recovery of the cache block is simplified, the maintenance of the message index is simpler and more efficient, and there will be no problem of space waste of the last cache block in the linked list. In this way, the reading and writing of the middleware message further uses the high-speed cache, so that the performance of the middleware can be improved. In addition, when writing messages, due to the limited capacity of the cache pool, the cache blocks need to be reused, and the message data is separated into hot and cold data. The hot data is first stored in the direct memory with the smallest capacity, the second hot data is stored in the persistent memory with a larger capacity, and the cold data is only stored in the solid-state drive. In this way, the cache pool with a relatively small capacity can be fully and effectively used.

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

[0128] A memory 60, for storing computer programs;

[0129] The processor 61 is used 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] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and 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), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an artificial intelligence (AI) processor, which is used to process computing 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, the relevant steps of the data reading and writing method disclosed in any of the aforementioned embodiments can be implemented. 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. 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 also 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 Fig. 9 The structure shown in the figure does not constitute a limitation on the data reading and writing device, and may include more or less components than those 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 such an understanding, the technical solution of the present invention is essentially 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, and the computer software product is stored in a storage medium to execute 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 and other media that can store program codes.

[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] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[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 composition and steps of each example have been generally described in the above description according to function. 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 article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[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 in this article 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 idea; at the same time, for a person skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A data reading and writing method, characterized in that: include: Determine the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages, determine the target cache blocks corresponding to the messages according to the capacity of the cache blocks in the target sub-cache pools corresponding to the messages, and write the messages into the target cache blocks corresponding to the messages; The released cache blocks are determined according to the reading situation of the message, and the released cache blocks are placed in the sub-cache pool of the corresponding level.

2. The data reading and writing method according to claim 1, characterized in that: Before determining the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages, 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-buffer pools of each level are divided according to the capacity of each message in the cache data to obtain each cache block.

3. The data reading and writing method according to claim 1, characterized in that: Before determining the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages, the following is also included: When the capacity of the cache data is greater than the free space capacity of the cache pool, the cache data is filtered to obtain filtered messages; Correspondingly, the step of determining the target sub-cache pools corresponding to the messages in the cache data according to the capacity of the messages includes: The corresponding target sub-buffer pools are determined according to the capacity of each of the filtered messages.

4. The data reading and writing method according to claim 1, characterized in that: The cache pool includes direct memory and persistent memory. Both the direct memory and the persistent memory contain sub-cache pools of multiple different 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, characterized in that: Also includes: Get the free capacity of the cache pool at the current moment in real time; The cache rate is calculated according to the free capacity of the cache pool at the current moment and the capacity of the cache data; The read and write efficiency is determined according to the cache rate.

6. The data reading and writing method according to any one of claims 1 to 5, characterized in that: 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 corresponding to the messages, 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; Determine an initial sub-buffer pool according to the capacity of the current message; the initial sub-buffer pool includes a cache block larger than the capacity of the current message, and also includes a cache block 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 the redundant data in the current message that is not written into the free cache blocks is written into other memories; the highest-level sub-cache pool is the sub-cache pool with the largest cache space; If the initial sub-buffer pool is not the highest-level sub-buffer pool, the upper-level sub-buffer pool of the initial sub-buffer pool is used as the target sub-buffer pool, and the current message is written into the free buffer block with the smallest space in the target sub-buffer pool.

7. The data reading and writing method according to claim 1, characterized in that: The cache blocks to be released are determined based on the reading of the message, 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 a number of times of reading 0 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.

8. A data reading and writing device, characterized in that: include: A writing module, used to 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; The reading module is used to determine the released cache block according to the reading situation of the message, and place the released cache block in the sub-cache pool of the corresponding level.

9. 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 as claimed in any one of claims 1 to 7 when executing the computer program.

10. 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 7 are implemented.

Citation Information

Patent Citations

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

    CN115481054A

  • Caching method and device of distributed storage system and computer equipment

    CN116048399A

  • Memory optimization method and device based on Spark program, equipment and storage medium

    CN117170585A

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

    CN117311621A

  • Apparatus, system, and method for managing contents of a cache

    US20120221774A1

Cited By

  • Cache file management method and device, storage medium and computer program product

    CN119759858A

  • Data storage method, storage device and related equipment

    CN121209796A