Google Bigtable、Apache HBase和Apache Cassandra和PostgreSQL 使用布隆过滤器来减少对不存在的行或列的磁盘查找。避免昂贵的磁盘查找可显着提高数据库查询操作的性能。
Google Chrome浏览器使用了布隆过滤器加速安全浏览服务。
Microsoft Bing搜索引擎对其搜索索引BitFunnel使用多级分层布隆过滤器。
Redis 缓存穿透
Bloom filter used to speed up answers in a key-value storage system. Values are stored on a disk which has slow access times. Bloom filter decisions are much faster. However some unnecessary disk accesses are made when the filter reports a positive (in order to weed out the false positives). Overall answer speed is better with the Bloom filter than without the Bloom filter. Use of a Bloom filter for this purpose, however, does increase memory usage
static <T> BloomFilter<T> create( Funnel<? super T> funnel, long expectedInsertions, double fpp, Strategy strategy) { checkNotNull(funnel); checkArgument( expectedInsertions >= 0, "Expected insertions (%s) must be >= 0", expectedInsertions); checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp); checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp); checkNotNull(strategy);
if (expectedInsertions == 0) { expectedInsertions = 1; } /* * TODO(user): Put a warning in the javadoc about tiny fpp values, since the resulting size * is proportional to -log(p), but there is not much of a point after all, e.g. * optimalM(1000, 0.0000000000000001) = 76680 which is less than 10kb. Who cares! */ // 计算需要的字节数 longnumBits= optimalNumOfBits(expectedInsertions, fpp); // 计算需要的hash函数数量 intnumHashFunctions= optimalNumOfHashFunctions(expectedInsertions, numBits); try { returnnewBloomFilter<T>(newLockFreeBitArray(numBits), numHashFunctions, funnel, strategy); } catch (IllegalArgumentException e) { thrownewIllegalArgumentException("Could not create BloomFilter of " + numBits + " bits", e); } }
/** * Returns {@code true} if the element <i>might</i> have been put in this Bloom filter, {@code * false} if this is <i>definitely</i> not the case. */ publicbooleanmightContain(T object) { return strategy.mightContain(object, funnel, numHashFunctions, bits); }
public <T> booleanmightContain( T object, Funnel<? super T> funnel, int numHashFunctions, LockFreeBitArray bits) { longbitSize= bits.bitSize(); byte[] bytes = Hashing.murmur3_128().hashObject(object, funnel).getBytesInternal(); longhash1= lowerEight(bytes); longhash2= upperEight(bytes);
longcombinedHash= hash1; for (inti=0; i < numHashFunctions; i++) { // Make the combined hash positive and indexable if (!bits.get((combinedHash & Long.MAX_VALUE) % bitSize)) { returnfalse; } combinedHash += hash2; } returntrue; }