Bloom filter




 

A Bloom filter is a method for representing a set $A = \{a_1, a_2,\ldots, a_n\}$ of n elements (also called keys) to support membership queries. It was invented by Burton Bloom in 1970 [6] and was proposed for use in the web context by Marais and Bharat [37] as a mechani sm for identifying which pages have associated comments stored within a CommonKnowledgeserver.


   
Figure 3: A Bloom Filter with 4 hash functions.
\begin{figure}\centerline{\psfig {figure=bloomfilter.eps,height=1.8in}}\end{figure}

The idea (illustrated in Figure 3) is to allocate a vector v of m bits, initially all set to 0, and then choose k independent hash functions, $h_1, h_2, \ldots, h_k$,each with range $\{1,\ldots,m\}$. For each element $a \in A$, the bits at positions h1(a), h2(a), ..., hk(a) in v are set to 1. (A particular bit might be set to 1 multiple times.) Given a query for bwe check the bits at positions h1(b), h2(b), ..., hk(b). If any of them is 0, then certainly b is not in the set A. Otherwise we conjecture that b is in the set although there is a certain probability that we are wrong. This is called a ``false positive.'' or, for historical reasons, a ``false drop.'' The parameters k and m should be chosen such that the probability of a false positive (and hence a false hit) is acceptable.

The salient feature of Bloom filters is that there is a clear tradeoff between m and the probability of a false positive. Observe that after inserting n keys into a table of size m, the probability that a particular bit is still 0 is exactly

\begin{displaymath}\left(1 - {1\over m}\right)^{k n}.\end{displaymath}

Hence the probability of a false positive in this situation is

\begin{displaymath}\left( 1 - \left(1 - {1\over m}\right)^{k n} \right)^k \approx \left(1 - e ^ { k n /m} \right)^k .\end{displaymath}

The right hand side is minimized for  $k = \ln 2 \times m / n$ , in which case it becomes

\begin{displaymath}\left({1\over2} \right) ^k = (0.6185)^{m/n}.\end{displaymath}

In fact  k  must be an integer and in practice we might chose a value less than optimal to reduce computational overhead. Some example values are:

Table 3 though Table 5 list the false positive retios for common combinations of m/n and k.


 
Table 3: False positive rate under various  m/ n and  k combinations.
m/nkk=1k=2k=3k=4k=5k=6k=7k=8
21.390.3930.400      
32.080.2830.2370.253     
42.770.2210.1550.1470.160    
53.460.1810.1090.0920.0920.101   
64.160.1540.08040.06090.05610.05780.0638  
74.850.1330.06180.04230.03590.03470.0364  
85.550.1180.04890.03060.0240.02170.02160.0229 
96.240.1050.03970.02280.01660.01410.01330.01350.0145
106.930.09520.03290.01740.01180.009430.008440.008190.00846
117.620.08690.02760.01360.008640.00650.005520.005130.00509
128.320.080.02360.01080.006460.004590.003710.003290.00314
139.010.0740.02030.008750.004920.003320.002550.002170.00199
149.70.06890.01770.007180.003810.002440.001790.001460.00129
1510.40.06450.01560.005960.0030.001830.001280.0010.000852
1611.10.06060.01380.0050.002390.001390.0009350.0007020.000574
1711.80.05710.01230.004230.001930.001070.0006920.0004990.000394
1812.50.0540.01110.003620.001580.0008390.0005190.000360.000275
1913.20.05130.009980.003120.00130.0006630.0003940.0002640.000194
2013.90.04880.009060.00270.001080.000530.0003030.0001960.00014
2114.60.04650.008250.002360.0009050.0004270.0002360.0001470.000101
2215.20.04440.007550.002070.0007640.0003470.0001850.0001127.46e-05
2315.90.04250.006940.001830.0006490.0002850.0001478.56e-055.55e-05
2416.60.04080.006390.001620.0005550.0002350.0001176.63e-054.17e-05
2517.30.03920.005910.001450.0004780.0001969.44e-055.18e-053.16e-05
26180.03770.005480.001290.0004130.0001647.66e-054.08e-052.42e-05
2718.70.03640.00510.001160.0003590.0001386.26e-053.24e-051.87e-05
2819.40.03510.004750.001050.0003140.0001175.15e-052.59e-051.46e-05
2920.10.03390.004440.0009490.0002769.96e-054.26e-052.09e-051.14e-05
3020.80.03280.004160.0008620.0002438.53e-053.55e-051.69e-059.01e-06
3121.50.03170.00390.0007850.0002157.33e-052.97e-051.38e-057.16e-06
3222.20.03080.003670.0007170.0001916.33e-052.5e-051.13e-055.73e-06


 
Table 4: False positive rate under various  m/ n and  k combinations.
m/nkk=9k=10k=11k=12k=13k=14k=15k=16
117.620.00531       
128.320.003170.00334      
139.010.001940.001980.0021     
149.70.001210.00120.00124     
1510.40.0007750.0007440.0007470.000778    
1611.10.0005050.000470.0004590.0004660.000488   
1711.80.0003350.0003020.0002870.0002840.000291   
1812.50.0002260.0001980.0001830.0001760.0001760.000182  
1913.20.0001550.0001320.0001180.0001110.0001090.000110.000114 
2013.90.0001088.89e-057.77e-057.12e-056.79e-056.71e-056.84e-05 
2114.67.59e-056.09e-055.18e-054.63e-054.31e-054.17e-054.16e-054.27e-05
2215.25.42e-054.23e-053.5e-053.05e-052.78e-052.63e-052.57e-052.59e-05
2315.93.92e-052.97e-052.4e-052.04e-051.81e-051.68e-051.61e-051.59e-05
2416.62.86e-052.11e-051.66e-051.38e-051.2e-051.08e-051.02e-059.87e-06
2517.32.11e-051.52e-051.16e-059.42e-068.01e-067.1e-066.54e-066.22e-06
26181.57e-051.1e-058.23e-066.52e-065.42e-064.7e-064.24e-063.96e-06
2718.71.18e-058.07e-065.89e-064.56e-063.7e-063.15e-062.79e-062.55e-06
2819.48.96e-065.97e-064.25e-063.22e-062.56e-062.13e-061.85e-061.66e-06
2920.16.85e-064.45e-063.1e-062.29e-061.79e-061.46e-061.24e-061.09e-06
3020.85.28e-063.35e-062.28e-061.65e-061.26e-061.01e-068.39e-067.26e-06
3121.54.1e-062.54e-061.69e-061.2e-068.93e-077e-075.73e-074.87e-07
3222.23.2e-061.94e-061.26e-068.74e-076.4e-074.92e-073.95e-073.3e-07


 
Table 5: False positive rate under various  m/ n and  k combinations.
m/nkk=17k=18k=19k=20k=21k=22k=23k=24
2215.22.67e-05       
2315.91.61e-05       
2416.69.84e-061e-05      
2517.36.08e-066.11e-066.27e-06     
26183.81e-063.76e-063.8e-063.92e-06    
2718.72.41e-062.34e-062.33e-062.37e-06    
2819.41.54e-061.47e-061.44e-061.44e-061.48e-06   
2920.19.96e-079.35e-079.01e-078.89e-078.96e-079.21e-07  
3020.86.5e-076e-075.69e-075.54e-075.5e-075.58e-07  
3121.54.29e-073.89e-073.63e-073.48e-073.41e-073.41e-073.48e-07 
3222.22.85e-072.55e-072.34e-072.21e-072.13e-072.1e-072.12e-072.17e-07

