Data access method, device, equipment and storage medium
By flexibly switching the head pointer in the hash-mapped circular linked list, the problem of low access efficiency of one-way linked lists is solved, efficient data access of circular linked lists is realized, and cache performance and single-thread performance are improved.
Patent Information
- Application Number
- CN201911101097.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-11-12
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2039-11-12
AI Technical Summary
The access efficiency of one-way linked lists in the existing technology is low, and the head pointer cannot be flexibly switched to traverse the entire linked list, resulting in low data access efficiency.
A hash-mapped circular linked list is used to flexibly switch the node pointed by the head pointer to achieve traversal of the circular linked list and fast access to hot data, improving data access efficiency.
Significantly improves data access efficiency, reduces hot data access overhead, improves cache performance, and improves single-thread performance without affecting cold data access latency.
Smart Images

Figure CN112860684B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computers, and in particular relates to a data access method, device, equipment and storage medium. Background Art
[0002] Memory management is an important issue in computer applications. In the prior art, memory management is performed in the form of a one-way linked list, which includes a series of nodes. The operations of the one-way linked list include inserting a node, accessing node data, deleting a node, modifying node data, searching for data, and the like.
[0003] Currently, each time a singly linked list is accessed, the access starts from the first node of the linked list, where the first node of the linked list is fixed. However, this access efficiency is low. Summary of the invention
[0004] The embodiments of the present invention provide a data access method, device, equipment and storage medium, which can improve access efficiency.
[0005] In a first aspect, an embodiment of the present invention provides a data access method, the method comprising:
[0006] In the circular linked list of the hash map, determining the node to which the head pointer of the circular linked list points;
[0007] The circular linked list is accessed according to the node pointed to by the head pointer.
[0008] In a second aspect, an embodiment of the present invention provides a data access method, including:
[0009] In a linked list of a hash map, determining a node pointed to by a first pointer of the linked list, wherein the first pointer is a pointer other than a head pointer;
[0010] In the case that the node pointed to by the first pointer is the target access node, if the node pointed to by the first pointer is accessed, the access to the linked list is terminated.
[0011] In a third aspect, an embodiment of the present invention provides a data access device, including:
[0012] A node determination module, used to determine the node pointed to by the head pointer of the circular linked list in the hash map;
[0013] The linked list access module is used to access the circular linked list according to the node pointed to by the head pointer.
[0014] In a fourth aspect, an embodiment of the present invention provides a data access device, comprising:
[0015] A node determination module, used to determine, in a linked list of a hash map, a node pointed to by a first pointer of the linked list, wherein the first pointer is a pointer other than a head pointer;
[0016] The access module is used to terminate the access to the linked list if the node pointed to by the first pointer is the target access node and the node pointed to by the first pointer is accessed.
[0017] In a fifth aspect, an embodiment of the present invention provides a computing device, the device comprising: a processor and a memory storing computer program instructions;
[0018] The data access method is implemented when the processor executes the computer program instructions.
[0019] In a sixth aspect, an embodiment of the present invention provides a computer storage medium, on which computer program instructions are stored, and the computer program instructions implement the data access method when executed by a processor.
[0020] In the data access method, device, equipment and storage medium of the embodiment of the present invention, the linked list of hash mapping is a circular linked list, and even if the node pointed to by the head pointer is changed, the nodes of the entire linked list can be traversed. The direction of the head pointer can be flexibly switched, and the head pointer can point to any node in the circular linked list, meeting the needs of data access and improving data access efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following is a brief introduction to the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0022] Figure 1 A schematic diagram of a data access method according to an embodiment of the present invention;
[0023] Figure 2 A schematic diagram of a circular linked list and a one-way linked list according to an embodiment of the present invention;
[0024] Figure 3 is a schematic diagram of the performance of the Zipf distribution when θ is 0.99;
[0025] Figure 4 is a schematic diagram of the performance of the Zipf distribution when θ is 1.22;
[0026] Figure 5 Schematic diagram of uniform distribution performance;
[0027] Figure 6A schematic diagram of a data access principle of an embodiment provided by the present invention;
[0028] Figure 7 A schematic flow chart of a data access method according to another embodiment of the present invention;
[0029] Figure 8 A schematic diagram of data access based on a one-way linked list according to an embodiment of the present invention;
[0030] Fig. 9 A block diagram of a data access device according to an embodiment of the present invention;
[0031] Fig.10 A block diagram of a data access device according to another embodiment of the present invention;
[0032] Fig.11 A schematic diagram of the hardware structure of a computing device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.
[0034] It should be noted that, in this article, relational terms such as first and second, etc. are only used 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", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including 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. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0035] In order to solve the problems in the prior art, the embodiments of the present invention provide a data access method, device, equipment and storage medium. The data access method provided by the embodiments of the present invention is first introduced below.
[0036] Figure 1 The following is a flow chart of a data access method according to an embodiment of the present invention. Figure 1 As shown, the data access method includes:
[0037] S101, in the circular linked list of the hash map, determine the node pointed to by the head pointer of the circular linked list.
[0038] S102, access the circular linked list according to the node pointed to by the head pointer.
[0039] Figure 2 A schematic diagram of a circular linked list and a one-way linked list according to an embodiment of the present invention.
[0040] A one-way linked list (single linked list) is a type of linked list. Its characteristic is that the link direction of the linked list is unidirectional. The access to the linked list must be read sequentially and start from the head. The linked list is a list constructed using pointers. It is also called a node list because the linked list is assembled from nodes one by one. Each node has a pointer member variable pointing to the next node in the list. The linked list includes nodes. The head pointer points to the first node, the pointer of the first node points to the second node, and so on, until the pointer of the last node points to NULL.
[0041] The pointer of each node in the multiple nodes of the circular linked list points to the next node, so that the multiple nodes are arranged in sequence, and the pointer of the last node points to the first node to form a circular linked list. Unlike a one-way linked list, the pointer of the last node of a circular linked list points to the first node, while the pointer of the last node of a one-way linked list points to NULL.
[0042] For a circular linked list, starting from the node pointed to by the head pointer, the nodes on the circular linked list are accessed in sequence until the target access node is accessed. The purpose of accessing the circular linked list is to access the data of the target access node.
[0043] For example, in Figure 2 In the process of accessing the circular linked list in , after visiting node 1, it is determined that node 1 is not the target access node, and node 2 is continued to be visited; after visiting node 2, it is determined that node 2 is not the target access node either, and node 3 is continued to be visited; after visiting node 3, it is determined that node 3 is the target access node, and the access to the circular linked list is terminated. Here, in the art, "node" may sometimes be referred to as "node".
[0044] Figure 2 In the figure, the nodes on the circular linked list are accessed counterclockwise. This is just one implementation method. Of course, the nodes on the circular linked list can also be accessed clockwise.
[0045] In the embodiment of the present invention, the linked list of the hash map is a circular linked list. Without modifying the linked list, even if the node pointed to by the head pointer is changed, the nodes of the entire linked list can be traversed. However, for a one-way linked list, if the head pointer of the one-way linked list points to a node in the middle of the linked list, it is impossible to traverse each node of the linked list.
[0046] The head pointer of the circular linked list of the embodiment of the present invention can be flexibly switched, and the head pointer points to any node in the circular linked list, so as to meet the data access requirements and improve the data access efficiency. If the head pointer points to the node where the hot data is located, then in most cases, the data to be accessed can be obtained by accessing the node pointed to by the head pointer, which effectively improves the access efficiency.
[0047] In one embodiment of the present invention, the data access method further includes: pointing the head pointer to the node where the hot data is located in the circular linked list.
[0048] If the node where the hot data is located changes, the head pointer is switched from one node of the circular linked list to another node of the circular linked list.
[0049] In one embodiment of the present invention, the data access method is applied in a cache memory (cache), and nodes (items) are cached in the cache service. The length of the node linked list is about 8 to 12 on average.
[0050] Since the percentage of the number of accesses to the node where the hot data is located in the total number of accesses to the node is greater than or equal to a threshold, for example, the threshold is 80%, that is, the access frequency of the node where the hot data is located is very high. If the head pointer points to the node where the hot data is located, then in most cases, the node pointed to by the head pointer is the target access node, and the required data can be obtained by accessing the node pointed to by the head pointer, which effectively improves the access efficiency, reduces the access overhead of hot data, and significantly improves the performance of the cache.
[0051] The cache is specially provided for cache services, or integrated into the database, such as the graph database GDB. If the access frequency of 20% of the data in the cache service accounts for 80% of the total access, then this 20% of the data is hot data. The embodiment of the present invention optimizes the performance of cache hotspot access, the access delay of hot data is more than 50% higher than that of cold data, the single-thread performance reaches 4Mqps, and does not affect the access delay of cold data, and there is no additional statistical overhead and memory overhead.
[0052] In one embodiment of the present invention, there are at least three ways to obtain the node where the hot data is located.
[0053] Method 1
[0054] If the target access node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list, the node where the hot data is located is the target access node of the current access to the circular linked list.
[0055] It should be noted that if the target access node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list, that is, the purpose of accessing the circular linked list twice in a row is to access the same node of the circular linked list, it means that the node is the node where the hot data is located.
[0056] As an example, the target access node of two visits is determined by the hash value of the node. If the hash value of the target access node of the last visit to the circular linked list is the same as the hash value of the target access node of the current visit to the circular linked list, then the target access node of the last visit to the circular linked list is the same as the target access node of the current visit to the circular linked list.
[0057] In addition, the hash value and the head pointer of the target access node of the last access to the circular linked list are stored in at least one byte, that is, the hash value and the head pointer of the target access node of the last access to the circular linked list are stored together.
[0058] For example, physically, the hash value of the target access node of the last access to the circular linked list and the head pointer are stored in an 8-byte array, so that the head pointer and the hash value of the target access node of the last access to the circular linked list can be obtained in one read without increasing the memory access overhead.
[0059] After obtaining the hash value of the target access node of the last access to the circular linked list, it is determined whether the hash value of the target access node of the current access to the circular linked list is the same as the hash value of the target access node of the last access to the circular linked list.
[0060] If they are the same, move the head pointer to the target access node of this access to the circular linked list, that is, move the head pointer to the target access node of the last access to the circular linked list. If they are not the same, record the hash value of the target access node of this access to the circular linked list.
[0061] Method 2
[0062] The most recently accessed node in the circular linked list is the node where the hot data is located.
[0063] For example, for Figure 2 The circular linked list shown in FIG. 1 shows a node 3 in the circular linked list, which is the target access node, and the access to the circular linked list is terminated. In this case, the node most recently accessed in the circular linked list is node 3, and node 3 is used as the node where the hot data is located.
[0064] Method 3
[0065] The target access node with the most access times in the circular linked list is the node where the hot data is located.
[0066] For example, for Figure 2 The circular linked list shown in the figure counts the latest five visits to the circular linked list. For the first three visits, the access to the circular linked list was stopped when the node 2 of the circular linked list was accessed, that is, the target access node for the first three visits was node 2; for the fourth visit, the access to the circular linked list was stopped when the node 5 of the circular linked list was accessed, that is, the target access node for the fourth visit was node 5; for the fifth visit, the access to the circular linked list was stopped when the node 2 of the circular linked list was accessed, that is, the target access node for the fifth visit was node 2.
[0067] It can be seen that in the last five accesses to the circular linked list, the target access node with the most accesses is node 2, which is the node where the hot data is located, and the head pointer points to node 2.
[0068] The effects of the embodiments of the present invention are described in detail below.
[0069] Assume that the circumference of the linked list is 5, that is, there are 5 nodes in the linked list, the data is evenly placed in each node, and the access model follows the 28 distribution, as shown in Table 1:
[0070] Table 1
[0071] Hot Data Cold Data Data ratio 0.2 0.8 Visit ratio 0.8 0.2
[0072] In Table 1, for the data stored in the entire linked list, 20% of the data is hot data, 80% of the data is cold data, the number of accesses to the hot data accounts for 80% of the total number of accesses, and the number of accesses to the cold data accounts for 20% of the total number of accesses.
[0073] 1. When the linked list is a one-way linked list
[0074] (1) Access the head pointer of the singly linked list once.
[0075] (2) In the process of accessing the nodes of the singly linked list, since the chain length of the singly linked list is 5, the average number of accesses to the nodes of the singly linked list is 2.5 times.
[0076] For example, when a singly linked list is accessed for the first time, the second node of the singly linked list is the target access node, so the number of visits to the node of the singly linked list for the first time is 2 times; when the singly linked list is accessed for the second time, the fifth node of the singly linked list is the target access node, so the number of visits to the node of the singly linked list for the second time is 5 times; and so on, after a large number of visits, it can be concluded that the average number of visits to the nodes of the singly linked list is 2.5 times.
[0077] Combining the above two points (1) and (2), it can be seen that in the process of accessing the singly linked list, the average number of accesses to the singly linked list is 1+2.5=3.5 times.
[0078] 2. When the linked list is a circular linked list
[0079] (1) For access to hot data, data access includes: accessing the head pointer of the circular linked list once; accessing the node pointed to by the head pointer. Since the node pointed to by the head pointer is the node where the hot data is located, the node of the circular linked list is accessed once.
[0080] From the above, it can be seen that the number of accesses to hot data is 1+1=2 times.
[0081] (2) For access to cold data, data access includes: accessing the head pointer of the circular linked list once; accessing the circular linked list starting from the node pointed to by the head pointer. Since the length of the circular linked list is 5, the average number of times the target access node in the circular linked list is accessed is 2.5 times.
[0082] From the above, it can be seen that the average number of accesses to cold data is 1+2.5=3.5 times.
[0083] Combining (1) and (2) above, since 80% of the accesses in Table 1 are to hot data and 20% of the accesses are to cold data, the average number of accesses to the circular linked list is 0.8×2+0.2×3.5=2.3 times during the access to the circular linked list.
[0084] Compared with the average number of accesses to a singly linked list, the average number of accesses to a circular linked list is reduced by 34%.
[0085] Another scenario different from the scenario in Table 1: 80% of accesses are to hot data, 15% of accesses are to cold data, and 5% of accesses are to failure to access required data.
[0086] (1) For access to hot data, the number of accesses to the hot data is 1+1=2 times.
[0087] (2) For access to cold data, the average number of accesses to cold data is 1+2.5=3.5 times.
[0088] The number of accesses to hot data and the number of accesses to cold data have been described in detail above, and will not be repeated here.
[0089] (3) For the required data that is not accessed, data access includes: accessing the head pointer of the circular linked list once; accessing the circular linked list starting from the node pointed to by the head pointer, and accessing the last node of the circular linked list. Therefore, the number of accesses to the nodes of the circular linked list is 5 times.
[0090] From the above, it can be seen that when the required data is not accessed in the circular linked list, the number of accesses is 1+5=6 times.
[0091] Combining (1)-(3) above, in the scenario where 5% of accesses do not access the required data, the average number of accesses to the circular linked list is 0.8×2+0.15×3.5+0.05×6=2.425 times.
[0092] Compared with the average number of accesses to a singly linked list, the average number of accesses to a circular linked list is reduced by 31%.
[0093] From the above analysis, it can be seen that compared with the average number of accesses to a one-way linked list, the average number of accesses to a circular linked list is relatively small, which can effectively improve the access efficiency of the linked list.
[0094] The advantages of the circular linked list are further illustrated by experimental results below.
[0095] Figure 3 Schematic diagram of Zipfian distribution performance when θ=0.99, where θ represents the access frequency of hot data, and the larger θ is, the greater the access frequency of hot data is.
[0096] Figure 3 (a) is a schematic diagram of the Zipf distribution performance in the case of read-only and θ = 0.99. Figure 3 (b) is a schematic diagram of the Zipf distribution performance when there are 50% reads and 50% writes and θ = 0.99. The three types of linked lists are a circular linked list, a one-way linked list, and a linked list based on a hash map (HashMap).
[0097] Figure 4 Schematic diagram of the Zipf distribution performance when θ = 1.22.
[0098] Figure 4 (a) is a schematic diagram of the Zipf distribution performance in the case of read-only and θ = 1.22. Figure 4 (b) is a schematic diagram of the Zipf distribution performance when there are 50% reads and 50% writes and θ=1.22.
[0099] from Figure 3 and Figure 4It can be seen that based on the access under Zipfian distribution, the throughput corresponding to the circular linked list is larger than that of other linked lists, especially when θ=1.22, the advantage of the circular linked list is more obvious because there is no need to deviate from the memory, so that the central processing unit (CPU) can cache hot data.
[0100] Figure 5 Schematic diagram of uniform distribution performance.
[0101] Figure 5 (a) is a schematic diagram of uniformly distributed performance in the read-only case. Figure 5 (b) is a schematic diagram of uniformly distributed performance when there are 50% reads and 50% writes.
[0102] from Figure 5 It can be seen that the performance comparison of the three linked lists under uniform data distribution shows that there is no distinction between cold data and hot data. The performance of the circular linked list is basically the same as that of the one-way linked list. This shows that the design of the circular linked list does not have a bad impact on data access.
[0103] exist Figures 3 to 5 In the figure, the horizontal axis represents the circumference of the linked list, which is the ratio of the key to the bucket. The vertical axis represents the throughput, and the unit of throughput is M ops / sec.
[0104] Figure 6 A schematic diagram of a data access principle provided by an embodiment of the present invention.
[0105] exist Figure 6 In the hashmap, each bucket contains a 6-byte head pointer and a 2-byte hash value, which is the hash value of the target access node of the last access to the circular linked list.
[0106] Memory allocator is the memory management part. Each slab manager is responsible for allocating a certain size of memory, for example, slab0 allocates 32 bytes of memory. Slab manager first requests a 1MB continuous memory page (full page) from the system, and then cuts it according to a fixed size, for example, slab0 is cut according to 32 bytes to get partial pages. When hashmap needs memory, it takes memory from the slab of the appropriate size.
[0107] Garbage collection and memory defragmentation can also be implemented.
[0108] Memory pre-allocation is to pre-allocate a portion of memory to each thread, reduce the memory allocation competition pressure of Memory Allocator, and improve performance.
[0109] Figure 7 FIG. 1 is a flow chart of a data access method according to another embodiment of the present invention. Figure 7 As shown, the data access method includes:
[0110] S201, in a linked list of a hash map, determine the node pointed to by the first pointer of the linked list, wherein the first pointer is a pointer other than the head pointer.
[0111] The linked list may include a unidirectional linked list, or a bidirectional linked list.
[0112] S202, when the node pointed to by the first pointer is the target access node, if the node pointed to by the first pointer is accessed, the access to the linked list is terminated.
[0113] In the embodiment of the present invention, in addition to the head pointer, the linked list also has an additional pointer, namely the first pointer, which points to a node in the linked list. The pointing of the first pointer can be flexibly switched, that is, the node pointed to by the first pointer can be changed, and the first pointer can point to any node in the linked list, so as to meet the data access requirements and improve the data access efficiency.
[0114] If the first pointer points to the node where the hot data in the linked list is located, when accessing the linked list, the node pointed to by the first pointer is accessed first, that is, the node where the hot data is located is accessed first. If the node where the hot data is located is the target access node, then accessing a node will obtain the required data, and the access to the linked list will be ended, which effectively improves the access efficiency.
[0115] In one embodiment of the present invention, the method further includes: if the node pointed to by the first pointer is not the target access node, accessing the one-way linked list according to the node pointed to by the head pointer of the linked list.
[0116] For example, in Figure 8In the example, the head pointer of the singly linked list points to node 1, and the first pointer of the singly linked list points to node 3. When accessing the nodes of the singly linked list, first visit node 3 to determine whether node 3 is the target access node; if the node is the target access node, then after visiting node 3, the access to the singly linked list ends; if node 3 is not the target access node, start from node 1 pointed to by the head pointer and visit the nodes of the singly linked list in sequence until the target access node is visited.
[0117] In one example, if the node pointed to by the first pointer is not the target access node, and the node pointed to by the first pointer is the same as the node pointed to by the head pointer, then after visiting the node pointed to by the first pointer, the linked list is accessed starting from the node pointed to by the head pointer, that is, the first node of the linked list is visited twice.
[0118] In another example, if the node pointed to by the first pointer is not the target access node, and the node pointed to by the first pointer is the same as the node pointed to by the head pointer, then after visiting the node pointed to by the first pointer, visit the node after the node, and do not visit the same node twice in a row, thus saving one visit.
[0119] In one embodiment of the present invention, the node pointed to by the first pointer can be changed, that is, the data access method further includes: switching the pointing of the first pointer from one node in the linked list to another node in the linked list.
[0120] The node pointed to by the first pointer is the node where the hot data is located. There are at least three ways to obtain the node where the hot data is located.
[0121] Method 1
[0122] If the target access node of the last access list is the same as the target access node of the current access list, the node where the hot data is located is the target access node of the current access list (or the target access node of the last access list), that is, the first pointer points to the target access node of the current access list.
[0123] It should be noted that if the target access node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list, that is, the purpose of accessing the circular linked list twice in a row is to access the same node of the circular linked list, it means that the node is the node where the hot data is located.
[0124] The hash value of the node is used to determine whether the target access node of the two visits is the same. If the hash value of the target access node of the last access to the linked list is the same as the hash value of the target access node of the current access to the linked list, then the target access node of the last access to the linked list is the same as the target access node of the current access to the linked list.
[0125] In addition, the hash value and the head pointer of the target access node of the last access to the linked list are stored in at least one byte, that is, the hash value and the head pointer of the target access node of the last access to the linked list are stored together.
[0126] For example, physically, the hash value of the target access node of the last access to the linked list and the head pointer are stored in an 8-byte array, so that the head pointer and the hash value of the target access node of the last access to the linked list can be obtained in one read without increasing the memory access overhead.
[0127] After obtaining the hash value of the target access node of the last access list, determine whether the hash value of the target access node of the current access list is the same as the hash value of the target access node of the last access list. If they are the same, move the head pointer to the target access node of the current access list, that is, move the head pointer to the target access node of the last access list. If they are not the same, record the hash value of the target access node of the current access list.
[0128] Method 2
[0129] The node where the hot data is located is the node that was most recently accessed in the linked list. The first pointer points to the node that was most recently accessed in the linked list.
[0130] For example, for Figure 8 In the one-way linked list, if node 4 in the one-way linked list is accessed and the current access to the one-way linked list is stopped, node 4 is the node visited most recently, and node 4 is also the target access node of the current access to the one-way linked list, then the first pointer points to node 4. If the next time the one-way linked list is accessed, node 5 is accessed and the current access to the one-way linked list is stopped, the first pointer is switched from node 4 to node 5.
[0131] Method 3
[0132] The node where the hot data is located is the target access node with the most access times in the linked list. The first pointer points to the target access node with the most access times in the linked list.
[0133] For example, for Figure 8 For the one-way linked list in , statistics are given for the last five visits to the one-way linked list. The first three visits stop the visit to the one-way linked list when the node 2 of the one-way linked list is visited, i.e., the target node of the first three visits is node 2; the fourth visit stops the visit to the one-way linked list when the node 5 of the one-way linked list is visited, i.e., the target node of the fourth visit is node 5; the fifth visit stops the visit to the one-way linked list when the node 2 of the one-way linked list is visited, i.e., the target node of the fifth visit is node 2.
[0134] It can be seen that in the last five accesses to the one-way linked list, the target access node with the most accesses is node 2, which is the node where the hot data is located, and the first pointer points to node 2.
[0135] The effects of the embodiments of the present invention are described in detail below using a one-way linked list as an example.
[0136] Assume that the perimeter of a one-way linked list is 5, that is, there are 5 nodes in the one-way linked list, and the data is evenly placed in each node. The access model follows the 80-20 distribution, as shown in Table 2:
[0137] Table 2
[0138] Hot Data Cold Data Data ratio 0.2 0.8 Visit ratio 0.8 0.2
[0139] In Table 2, for the data stored in the entire one-way linked list, 20% of the data is hot data, 80% of the data is cold data, the number of accesses to the hot data accounts for 80% of the total number of accesses, and the number of accesses to the cold data accounts for 20% of the total number of accesses.
[0140] (1) For access to hot data, data access includes: accessing the head pointer of the one-way linked list once; accessing the node pointed to by the first pointer of the one-way linked list once. Since the node pointed to by the first pointer is the node where the hot data is located, that is, the node pointed to by the first pointer is the target access node, therefore, the node of the one-way linked list is accessed once.
[0141] From the above, it can be seen that the number of accesses to hot data is 1+1=2 times.
[0142] (2) For access to cold data, data access includes: accessing the head pointer of the one-way linked list once; accessing the node pointed to by the first pointer of the one-way linked list once; since the node pointed to by the first pointer is not the target access node, the one-way linked list is accessed starting from the node pointed to by the head pointer. Since the length of the one-way linked list is 5, the average number of times the target access node in the one-way linked list is accessed is 2.5 times.
[0143] From the above, it can be seen that the average number of accesses to cold data is 1+1+2.5=4.5 times.
[0144] Combining (1) and (2) above, since 80% of the accesses in Table 1 are to hot data and 20% of the accesses are to cold data, the average number of accesses to the one-way linked list is 0.8×2+0.2×4.5=2.3 times.
[0145] It has been calculated above that the average number of accesses to a singly linked list without a first pointer is 1+2.5=3.5 times.
[0146] In comparison, the average number of accesses to the singly linked list with the first pointer is reduced by 34% compared to the average number of accesses to the singly linked list without the first pointer.
[0147] Fig. 9 FIG. 1 is a block diagram of a data access device according to an embodiment of the present invention. Fig. 9 As shown, the data access device 300 includes a node determination module 301 and a linked list access module 302 .
[0148] The node determination module 301 is used to determine the node pointed to by the head pointer of the circular linked list in the hash map circular linked list.
[0149] The linked list access module 302 is used to access the circular linked list according to the node pointed to by the head pointer.
[0150] In one embodiment of the present invention, the data access device 300 further includes a pointer pointing module.
[0151] The pointer pointing module is used to point the head pointer to the node where the hot data in the circular linked list is located.
[0152] In one embodiment of the present invention, if the target access node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list, the node where the hot data is located is the target access node of the current access to the circular linked list.
[0153] In one embodiment of the present invention, if the hash value of the target access node of the last access to the circular linked list is the same as the hash value of the target access node of the current access to the circular linked list, then the target node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list.
[0154] In one embodiment of the present invention, the hash value and the head pointer of the target access node of the last access to the circular linked list are stored in at least one byte.
[0155] In one embodiment of the present invention, the node where the hot data is located is the node that was most recently accessed in the circular linked list.
[0156] In one embodiment of the present invention, the node where the hot data is located is the target access node with the largest number of accesses in the circular linked list.
[0157] In one embodiment of the present invention, a pointer of each node in the plurality of nodes of the circular linked list points to the next node, so that the plurality of nodes are arranged in sequence, and a pointer of the last node points to the first node, to form a circular linked list.
[0158] Fig.10 FIG. 1 is a block diagram of a data access device according to another embodiment of the present invention. Fig.10As shown, the data access device 400 includes a node determination module 401 and a first access module 402 .
[0159] The node determination module 401 is used to determine, in the linked list of the hash map, the node pointed to by the first pointer of the linked list, wherein the first pointer is a pointer other than the head pointer.
[0160] The first access module 402 is used to terminate the access to the linked list if the node pointed to by the first pointer is the target access node and the node pointed to by the first pointer is accessed.
[0161] In one embodiment of the present invention, the data access device 400 further includes a second access module.
[0162] The second access module is used to access the linked list according to the node pointed to by the head pointer of the linked list when the node pointed to by the first pointer is not the target access node.
[0163] In one embodiment of the present invention, the first pointer points to the most recently visited node in the linked list.
[0164] In one embodiment of the present invention, if the target access node of the last access linked list is the same as the target access node of the current access linked list, the first pointer points to the target access node of the current access linked list.
[0165] In one embodiment of the present invention, the first pointer points to the target access node with the most access times in the linked list.
[0166] In one embodiment of the present invention, the data access device 400 further includes a pointer pointing switching module.
[0167] The pointer pointing switching module is used to switch the pointing of the first pointer from one node of the linked list to another node of the linked list.
[0168] Fig.11 A schematic diagram of the hardware structure of a computing device according to an embodiment of the present invention.
[0169] The computing device may include a processor 501 and a memory 502 storing computer program instructions.
[0170] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiment of the present invention.
[0171] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 502 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory. In a specific embodiment, the memory 502 includes a read-only memory (ROM). In appropriate cases, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM) or a flash memory or a combination of two or more of these.
[0172] The processor 501 implements any one of the data access methods in the above embodiments by reading and executing computer program instructions stored in the memory 502 .
[0173] In one example, the computing device may further include a communication interface 503 and a bus 510. Fig.11 As shown, the processor 501, the memory 502, and the communication interface 503 are connected via a bus 510 and communicate with each other.
[0174] The communication interface 503 is mainly used to implement the communication between the modules, devices, units and / or equipment in the embodiment of the present invention.
[0175] Bus 510 includes hardware, software or both, and the parts of computing device are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 510 may include one or more buses. Although the embodiment of the present invention describes and shows a specific bus, the present invention considers any suitable bus or interconnection.
[0176] The computing device can execute the data access method in the embodiment of the present invention, thereby realizing the combination Figure 1 , Figure 7 , Fig. 9 , Fig.10 Described is a data access method and apparatus.
[0177] In addition, in combination with the data access method in the above embodiment, the embodiment of the present invention can provide a computer storage medium to implement. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the data access methods in the above embodiment is implemented.
[0178] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.
[0179] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0180] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.
[0181] The above is only a specific implementation of the present invention. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the system, module and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be covered within the protection scope of the present invention.
Claims
1. A data access method, the method comprising: In the circular linked list of the hash map, determining the node pointed to by the head pointer of the circular linked list, wherein the head pointer points to the node where the hot data in the circular linked list is located; The circular linked list is accessed according to the node pointed to by the head pointer.
2. The method according to claim 1, wherein: If the target access node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list, the node where the hot data is located is the target access node of the current access to the circular linked list.
3. The method according to claim 2, wherein: If the hash value of the target access node of the last access to the circular linked list is the same as the hash value of the target access node of the current access to the circular linked list, then the target node of the last access to the circular linked list is the same as the target access node of the current access to the circular linked list; The hash value of the target access node of the last access to the circular linked list and the head pointer are stored in at least one byte.
4. The method according to claim 1, wherein: The node where the hot data is located is the node that was most recently accessed in the circular linked list.
5. The method according to claim 1, wherein: The node where the hot data is located is the target access node with the largest number of accesses in the circular linked list.
6. A data access method, the method comprising: In a linked list of a hash map, determining a node pointed to by a first pointer of the linked list, wherein the first pointer points to a node where hot data in the linked list is located, wherein the first pointer is a pointer other than a head pointer; In the case that the node pointed to by the first pointer is the target access node, if the node pointed to by the first pointer is accessed, the access to the linked list is terminated.
7. The method according to claim 6, wherein: Also includes: If the node pointed to by the first pointer is not the target access node, the linked list is accessed according to the node pointed to by the head pointer of the linked list.
8. The method according to claim 6, wherein: The node where the hot data is located is the node in the linked list that was accessed most recently.
9. The method according to claim 6, wherein: If the target access node of the last access to the linked list is the same as the target access node of the current access to the linked list, the node where the hot data is located is the target access node of the current access to the linked list.
10. The method according to claim 6, wherein: The node where the hot data is located is the target access node with the largest number of accesses in the linked list.
11. A data access device, comprising: A node determination module, used to determine, in a circular linked list of a hash map, a node pointed to by a head pointer of the circular linked list, wherein the head pointer points to a node where hot data in the circular linked list is located; The linked list access module is used to access the circular linked list according to the node pointed to by the head pointer.
12. A data access device, comprising: A node determination module, used to determine, in a linked list of a hash map, a node pointed to by a first pointer of the linked list, wherein the first pointer points to a node where hot data in the linked list is located, wherein the first pointer is a pointer other than a head pointer; The access module is used to terminate the access to the linked list if the node pointed to by the first pointer is the target access node and the node pointed to by the first pointer is accessed.
13. A computing device, the device comprising: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the data access method according to any one of claims 1 to 10 is implemented.
14. A computer storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed by a processor, implement the data access method according to any one of claims 1 to 10.
