CN108287840B - A Data Storage and Query Method Based on Matrix Hash - Google Patents
A Data Storage and Query Method Based on Matrix Hash Download PDFInfo
- Publication number
- CN108287840B CN108287840B CN201710014205.9A CN201710014205A CN108287840B CN 108287840 B CN108287840 B CN 108287840B CN 201710014205 A CN201710014205 A CN 201710014205A CN 108287840 B CN108287840 B CN 108287840B
- Authority
- CN
- China
- Prior art keywords
- sub
- key
- tables
- bit
- bloom filter
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2255—Hash tables
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明涉及一种基于矩阵哈希的数据存储和查询方法。该方法包括:1)建立哈希表数据结构,其包含z个子表,z是偶数,各子表的大小等差递减;对于
将第i个子表和第z‑i+1个子表结合,得到个大小相等的子表;2)建立辅助数据结构,其包含与所述z个子表对应的z个布隆过滤器,各布隆过滤器的大小等差递减;对于将第i个布隆过滤器和第z‑i+1个布隆过滤器结合,得到个大小相等的布隆过滤器;然后将该个布隆过滤器的对应比特追加在一起,形成1个多比特布隆过滤器;3)利用所述哈希表数据结构和所述辅助数据结构插入键值对,实现数据存储。本发明能够实现快速更新和快速查询。The invention relates to a data storage and query method based on matrix hash. The method includes: 1) establishing a hash table data structure, which includes z sub-tables, z is an even number, and the sizes of the sub-tables decrease equally;
Combining the i-th sub-table with the z-i+1-th sub-table, we get 2) establish an auxiliary data structure, which includes z bloom filters corresponding to the z sub-tables, and the sizes of each bloom filter are equidistantly decreasing; for Combining the i-th Bloom filter with the z‑i+1-th Bloom filter, we get Bloom filters of equal size; then the Corresponding bits of each Bloom filter are added together to form a multi-bit Bloom filter; 3) Key-value pairs are inserted by using the hash table data structure and the auxiliary data structure to realize data storage. The present invention can realize fast update and fast query.Description
技术领域technical field
本发明属于内存数据库技术领域,特别涉及一种基于矩阵哈希算法的数据组织、索引、存储方法。The invention belongs to the technical field of in-memory databases, and in particular relates to a data organization, index and storage method based on a matrix hash algorithm.
背景技术Background technique
内存数据库相比于磁盘数据库具有较高的灵活性和易用性,内存数据库从范型上可以分为关系型内存数据库和键值型内存数据库。基于键值的内存数据库(Key ValueStore)具有灵活简洁、节省内存、快速查询等优点,相比于基于关系型的内存数据库有独特优势,因而被广泛应用在各大互联网公司,比如在亚马逊、Facebook、Youtube、百度、新浪、搜狐等。键值存储系统的数据是以键值对的形式存在,并且用哈希表来进行存储,因此哈希算法作为键值存储系统的核心技术,是直接影响系统性能和网站效率的关键因素。Compared with disk database, in-memory database has higher flexibility and ease of use. In-memory database can be divided into relational in-memory database and key-value in-memory database from the paradigm. The key-value-based in-memory database (Key ValueStore) has the advantages of flexibility and simplicity, saving memory, and fast query. Compared with the relational in-memory database, it has unique advantages, so it is widely used in major Internet companies, such as Amazon, Facebook , Youtube, Baidu, Sina, Sohu, etc. The data of the key-value storage system exists in the form of key-value pairs and is stored in a hash table. Therefore, the hash algorithm, as the core technology of the key-value storage system, is a key factor that directly affects the system performance and website efficiency.
目前存在的实际问题是,随着互联网快速发展,很多互联网公司都积累了大量的数据,由于键值对的数量巨大,而可供使用的内存空间却是有限的,因此当插入一个新的键值对时,键值对的冲突会比较多。这样的冲突会导致新键值对的插入失败、已有键值对的更新查找失败等问题,大大影响了键值存储系统的性能,因而对使用键值存储系统的互联网公司造成较大的经济损失。The actual problem at present is that with the rapid development of the Internet, many Internet companies have accumulated a large amount of data. Due to the huge number of key-value pairs, the available memory space is limited, so when a new key is inserted When the value is paired, the conflict of the key-value pair will be more. Such conflicts will lead to the failure of inserting new key-value pairs, the failure of updating and searching of existing key-value pairs, etc., which greatly affects the performance of the key-value storage system, thus causing great economic losses to Internet companies using the key-value storage system. loss.
同时,客户对数据操作的需求和要求越来越高,需要快速得到数据的查询结果,因而对互联网公司的响应能力提出较高要求,如果互联网公司不能做到即时响应,将会大大影响用户体验。At the same time, customers have higher and higher demands and requirements for data operations, and they need to quickly obtain data query results. Therefore, higher requirements are placed on the responsiveness of Internet companies. If Internet companies cannot respond immediately, it will greatly affect the user experience. .
以上两个问题广泛存在各大应用键值存储系统的互联网公司中,现有的哈希表设计也不断尝试新的思路以更好的解决这两个关键问题。首先针对冲突问题,已有的哈希表设计广泛通过辅助的数据结构(比如布隆过滤器)减少冲突概率。比较典型的算法设计是快速哈希(fast hash table)(H.Song,S.Dharmapurikar,J.Turner,and J.Lockwood.Fasthash table lookup using extended bloom filter:an aid to networkprocessing.ACM SIGCOMM Computer Communication Review,35(4):181–192,2005.),分段哈希(segment hash)(S.Kumar and P.Crowley.Segmented hash:an efficient hashtable implementation for high performance networking subsystems.In Proc.ACMANCS,pages 91–103,2005.),孔雀哈希(peacock hash)(S.Kumar,J.Turner,andP.Crowley.Peacock hashing:Deterministic and updatable hashing for highperformance networking.In Proc.IEEE INFOCOM,2008.)。对于一个需要插入的新键值对,这些哈希设计都使用布隆过滤器来决定待插入的哈希表。对于冲突的键值对,要么使用指针挂在链表上,要么丢弃。这些哈希设计虽然使用多子表来减少冲突,但是仍然存在缺点,比如较低的装载率。冲突率也还有较大的减少空间。The above two problems widely exist in major Internet companies applying key-value storage systems, and the existing hash table designs are constantly trying new ideas to better solve these two key problems. First of all, for the conflict problem, the existing hash table designs widely use auxiliary data structures (such as Bloom filters) to reduce the conflict probability. A typical algorithm design is fast hash table (H. Song, S. Dharmapurikar, J. Turner, and J. Lockwood. Fasthash table lookup using extended bloom filter: an aid to network processing. ACM SIGCOMM Computer Communication Review , 35(4):181–192, 2005.), segment hash (S.Kumar and P.Crowley.Segmented hash: an efficient hashtable implementation for high performance networking subsystems.In Proc.ACMANCS,pages 91–103, 2005.), peacock hash (S. Kumar, J. Turner, and P. Crowley. Peacock hashing: Deterministic and updatable hashing for highperformance networking. In Proc. IEEE INFOCOM, 2008.). For a new key-value pair that needs to be inserted, these hash designs use Bloom filters to determine the hash table to insert. For conflicting key-value pairs, either use a pointer to hang on the linked list, or discard it. Although these hash designs use multiple subtables to reduce collisions, there are still drawbacks, such as lower load rates. There is also a large room for reduction in the conflict rate.
其次是查询时间问题,比较典型的哈希设计有完美哈希(Z.J.Czech,G.Havas,andB.S.Majewski.An optimal algorithm for generating minimal perfect hashfunctions.Information Processing Letters,43(5):257–264,1992.)、布谷鸟哈希(B.Fan,D.G.Andersen,and M.Kaminsky.Memc3:Compact and concurrent memcache withdumber caching and smarter hashing.In NSDI,volume 13,pages 385–398,2013.)等,然而这些哈希的缺点在于更新时十分低效,需要大量的哈希计算和内存访问。比如,布谷鸟哈希在更新哈希表时需要近500次哈希计算和内存访问,即使如此,也很有可能更新失败。因此对于这些哈希表设计,如果多次更新失败,则将不得不重建整个哈希表。重建过程将会需要大量时间,对于现实的应用系统是无法接受的。The second is the query time problem. The typical hash design is perfect hash (Z.J.Czech,G.Havas,andB.S.Majewski.An optimal algorithm for generating minimal perfect hashfunctions.Information Processing Letters,43(5):257– 264, 1992.), Cuckoo Hash (B.Fan,D.G.Andersen,and M.Kaminsky.Memc3:Compact and concurrent memcache withdumber caching and smarter hashing.In NSDI,volume 13,pages 385–398,2013.), etc. However, the disadvantage of these hashes is that they are very inefficient to update, requiring a large number of hash calculations and memory accesses. For example, cuckoo hashing requires nearly 500 hash calculations and memory accesses when updating the hash table, and even then, there is a high chance that the update will fail. So with these hash table designs, if multiple updates fail, the entire hash table will have to be rebuilt. The reconstruction process will take a lot of time, which is unacceptable for real application systems.
发明内容SUMMARY OF THE INVENTION
为解决哈希表冲突和查询时间问题,克服已有哈希表存在的高冲突率、低内存使用效率、低装载率等缺陷,本发明提供一种将多子表哈希、布隆过滤器、位图相结合的新的哈希表设计方案—“矩阵哈希”。In order to solve the problem of hash table conflict and query time, and overcome the defects of high conflict rate, low memory usage efficiency, low loading rate, etc. existing in the existing hash table, the present invention provides a multi-subtable hash and bloom filter. , a new hash table design scheme combined with bitmap - "Matrix Hash".
本发明采用的技术方案如下:The technical scheme adopted in the present invention is as follows:
一种基于矩阵哈希的数据存储方法,其特征在于,包括以下步骤:A data storage method based on matrix hash, is characterized in that, comprises the following steps:
1)建立哈希表数据结构,其包含z个子表,z是偶数,各子表的大小等差递减;对于将第i个子表和第z-i+1个子表结合,得到个大小相等的子表;1) Establish a hash table data structure, which includes z sub-tables, z is an even number, and the size of each sub-table decreases equally; for Combining the i-th sub-table with the z-i+1-th sub-table, we get subtables of equal size;
2)建立辅助数据结构,其包含与所述z个子表对应的z个布隆过滤器,各布隆过滤器的大小等差递减;对于将第i个布隆过滤器和第z-i+1个布隆过滤器结合,得到个大小相等的布隆过滤器;然后将该个布隆过滤器的对应比特追加在一起,形成1个多比特布隆过滤器;2) establish an auxiliary data structure, which comprises z bloom filters corresponding to the z sub-tables, and the size of each bloom filter is equidistantly decreasing; for Combining the i-th bloom filter and the z-i+1-th bloom filter, we get Bloom filters of equal size; then the The corresponding bits of each Bloom filter are appended together to form a multi-bit Bloom filter;
3)利用所述哈希表数据结构和所述辅助数据结构插入键值对,实现数据存储。3) Using the hash table data structure and the auxiliary data structure to insert key-value pairs to realize data storage.
进一步地,每当插入一个新的键值对时,将其插入到装载率最小的子表中。Further, whenever a new key-value pair is inserted, it is inserted into the child table with the smallest load rate.
进一步地,在最后一个子表即第z个子表上挂链表,如果待插入的键值对找不到一个空桶,则使用指针将其挂在链表上。Further, a linked list is attached to the last sub-table, that is, the z-th sub-table. If the key-value pair to be inserted cannot find an empty bucket, a pointer is used to attach it to the linked list.
进一步地,每个子表有一个位图相对应,位图中的每一个比特与其对应子表中的的一个桶相对应;空桶对应位图中的比特为0,非空桶对应位图中的比特为1。Further, each subtable corresponds to a bitmap, and each bit in the bitmap corresponds to a bucket in its corresponding subtable; the bit in the bitmap corresponding to an empty bucket is 0, and the bitmap corresponding to a non-empty bucket is 0. bit is 1.
进一步地,增加一个额外的布隆过滤器Fhalf,其负责记录子表的第二部分,即以减少查询的子表数。Further, add an additional bloom filter F half , which is responsible for recording the second part of the subtable, namely to reduce the number of subtables queried.
进一步地,键值对的插入方式如下:Further, key-value pairs are inserted as follows:
a)对于一个给定的键值对,首先通过位图检查z个候选桶是否为空,然后将键值对插入到装载率最低的子表中,以平衡所有子表装载率;假设要插入的子表索引为i,如果则更新布隆过滤器Fi来表示键x在子表Ti中,并更新对应位图;如果则更新布隆过滤器Fz-i+1来表示x在子表Ti中,并更新Fhalf和对应位图;a) For a given key-value pair, first check whether the z candidate buckets are empty through the bitmap, and then insert the key-value pair into the child table with the lowest loading rate to balance the loading rate of all child tables; The subtable index of i is i, if Then update the Bloom filter F i to indicate that the key x is in the sub-table T i , and update the corresponding bitmap; if Then update the Bloom filter F z-i+1 to represent that x is in the sub-table T i , and update F half and the corresponding bitmap;
b)如果位图显示键x应该插入的z个桶均已满,则使用踢的机制实现键值对的插入。b) If the bitmap shows that the z buckets into which the key x should be inserted are all full, then use the kick mechanism to implement key-value pair insertion.
进一步地,键值对的查询方式为:在查询x时,首先在多比特布隆过滤器Fm和Fhalf中查询x,如果返回true,且Fhalf返回false,则检查子表Ti;否则,先检查子表Tz-i+1,如果没有匹配,再检查子表Ti;如果在z个子表中都无法查找到x,则查找最后一个子表的链表;如果仍然无法找到,则说明x不在哈希表中。Further, the query method of key-value pairs is: when querying x, first query x in the multi-bit Bloom filters F m and F half , if Returns true, and F half returns false, then check the sub-table T i ; otherwise, check the sub-table T z-i+1 first , if there is no match, then check the sub-table T i ; if none of the z sub-tables can be found x, then look up the linked list of the last sublist; if it still cannot be found, it means that x is not in the hash table.
进一步地,键值对的删除方式为:在删除x时,首先根据查询操作找到x所在的桶,然后将键值对从桶中移除,并重置位图中x所在桶的对应比特。Further, the deletion method of the key-value pair is as follows: when deleting x, first find the bucket where x is located according to the query operation, then remove the key-value pair from the bucket, and reset the corresponding bit of the bucket where x is located in the bitmap.
本发明的有益效果是:1)高装载率+较少指针:用较小的内存空间存储大量的键值对,并且使用的指针数很少。2)低冲突率。3)快速更新:利用很少的内存访问即可更新哈希表。4)零更新失败。5)快速查询:能够用很少的内存访问快速查找到键值对,或者对于不存在的键值对,能够快速返回不存在的结果。6)实用性:很容易在硬件系统中实现。The beneficial effects of the present invention are: 1) high loading rate + less pointers: a small memory space is used to store a large number of key-value pairs, and the number of pointers used is small. 2) Low conflict rate. 3) Fast update: Hash table can be updated with few memory accesses. 4) Zero update failed. 5) Fast query: can quickly find key-value pairs with little memory access, or can quickly return non-existent results for key-value pairs that do not exist. 6) Practicality: It is easy to implement in hardware system.
附图说明Description of drawings
图1是矩阵哈希的算法示意图。Figure 1 is a schematic diagram of the algorithm of matrix hashing.
图2是多比特布隆过滤器的结构图。Figure 2 is a structural diagram of a multi-bit Bloom filter.
具体实施方式Detailed ways
下面通过具体实施例和附图,对本发明做进一步说明。The present invention will be further described below through specific embodiments and accompanying drawings.
一.数据结构1. Data structure
本发明的“矩阵哈希”的数据结构综合使用了多级子表、布隆过滤器和位图。数据结构由哈希表数据结构和辅助数据结构两部分组成。The data structure of the "matrix hash" of the present invention comprehensively uses multi-level sub-tables, bloom filters and bitmaps. The data structure consists of two parts, the hash table data structure and the auxiliary data structure.
1.哈希表数据结构1. Hash table data structure
每个子表的大小,即能够存储的最大元素数目,是等差递减的,因此与子表对应的布隆过滤器也是等差递减的。在插入元素时使用了一个比较简单的均衡策略:每当插入一个新的键值对时,将它插入到装载率最小的子表中,如此就能保证每个子表中的元素数目也是类似算术级数递减形式存在的。The size of each subtable, that is, the maximum number of elements that can be stored, is arithmetically decreasing, so the Bloom filter corresponding to the subtable is also arithmetically decreasing. A relatively simple balancing strategy is used when inserting elements: whenever a new key-value pair is inserted, it is inserted into the sub-table with the smallest load rate, so that the number of elements in each sub-table is guaranteed to be similar to arithmetic It exists in the form of decreasing series.
假设一共有z个子表,z是偶数。对于矩阵哈希将第i个子表和第z-i+1个子表结合,最终得到了个大小相等的子表。因为结合后的子表形状与矩阵类似,因此我们将这个算法命名为矩阵哈希。为了避免插入失败,允许最后一个子表挂链表。如果待插入键值对最终找不到一个空桶,则可以在第z个子表上挂链表。因为第z个子表是最小的子表,因此指针将会占用最小的内存。Suppose there are z sublists in total, and z is an even number. for The matrix hash combines the i-th subtable with the z-i+1-th subtable, and finally gets subtables of equal size. Because the shape of the combined subtable is similar to that of a matrix, we name this algorithm matrix hashing. To avoid insert failures, allow the last child list to be linked. If the key-value pair to be inserted cannot find an empty bucket, a linked list can be attached to the z-th sub-table. Because the z-th subtable is the smallest subtable, the pointer will occupy the smallest memory.
图1矩阵哈希的算法示意图,其中,左边是大小呈等差递减的6个子表和6个布隆过滤器,中间是结合后的大小相等的3个子表和3个布隆过滤器。右上方是三个标准布隆过滤器BF1,BF2,BF3结合而成的多比特布隆过滤器。Figure 1 is a schematic diagram of the algorithm of matrix hashing, in which, the left side is 6 sub-tables and 6 bloom filters with equally decreasing size, and the middle is the combined 3 sub-tables and 3 bloom filters of equal size. The upper right is a multi-bit Bloom filter composed of three standard Bloom filters BF1, BF2, BF3.
2.辅助数据结构2. Auxiliary data structure
与哈希表结合类似,对于矩阵哈希将第i个布隆过滤器和第z-i+1个布隆过滤器结合,最终得到了个大小相等的标准布隆过滤器。接着,通过将这个布隆过滤器对应比特追加在一起,形成了1个布隆过滤器。在这个布隆过滤器中,每个箱由个比特组成。我称将这一个布隆过滤器为多比特布隆过滤器,并用Fm表示。到此,我们已经把原z个等差的布隆过滤器组合成1个多比特布隆过滤器。Similar to the hash table combination, for The matrix hash combines the i-th bloom filter with the z-i+1-th bloom filter, and finally gets A standard bloom filter of equal size. Then, by putting this The corresponding bits of each bloom filter are appended together to form a bloom filter. In this bloom filter, each bin consists of composed of bits. I call this a bloom filter a multi-bit bloom filter and denote it by F m . So far, we have combined the original z arithmetic bloom filters into a multi-bit bloom filter.
图2多比特布隆过滤器的结构图。如该图所示,一个箱中的三个比特分别来自三个大小相等的标准布隆过滤器即F1,F2,F3。值得注意的是,布隆过滤器的组合是在片内内存进行的,是物理上的,而子表的结合仅是概念上的。多比特布隆过滤器的算法实现方式如下所示:Figure 2 is a structural diagram of a multi-bit Bloom filter. As shown in the figure, the three bits in a bin come from three equal-sized standard bloom filters namely F1, F2, F3. It is worth noting that the combination of bloom filters is done in on-chip memory and is physical, while the combination of sub-tables is only conceptual. The algorithm implementation of the multi-bit bloom filter is as follows:
假设F1,F2,F3均有m个比特。对于F1,先取最高位比特(将F1的m个比特与2m-1做逻辑与操作),然后将所得结果向左移2*m位(所得m个比特乘以22m),接着取次高位比特(将F1的m个比特与2m-2做逻辑与操作),将所得结果向左移2*(m-1)位(所得m个比特乘以22(m-1)),将所得结果与最高比特操作后的值累加,以此类推,每个比特做类似操作,累加,直到最后一个比特,假设所得到的累加值为f1。对F2,F3分别做相同操作,得到累加值为f2,f3。将f1、f2右移一位后结果和f3右移两位后结果,这三者做逻辑或操作即得到多比特布隆过滤器(即为)。Assume that F1, F2, and F3 all have m bits. For F1, first take the most significant bit (the m bits of F1 are logically ANDed with 2 m-1 ), then shift the result to the left by 2*m bits (the resulting m bits are multiplied by 2 2m ), and then take the second most significant bit bits (the m bits of F1 are logically ANDed with 2 m-2 ), the result is shifted to the left by 2*(m-1) bits (the resulting m bits are multiplied by 2 2(m-1) ), the The obtained result is accumulated with the value after the operation of the highest bit, and so on. Similar operations are performed for each bit and accumulated until the last bit, assuming that the accumulated value obtained is f1. Do the same operation on F2 and F3 respectively, and get the accumulated value of f2 and f3. The result of shifting f1 and f2 to the right by one bit and the result of shifting f3 to the right by two bits, these three are logically ORed to obtain a multi-bit Bloom filter (that is, ).
由于以上布隆过滤器的设计会导致一个问题:当一个布隆过滤器返回true时,我们需要查询对应的两个子表。比如若x在第i个布隆过滤器中,则需要在子表Ti或Tz-i+1中查询。为了减少查询的子表数,增加了一个额外的布隆过滤器,称为Fhalf,负责记录子表的第二部分,即 Due to the design of the above bloom filter, there will be a problem: when a bloom filter returns true, we need to query the corresponding two sub-tables. For example, if x is in the i-th Bloom filter, you need to query in the sub-table T i or T z-i+1 . In order to reduce the number of sub-tables queried, an additional bloom filter called F half is added, which is responsible for recording the second part of the sub-table, namely
此外矩阵哈希还在片内使用位图,每个子表有一个位图相对应,位图中的每一个比特与其对应子表中的的一个桶相对应。空桶对应位图中的比特为0,非空桶为1。In addition, matrix hashing also uses bitmaps within the slice. Each subtable has a corresponding bitmap, and each bit in the bitmap corresponds to a bucket in its corresponding subtable. The bit in the bitmap corresponding to an empty bucket is 0, and a non-empty bucket is 1.
二.矩阵哈希假阳率推导2. Derivation of matrix hash false positive rate
矩阵哈希有两个布隆过滤器:Fm和Fhalf。假设n为键值对的个数,z个子表重组成了个子表。假设Fm有m个箱,每个箱里有个比特,这个比特分别对应个子表。假设Fm有k个子表,Fm的假阳率和组成它的独立的个布隆过滤器相等。因此Fm的假阳率如用f(Fm)表示,公式如下:Matrix hashing has two bloom filters: F m and F half . Assuming n is the number of key-value pairs, z sub-tables are reorganized into subtable. Suppose F m has m bins, each with bits, this bits corresponding to subtable. Suppose F m has k subtables, The false positive rate of F m and the independent Bloom filters are equal. Therefore, the false positive rate of F m is expressed as f(F m ), and the formula is as follows:
如果返回true的布隆过滤器的个数为u+1,那么假阳率公式为:If the number of Bloom filters that return true is u+1, then the formula for the false positive rate is:
f(Fm,u)=0.5k*u*(1-0.5k(z-u-1))f(F m ,u)=0.5 k*u *(1-0.5 k(zu-1) )
Fhalf同样有k个哈希函数,Fhalf的假阳率为:f(Fhalf)=0.5k。如果只有Fm返回true,并且键值对仅存在于一个子表中,则没有误报,这个事件发生的概率为(1-f(Fm))*(1-f(Fhalf))。如果只有Fm返回true,且报告键值对存在于u+1个子表中,则会有u个误报,这个事件的概率为f(Fm,u)*(1-f(Fhalf))。如果只有Fhalf报告一个误报,这个事件发生的概率为(1-f(Fm))*f(Fhalf)。如果Fm有u个误报,且Fhalf有一个误报,这个事件发生的概率为f(Fm,u)*f(Fhalf)。F half also has k hash functions, and the false positive rate of F half is: f(F half )=0.5 k . If only F m returns true, and the key-value pair exists in only one subtable, there are no false positives, and the probability of this event occurring is (1-f(F m ))*(1-f(F half )). If only F m returns true, and the reported key-value pair exists in u+1 sub-tables, there will be u false positives, and the probability of this event is f(F m ,u)*(1-f(F half ) ). If only F half reports a false positive, the probability of this event occurring is (1-f(F m ))*f(F half ). If F m has u false positives and F half has one false positive, the probability of this event occurring is f(F m ,u)*f(F half ).
例如:当z=8并且k=16时,矩阵哈希的假阳率为1-(1-f(Fm))*(1-f(Fhalf))≈6.1*10-5,这个数字是非常小的。For example: when z=8 and k=16, the false positive rate of matrix hashing is 1-(1-f(F m ))*(1-f(F half ))≈6.1*10 -5 , this number is very small.
三.键值对的插入、查询、删除方式3. Insert, query and delete key-value pairs
在键值存储系统中,矩阵哈希算法插入、查询、删除键值对的具体操作实施方式如下:In the key-value storage system, the specific operations of the matrix hash algorithm to insert, query, and delete key-value pairs are as follows:
1.键值对的插入方式1. How to insert key-value pairs
对于一个给定的键值对,要将键x插入。首先通过位图检查z个候选桶是否为空。然后将键值对插入到装载率最低的子表中,以平衡所有子表装载率。假设要插入的子表索引为i。如果则更新Fi来表示x在子表Ti中,更新对应位图;如果子表索引需将Fz-i+1更新来表示x在子表Ti中,并更新Fhalf和对应位图。插入过程中,为了将一个箱中与Fi对应的比特置为1,将这个箱中的个比特与2i-1做逻辑或操作即可。For a given key-value pair, key x is to be inserted. First check if z candidate buckets are empty by bitmap. The key-value pair is then inserted into the child table with the lowest load ratio to balance all child table load ratios. Suppose the index of the subtable to be inserted is i. if Then update F i to indicate that x is in the sub-table T i , and update the corresponding bitmap; if the sub-table index It is necessary to update F z-i+1 to indicate that x is in the sub-table Ti, and update F half and the corresponding bitmap. During insertion, in order to set the bit corresponding to Fi in a bin to 1, set the A bit and 2 i-1 can be logically ORed.
如果位图显示x应该插入的z个桶均已满,则使用cuckoo哈希(布谷鸟哈希)中踢的机制,并用位图来决定要踢哪一个键值对。使用位图来按顺序检查x对应的z个候选桶,以确定候选桶中原有的元素,比如y,在剩余的z-1个子表中,是否有一个空桶可以将y插入。如果有,则将y踢出,将x插入,并将y插入新的位置。如果找不到这样一个y,则执行盲踢,并重复以上插入的流程。盲踢的次数限制为θ,如超过θ次盲踢,则将键值对挂到最后一个子表的链表上。通过改变θ的值,RHT4可以在装载率和插入速度之间进行权衡。因为位图对子表中的空桶和非空桶有一个全局的记录,片内位图的使用显著的减少了踢操作的次数。If the bitmap shows that the z buckets that x should be inserted into are all full, use the kicking mechanism in cuckoo hashing (cuckoo hashing) and use the bitmap to decide which key-value pair to kick. Use the bitmap to check the z candidate buckets corresponding to x in order to determine whether the original element in the candidate bucket, such as y, has an empty bucket to insert y into the remaining z-1 subtables. If there is, kick y out, insert x, and insert y in the new position. If such a y cannot be found, a blind kick is performed, and the above insertion process is repeated. The number of blind kicks is limited to θ. If the number of blind kicks exceeds θ, the key-value pair will be linked to the linked list of the last sub-list. By changing the value of θ, RHT4 can trade off loading rate and insertion speed. Because bitmaps have a global record of empty and non-empty buckets in subtables, the use of on-chip bitmaps significantly reduces the number of kick operations.
2.键值对的查询方式2. How to query key-value pairs
如查询x,首先在Fm和Fhalf中查询x,如果返回true,且Fhalf返回false,则检查子表Ti。否则,先检查子表Tz-i+1,如果没有匹配,再检查子表Ti。如果在z个子表中都无法查找到x,则查找最后一个子表的链表。如果仍然无法找到,则说明x不在该哈希表中。If query x, first query x in F m and F half , if Returns true, and F half returns false, check the sub-table T i . Otherwise, the sub-table T z-i+1 is checked first, and if there is no match, then the sub-table T i is checked. If x cannot be found in z sublists, look up the linked list of the last sublist. If it still can't be found, then x is not in that hash table.
值得注意的是,在查询过程中,只需计算k个哈希函数即可,并不需要计算z×k个哈希函数,这是因为:组成一个布隆过滤器的原个布隆过滤器的参数是相同的。如果要读取一个箱中与Fi对应的比特,将这个比特与2i-1做逻辑与操作。如果结果为0,则箱中与Fi对应的比特为0,反之为1。It is worth noting that in the query process, only k hash functions need to be calculated, and z × k hash functions do not need to be calculated. This is because: the original composition of a Bloom filter The parameters of each bloom filter are the same. If you want to read the bits corresponding to Fi in a bin, put this The bits are logically ANDed with 2 i-1 . If the result is 0, the bit corresponding to Fi in the bin is 0, otherwise it is 1.
3.键值对的删除方式3. How to delete key-value pairs
如删除x,RHT1首先根据上述查询操作,找到x所在的桶,然后将键值对从桶中移除,并重置位图中x所在桶的对应比特。If x is deleted, RHT1 first finds the bucket where x is located according to the above query operation, then removes the key-value pair from the bucket, and resets the corresponding bit of the bucket where x is located in the bitmap.
四.实验数据4. Experimental data
为了更好的评估本发明的矩阵哈希以及现有的哈希设计,我们采用了实际应用的数据。我们获取了网站www.ripe.net在2014.07.08日上午8点的12个转发信息库(FIB,Forward Information Base),对于每一个FIB,对每个前缀(prefix)统一人工生成一个流量追踪(traffic trace)。我们使用FIB中与我们相关的部分,也就是前缀(prefix)和相关的下一跳。前缀(prefix)作为键,下一跳作为值。我们用β来表示哈希表总的桶数量和总的元素数量的比值。其中1.05≤β≤10。我们用θ表示盲踢操作的阈值。FIB中键值对个数为500,000。建立的8个子表的大小差值为5000,子表的总大小为β*n。使θ=0,这意味着不允许盲踢,只能只用位图踢。每次插入键值对,仿存次数的最大值为8+1,如果元素在8个子表中没有找到空的候选位置,则需要被插入到最后一个子表的链表上。冲突率用最后一个子表链表上的数目和总元素数目的比值。布隆过滤器有16个哈希函数。实验结果如下:In order to better evaluate the matrix hashing of the present invention as well as existing hashing designs, we use actual application data. We obtained 12 forwarding information bases (FIB, Forward Information Base) of the website www.ripe.net at 8:00 am on 2014.07.08, and for each FIB, a traffic trace ( traffic trace). We use the part of the FIB that is relevant to us, namely the prefix and the associated next hop. The prefix is the key and the next hop is the value. We use β to denote the ratio of the total number of buckets to the total number of elements in the hash table. where 1.05≤β≤10. We denote the threshold for blind kick operations by θ. The number of key-value pairs in the FIB is 500,000. The size difference of the 8 sub-tables established is 5000, and the total size of the sub-tables is β*n. Let θ=0, which means that no blind kicks are allowed, only bitmap kicks are allowed. Each time a key-value pair is inserted, the maximum number of imitations is 8+1. If the element does not find an empty candidate position in the 8 sub-lists, it needs to be inserted into the linked list of the last sub-list. The collision rate is the ratio of the number on the last child list to the total number of elements. Bloom filters have 16 hash functions. The experimental results are as follows:
1.矩阵哈希实验表现:1. Matrix hash experiment performance:
1)装载率和冲突率1) Loading rate and conflict rate
实验设置β=1.05,θ=0,实验结果表明,矩阵哈希仅用1.05*n的内存就实现了非常高的装载率,其中8个子表的装载率十分均衡,总的装载率是95.19%。冲突率在0.05%左右,仅有几个FIB冲突率超过了0.06%。The experimental settings are β=1.05 and θ=0. The experimental results show that the matrix hash can achieve a very high loading rate with only 1.05*n memory. The loading rate of the 8 sub-tables is very balanced, and the total loading rate is 95.19%. . The conflict rate is around 0.05%, with only a few FIBs exceeding 0.06%.
2)插入和查询时间2) Insert and query time
实验设置β=1.05,θ=0,实验将每个FIB的所有元素插入到矩阵哈希,实验结果表明,插入元素越多,所需的内存访问越多。大多数元素,每次插入所需的内存访问次数低于6次,查询的内存访问次数在1到1.0019之间,均值为1.00059。The experiment sets β=1.05 and θ=0, and the experiment inserts all elements of each FIB into the matrix hash. The experimental results show that the more elements inserted, the more memory accesses are required. For most elements, the number of memory accesses required per insert was less than 6, and the number of memory accesses for queries ranged from 1 to 1.0019, with a mean of 1.00059.
3)位图踢和盲踢3) Bitmap Kicks and Blind Kicks
实验设置β=1.05,实验结果表明,当θ=5时,插入一个键值对的内存次数最多是8*(5+1)+1=49次,查询一个键值对的内存访问次数低于8次,这时最后一个子表的链表上没有元素。θ=0时,尽管盲踢不被允许,在最后一个子表的链表上也仅有很少的元素(0.56%)。插入时内存访问的最坏情况是8+1次。The experimental setting is β=1.05. The experimental results show that when θ=5, the maximum number of times of inserting a key-value pair into memory is 8*(5+1)+1=49 times, and the number of memory accesses for querying a key-value pair is lower than 8 times, when there is no element in the linked list of the last sublist. When θ=0, even though blind kicks are not allowed, there are only a few elements (0.56%) on the linked list of the last sublist. Worst case memory access at insert time is 8+1 times.
4)冲突率vsβ4) Conflict rate vs β
实验设置θ=0,实验结果表明β越大,冲突率越小,并且当β≥1.18时,冲突率接近为0。The experimental set θ=0, the experimental results show that the larger the β, the smaller the conflict rate, and when β≥1.18, the conflict rate is close to 0.
2.矩阵哈希与其他哈希对比:2. Comparison of matrix hashes with other hashes:
实验将矩阵哈希与链式哈希、线性探测、双哈希、布谷鸟哈希、d-left哈希、孔雀鸟哈希六种广为人知的哈希设计相对比。首先定义一下插入失败,对于线性探测、双哈希和布谷鸟哈希,当冲突发生时,会探测另外一个桶,并且这种探测会一直重复。我们将重复探测的次数限定在500以内,这就意味着,对于这三种哈希设计,每次插入内存访问次数的最大值为500,如果超过500次仍有冲突,这三种哈希设计就会放弃继续插入,将第500次循环时未被插入的元素丢弃,也就导致了插入失败。对于孔雀鸟哈希和矩阵哈希,布隆过滤器有16个哈希函数。The experiment compares matrix hashing with six well-known hashing designs: chained hashing, linear probing, double hashing, cuckoo hashing, d-left hashing, and peacock bird hashing. First define the insertion failure. For linear detection, double hash and cuckoo hash, when a collision occurs, another bucket is detected, and this detection is repeated all the time. We limit the number of repeated detections to less than 500, which means that for these three hash designs, the maximum number of memory accesses per insertion is 500. If there are still collisions after more than 500 times, the three hash designs It will give up and continue to insert, and discard the elements that have not been inserted in the 500th cycle, which will cause the insertion to fail. For peacock bird hashing and matrix hashing, the Bloom filter has 16 hash functions.
实验一:(β=1.05,不同的FIB)Experiment 1: (β=1.05, different FIBs)
1)装载率1) Loading rate
实验结果表明:矩阵哈希的装载率一直是最高的。The experimental results show that the loading rate of matrix hashing has always been the highest.
2)插入时间2) Insert time
实验结果表明:矩阵哈希,在除了链式哈希之外的其他所有哈希中,插入所需的仿存次数最少。这是因为链式哈希,在插入时只需要一次或两次访存,所以访存时间较短,但链式哈希在其他方面的缺点十分突出。而矩阵哈希,由于布隆过滤器和位图的存在,能达到快速插入。The experimental results show that matrix hashing requires the least number of replicas to insert among all hashes except chain hashing. This is because chained hashing requires only one or two fetches when inserting, so the fetching time is shorter, but chained hashing has very prominent shortcomings in other aspects. The matrix hash, due to the existence of Bloom filters and bitmaps, can achieve fast insertion.
3)查找时间3) Find time
实验结果表明:矩阵哈希有着最短的查找时间,因为矩阵哈希有这较高的装载率和很小的假阳率。The experimental results show that matrix hashing has the shortest search time, because matrix hashing has a high loading rate and a small false positive rate.
实验二(不同的β,FIB rrc00)Experiment 2 (different beta, FIB rrc00)
1)装载率1) Loading rate
实验结果表明:矩阵哈希的装载率一直是最高的,链式哈希和双哈希的装载率差不多,孔雀鸟哈希只有在β比较高时,才达到了较高的装载率。The experimental results show that the loading rate of matrix hashing is always the highest, the loading rate of chain hashing and double hashing is similar, and the loading rate of peacock bird hashing can only reach a higher loading rate when β is relatively high.
2)插入时间2) Insert time
实验结果表明:矩阵哈希,在除了链式哈希之外的其他所有哈希中,插入所需的仿存次数最少。The experimental results show that matrix hashing requires the least number of replicas to insert among all hashes except chain hashing.
3)查找时间3) Find time
实验结果表明:矩阵哈希有着最短的查找时间。The experimental results show that the matrix hash has the shortest search time.
以上实施例仅用以说明本发明的技术方案而非对其进行限制,本领域的普通技术人员可以对本发明的技术方案进行修改或者等同替换,而不脱离本发明的精神和范围,本发明的保护范围应以权利要求书所述为准。The above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Those skilled in the art can modify or equivalently replace the technical solutions of the present invention without departing from the spirit and scope of the present invention. The scope of protection shall be subject to what is stated in the claims.
Claims (3)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710014205.9A CN108287840B (en) | 2017-01-09 | 2017-01-09 | A Data Storage and Query Method Based on Matrix Hash |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710014205.9A CN108287840B (en) | 2017-01-09 | 2017-01-09 | A Data Storage and Query Method Based on Matrix Hash |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN108287840A CN108287840A (en) | 2018-07-17 |
| CN108287840B true CN108287840B (en) | 2022-05-03 |
Family
ID=62819334
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201710014205.9A Active CN108287840B (en) | 2017-01-09 | 2017-01-09 | A Data Storage and Query Method Based on Matrix Hash |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN108287840B (en) |
Families Citing this family (14)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN108989452A (en) * | 2018-08-07 | 2018-12-11 | 佛山市苔藓云链科技有限公司 | A kind of data transmission of internet of things device |
| CN109471635B (en) * | 2018-09-03 | 2021-09-17 | 中新网络信息安全股份有限公司 | Algorithm optimization method based on Java Set implementation |
| CN109597807A (en) * | 2018-10-25 | 2019-04-09 | 阿里巴巴集团控股有限公司 | Number storehouse list processing method and apparatus |
| CN109766341B (en) * | 2018-12-27 | 2022-04-22 | 厦门市美亚柏科信息股份有限公司 | Method, device and storage medium for establishing Hash mapping |
| CN109800228B (en) * | 2018-12-28 | 2023-03-10 | 深圳竹云科技有限公司 | Method for efficiently and quickly solving hash conflict |
| CN111563199B (en) * | 2020-04-26 | 2023-10-10 | 北京奇艺世纪科技有限公司 | Data processing method and device |
| CN111552692B (en) * | 2020-04-30 | 2023-04-07 | 南方科技大学 | An additive and subtractive cuckoo filter |
| CN112416933B (en) * | 2020-11-19 | 2022-09-23 | 重庆邮电大学 | A high-performance hash table implementation method based on on-chip and off-chip memory |
| CN112699323A (en) * | 2021-01-07 | 2021-04-23 | 西藏宁算科技集团有限公司 | Cloud caching system and cloud caching method based on double bloom filters |
| CN113342828A (en) * | 2021-07-02 | 2021-09-03 | 广东唯审信息科技有限公司 | Hash table conflict resolution method based on d-dimensional mapping |
| CN115529149B (en) * | 2021-12-06 | 2025-07-29 | 北京大学 | Method for searching continuous low-frequency elements in real time, APT attack detection method and FRP detection method |
| CN116566863A (en) * | 2023-05-18 | 2023-08-08 | 天津大学 | Efficient image flow measurement method for elephant flow and mutation flow |
| CN116719813B (en) * | 2023-05-26 | 2025-08-19 | 华中科技大学 | Hash table processing method and device and electronic equipment |
| CN116860788A (en) * | 2023-07-24 | 2023-10-10 | 杭州电子科技大学 | Multi-set search insertion and search optimization method based on multi-path parallel processing |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104317795A (en) * | 2014-08-28 | 2015-01-28 | 华为技术有限公司 | Two-dimensional filter generation method, query method and device |
| CN105027527A (en) * | 2012-12-31 | 2015-11-04 | 华为技术有限公司 | Scalable storage system with longest prefix matching switches |
| CN105468298A (en) * | 2015-11-19 | 2016-04-06 | 中国科学院信息工程研究所 | Key value storage method based on log-structured merged tree |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US10810200B2 (en) * | 2015-01-07 | 2020-10-20 | International Business Machines Corporation | Technology for join processing |
-
2017
- 2017-01-09 CN CN201710014205.9A patent/CN108287840B/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105027527A (en) * | 2012-12-31 | 2015-11-04 | 华为技术有限公司 | Scalable storage system with longest prefix matching switches |
| CN104317795A (en) * | 2014-08-28 | 2015-01-28 | 华为技术有限公司 | Two-dimensional filter generation method, query method and device |
| CN105468298A (en) * | 2015-11-19 | 2016-04-06 | 中国科学院信息工程研究所 | Key value storage method based on log-structured merged tree |
Also Published As
| Publication number | Publication date |
|---|---|
| CN108287840A (en) | 2018-07-17 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108287840B (en) | A Data Storage and Query Method Based on Matrix Hash | |
| CN101655861B (en) | Hashing Method and Hashing Device Based on Double Count Bloom Filter | |
| CN110083601A (en) | Index tree constructing method and system towards key assignments storage system | |
| CN112000846B (en) | Method for grouping LSM tree indexes based on GPU | |
| CN104866502B (en) | Data matching method and device | |
| CN101594319B (en) | Entry lookup method and entry lookup device | |
| CN103051543B (en) | A kind of process of route prefix, search, increase and delet method | |
| CN102521334A (en) | Data storage and query method based on classification characteristics and balanced binary tree | |
| Xiao et al. | Using parallel bloom filters for multiattribute representation on network services | |
| WO2016201930A1 (en) | Traffic classification method and device, and storage medium | |
| CN112783644B (en) | A distributed oblique stream processing method and system based on high-frequency key-value counting | |
| CN102110171A (en) | Method for inquiring and updating Bloom filter based on tree structure | |
| WO2018205151A1 (en) | Data updating method and storage device | |
| CN106599091B (en) | RDF graph structure storage and index method based on key value storage | |
| US20220075766A1 (en) | Cuckoo hashing including accessing hash tables using affinity table | |
| CN102346735A (en) | Hash search method capable of reducing hash collision | |
| Gong et al. | Abc: a practicable sketch framework for non-uniform multisets | |
| CN118227518B (en) | Table entry storage and searching method and device, network equipment and storage medium | |
| CN109800228B (en) | Method for efficiently and quickly solving hash conflict | |
| CN108093024B (en) | Classified routing method and device based on data frequency | |
| CN103780692B (en) | Data access method and system for key value storage | |
| CN106302178B (en) | A route query method and device | |
| CN110995876B (en) | Method and device for storing and searching IP | |
| CN104301227B (en) | High-speed low-power-consumption IP route table lookup method based on TCAM | |
| CN108021678A (en) | A kind of compact-sized key-value pair storage organization and quick key-value pair lookup method |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |