summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-09-25 17:43:40 -0700
committerSage Weil <sage@inktank.com>2013-10-03 09:21:54 -0700
commit4b23b653788bec82b10c4163006674e4158e3f3c (patch)
treea3c9d3927950824d8b3929117e728ea617dfb678
parent0a69baeb3dd0bd85500ab1ca10d64e9c25e24356 (diff)
downloadceph-4b23b653788bec82b10c4163006674e4158e3f3c.tar.gz
common/bloom_filter: test binning fpp behavior
Signed-off-by: Sage Weil <sage@inktank.com>
-rw-r--r--src/test/common/test_bloom_filter.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/common/test_bloom_filter.cc b/src/test/common/test_bloom_filter.cc
index d074407a851..f0714cb530c 100644
--- a/src/test/common/test_bloom_filter.cc
+++ b/src/test/common/test_bloom_filter.cc
@@ -100,6 +100,42 @@ TEST(BloomFilter, SweepInt) {
}
+TEST(BloomFilter, BinSweep) {
+ int total_max = 16384;
+ float total_fpp = .01;
+ std::cout << "total_inserts " << total_max << " target-fpp " << total_fpp << std::endl;
+ for (int bins = 1; bins < 16; ++bins) {
+ int max = total_max / bins;
+ float fpp = total_fpp / bins;//pow(total_fpp, bins);
+
+ std::vector<bloom_filter*> ls;
+ bufferlist bl;
+ for (int i=0; i<bins; i++) {
+ ls.push_back(new bloom_filter(max, fpp, i));
+ for (int j=0; j<max; j++) {
+ ls.back()->insert(10000 * (i+1) + j);
+ }
+ ::encode(*ls.front(), bl);
+ }
+
+ int hit = 0;
+ int test = max * 100;
+ for (int i=0; i<test; ++i) {
+ for (std::vector<bloom_filter*>::iterator j = ls.begin(); j != ls.end(); ++j) {
+ if ((*j)->contains(i * 732)) { // note: sequential i does not work here; the intenral int hash is weak!!
+ hit++;
+ break;
+ }
+ }
+ }
+
+ double actual = (double)hit / (double)test;
+ std::cout << "bins " << bins << " bin-max " << max << " bin-fpp " << fpp
+ << " actual-fpp " << actual
+ << " total-size " << bl.length() << std::endl;
+ }
+}
+
// disable these tests; doing dual insertions in consecutive filters
// appears to be equivalent to doing a single insertion in a bloom
// filter that is twice as big.