The graph in Figure 4 shows the probability of a false positive as a function of the number of bits allocated for each entry, that is, the ratio $\alpha = n/m$. The curve above is for the case of 4 hash functions. The curve below is for the optimum number of hash functions. The scale is logarithmic so the straight line observed corresponds to an exponential decrease. It is clear that Bloom filters require very little storage per key at the slight risk of some false positives. For instance for a bit array 10 times larger than the number of entries, the probability of a false positive is 1.2% for 4 hash functions, and 0.9% for the optimum case of 5 hash functions. The probability of false positives can be easily decreased by allocating more memory.


   
Figure 4: Probability of false positives (log scale). The top curve is for 4 hash functions. The bottom curve is for the optimum (integral) number of hash functions.
\begin{figure}\psfig {figure=bloom.ps,angle=270,width=3in}\end{figure}

Since in our context each proxy maintains a local Bloom filter to represent its own cached documents, changes of set A must be supported. This is done by maintaining for each location $\ell$ in the bit array a count $c(\ell)$ of the number of times that the bit is set to 1 (that is, the number of elements that hashed to $\ell$ under any of the hash functions). All the counts are initially 0. When a key a (in our case, the URL of a document) is inserted or deleted, the counts c(h1(a)), c(h2(a)), ..., c(hk(a)) are incremented or decremented accordingly. When a count changes from 0 to 1, the corresponding bit is turned on. When a count changes from 1 to 0 the corresponding bit is turned off. Hence the local Bloom filter always reflects correctly the current directory.

Since we also need to allocate memory for the counts, it is important to know how large they can become. The asymptotic expected maximum count after inserting n keys with khash functions into a bit array of size m is (see [22, p. 72])

\begin{displaymath}\Gamma^{-1}(m) \left(1 + {\ln (k n/m) \over \ln \Gamma^{-1}(m)} + O \left({1 \over \ln^2 \Gamma^{-1}(m)} \right)  \right), \end{displaymath}

and the probability that any count is greater or equal  i  is

\begin{displaymath}\Pr(\max(c) \geq i) \leq m {n k \choose i} {1\over m^i} \leq m\left( e n k \over i m \right)^i.\end{displaymath}

As already mentioned the optimum value for k (over reals) is  $\ln 2m/n$  so assuming that the number of hash functions is less than  $\ln 2m/n$  we can further bound

\begin{displaymath}\Pr(\max(c) \geq i) \leq m \left( e \ln 2 \over i\right)^i.\end{displaymath}

Hence taking  i =16 we obtain that

\begin{displaymath}\Pr(\max(c) \geq 16) \leq { 1.37\times 10^{-15}} \times m.\end{displaymath}

In other words if we allow 4 bits per count, the probability of overflow for practical values of  m  during the initial insertion in the table is minuscule.

In practice we must take into account that the hash functions are not truly random, and that we keep doing insertions and deletions. Nevertheless, it seems that 4 bits per count would be amply sufficient. Furthermore if the count ever exceeds 15, we can simply let it stay at 15; after many deletions this might lead to a situation where the Bloom filter allows a false negative (the count becomes 0 when it shouldn't be), but the probability of such a chain of events is so low that it is much more likely that the proxy server would be rebooted in the meantime and the entire structure reconstructed.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值