SlideShare a Scribd company logo
Cuckoo Filter: Practically
Better Than Bloom
紹介: nikezono
Bin Fan, Dave G. Andersen, Michael Kaminsky, and Michael D. Mitzenmacher. 2014. Cuckoo Filter: Practically Better Than Bloom. In Proceedings of the
10th ACM International on Conference on emerging Networking Experiments and Technologies (CoNEXT '14). Association for Computing Machinery, New
York, NY, USA, 75–88. DOI:https://doi.org/10.1145/2674005.2674994
概要
● ブルームフィルタ(Bloom Filter) の改善提案
● Hash Table の改善であるCuckoo Hashing が元ネタ
○ Cuckoo Hashing を使って Filter を作った、ということ
● Bloom Filter に比べて以下の改善点がある
○ “Delete” operationが追加
○ Lower space overhead
○ Lower false positive rates
● 最近盛り上がりを見せている(?)
○ VLDB’21 では Cuckoo Index という Secondary Index for data skipping が提案
○ SIGMOD’21 では Conditional Cuckoo Filters という Join 演算を可能にする variantが提案
Cuckoo Hashing 101
まず、Cuckoo Filterの前提知識となるCuckoo Hashingについて.
● Open addressing hash table の一種.2001年に提案.
● Hash table はハッシュ関数を一つしか持たないが、
Cuckoo Hashingは2つ持つ.
● Insert(key, value) に対して:
○ よくあるHash table: Insert(key, value) => { Table [h(key) % sizeof(Table)] = value }
i. 衝突したら線形リストを作ったり,線形に空きスロットを探索したり.
○ Cuckoo Hashing:
i. Table[h1(key)] か Table[h2(key)] が空いている => そこに入る
ii. 空いていない(衝突してる) => 入っていたやつ (key’) を追い出す!
1. key’ が h1(key’) のスロットに入っているとする :
2. Table[h2(key’)] をルックアップ.空いているならそこに key’ を引っ越し
3. 空いていない => 入っていた key (key’’) を追い出す!goto 1
iii. ループしすぎたら満員と判定して Tableをextendする
Cuckoo Hashing 101
特徴
● Lookupは O(1~2), 最悪計算量がO(2).こ
れは強い!
● Insertionの最悪計算量は保証がない(満
員でも気付かない)
○ 無限にループできる
○ 適当なしきい値を決定してどこかで諦め
る(≒ rehashする) 必要がある
○ それはオープンアドレッシング系ハッシュ
テーブルの宿命で, Cuckoo特有の弱点
ではないが・・・
○ しかし償却計算量は O(1)
Bloom Filter 101
次に,Cuckoo Filter の元ネタとなるBloom Filter について.
● approximate set membership testing のためのデータ構造.
● k 個の ハッシュ関数を持つ.
● Insert(key) => k回 h(key)してヒットしたindexのビットを立てる
● Lookup(key) => k回 h(key) して全ビット立っていれば(maybe) True
● Delete(key) => できません!
Bloom filter. (2021.09.06.). In Wikipedia. https://en.wikipedia.org/wiki/Bloom_filter
Cuckoo Filter
Bloom Filter を Cuckoo Hashing のテクニックを使って改善したもの.
貢献は以下:
1. It supports adding and removing items dynamically;
2. It provides higher lookup performance than traditional Bloom filters, even when close to full (e.g., 95% space utilized);
3. It is easier to implement than alternatives such as the quotient filter; and
4. It uses less space than Bloom filters in many practical applications, if the target false positive rate is less than 3%.
Cuckoo Filter: Introduction
A cuckoo filter is a compact variant of a cuckoo hash table [21] that stores only fingerprints—a bit string derived from the
item using a hash function—for each item inserted, instead of key-value pairs. … A set membership query for item x
simply searches the hash table for the fingerprint of x, and returns true if an identical fingerprint is found.
Cuckoo Filterは Cuckoo Hashing をほぼそのまま使っている.
Hashing は Key/Value を保存できるHash table だが, Filter のほうは Valueに fingerprint を保存する.
Lookup はこの fingerprint をHash table から検索する処理になる.
fingerprint をどう作るか,という設計がフィルタの性能(偽陽性)を左右する.
Cuckoo Filter: Figure 1
● Key: index (uint)
● Value (bucket): 4 entries
○ すべて fingerprint が保存される
○ 4回までcollision してもいいということ
○ いろいろ計算量理論的な話が出てきますが,
実験に使っているのはこの構造です
Cuckoo Filter: Introduction
Interestingly, while we show that cuckoo filters are practically better than Bloom filters for many real workloads, they are
asymptotically worse: the minimum fingerprint size used in the cuckoo filter grows logarithmically with the number of
entries in the table.
Cuckoo Filterは Practical にはBloomより性能が良いが,テーブルサイズが増大すると漸近的に性能が悪
くなっていく.fingerprint の最小サイズがテーブルサイズに対して増大していく.
(ので,空間効率もキャッシュ効率も悪くなる)
ここでいう Practical は < billion items
Cuckoo Filter: Related Work
● Cuckoo は 削除ができてかつ空間計算量が
少ない.キャッシュミス回数も少ない.
各手法の(雑な)説明
● blocked: CPUキャッシュラインにサイズを合わせた複数
の配列で構成する
BF
● counting: 各bucketをboolから4bit以上のuintに変更し
て削除可能にする
BF
● d-left: counting + fingerprint.
● quotient: hash table (linear probing) で実装するfilter?
2.2 Using Cuckoo Hashing for Set-membership
もと, cuckoo hash tableを set membership testing に使う例は過去にもいくつかある.この論文の著者陣はも
ともと cuckoo hash table を使ってset-membership testing の研究をしていた.
partial-key cuckoo hashing と呼ばれるテクニックを使ってhash table / NW switch を改善してきたが,
そのテクニックをBloom Filter 化したCuckoo に用いる,というのが今回の論旨.
Recently, standard cuckoo hash tables have been used to provide set membership information in a few applications. …
Our previous study in building high-speed and memory efficient key-value stores [17, 11] and software-based Ethernet
switches [26] all applied cuckoo hash tables as internal data structures. That work was motivated by and also focused on
improving hash table performance by an optimization called partial-key cuckoo hashing. However, as we show in this
paper, this technique also enabled a new approach to build a Bloom filter replacement which has not been studied
before.
Cuckoo Filter: Insert
1. hash 関数を用いてindexを2つ作る.
2. どちらかのbucketが空いていたら終了
     # 「同じfingerprintがあれば終了」ではないのがポイント.後述.
3. 両方埋まっている:
a. どちらかのbucketを引っ越し.
b. 以下ループ・・・は Cuckoo Hashingと同じ
問題はreallocateの際にある. fingerprint しか保存していない
ため,オリジナルのキーの rehash ができない … i.e., h1(key) の
結果と keyの断片しか持っていない状態で, h2(key) を求めなく
てはならない.
ここでは partial-key cuckoo hashing という手法を使う.
Partial-key Cuckoo Hashing
The xor operation … ensures an important property: h1(x) can also be calculated from h2(x) and the fingerprint using the
same formula. In other words, to displace a key originally in bucket i (no matter if i is h1(x) or h2(x)), we directly calculate
its alternate bucket j from the current bucket index i and the fingerprint stored in this bucket by
このやり方でh1(x), h2(x) を作ると,片方のbucket (h1(x) or h2(x))とfingerprintがわかっていれば,もう片方
のbucket が求められる.ハッシュ関数2つを使うのと異なり,衝突もしない.さらに
`sizeof(fingerprint)` ビット
離れたindexとなることが保証されるため,空間効率も良くなる.(
#?)
Cuckoo Filter: Lookup
Notice that this ensures no false negatives as long as bucket overflow never occurs.
Cuckoo Filter: Delete
削除もシンプル.
1. Lookup(x) を行う.
2. fingerprint がマッチするエントリがあれば,削除す
る.
Notes:
● fingeprint collisionが起きている場合, false
deletion problem は起きない.Insert(x) のときに重
複挿入を許しているため,削除一回につき同じ
bucket の entry は一つしか消さないので,bucket
が溢れない限り問題ない.
Cuckoo Filter: Asymptotic Behavior
Minimal Fingerprint Size:
● f bits のfingerprint size を選択すると,hashの結果は2^f 通り
● m buckets 用意したtable で, 2^f < m ならば綺麗に収まる
● Delete も Lookup も最悪時間計算量O(2)で終わるので,重要なのは
Insert(x) の性能
● f or m が小さいとcollision が増える=> Insert(x) の償却計算量が増えてしまう
● 充分に長い2つのkey x, y のfingerprints がcollision する確率は1/(2^f)
● fingerprintsはcollisionしていないが同じbucketが割り当てられてしまう確率は2/m
● したがってq のitemsが bucket を共有(collision)してしまう確率は
● The construction process (#? スミマセン...) の結果
n: number of items. b: number of entries per bucket.
`n` に応じてfingerprint size が増えていくのは(著者陣含め)懸念点. Bloom Filterは各 entry で 1bit しか要求しない.
が, `b` を調整すればfingerprintは (practicalには) 小さく保たれる.
Cuckoo Filter: Asymptotic Behavior
Empirical Evaluation:
● 64bit random key insertion で実験.
● Kick のしきい値は 500; これに到達したら実験終
了
● m (テーブルサイズ) も変えて実験.
○ 実験環境の制約から m=2^30 以上はできなかっ
たらしい
● load factor: 占有率はfingerprintが一定以上長け
れば充分に理想的(95%)
● むしろ fingerprint > 4 にする意義は2^30≒40億
行までのテーブルに対してはほとんどない
○ 偽陽性を削減するという別の意義はある
bucket size b = 8 のときも傾向はほぼ同じ.
Cuckoo Filter: Space Optimizations
前項はtable size m と bucket size b を定数にして,最適なfingerprint size f を調べた.
実際には,finger print size は 6bits くらいがよかろうということで,そこで最適なm / b を考える.
filter の空間効率は(埋まったentry数の平均/全entry数) で求まる.
Cuckoo Filter: Optimal Bucket Size
今度はテーブルサイズを固定して計算・考察した結果,以下の結論が得られた
:
1. Larger buckets improve table occupancy
bucket size を増やせば増やすほど,collision を許容できるので,load factorが上がる.
2. Larger buckets require longer fingerprints to retain the same false positive rate
bucket size を増やすと,同じbucket (hashed key) に多くのentriesが入る.したがってLookupの偽陽性
も上がる.fingerprints を伸ばせばこれに対処できる.
偽陽性とload factorを両立させるbucket size の最適な設定値は・・・?
Cuckoo Filter: Optimal Bucket Size
● false positive rate ε を得るための
space-optimal bucket size を調べる.
● 縦軸は1 item あたりの償却空間計算量
● 横軸は偽陽性発生率
● 0.2 % (ε 0.002) 以上でいいなら,bucket = 2 で
充分.
● 0.00001 < ε < 0.002 まではbucket=4 でいい
● それ以上の精度を求めるなら,
bucketを増やし
ていくことになるが... (inpractical)
● practical に最適な設定値をまとめると
:
○ fingerprint size: 4 bits
○ bucket size: 4
Semi-sorting Buckets to Save Space
bucket size = 4 のときに使える最適化.
● bucket内のentries をソートする.
● entries を単一の変数にencodingする.(4x4 = 16bits)
● 4ビット fingerprints 4つをソートした際の組み合わせの数は
3876通り.
● あらかじめ定数表として全組合わせを定義しておき,
entryには定数表におけるindexを入れる
● 3876エントリは12ビット (4096) で表わせるので,16ビットのbucketが12ビットになった!
● このメモリ節約がキャッシュ効率に効いてくるらしい(
# 評価は先行研究[5]にある)
○ # 間接参照を一個挟むことになるし,素直に vector<uint16> で表現すればいいのでは・・・?
Comparison with Bloom Filter: Space efficiency
● 横軸: 偽陽性εの設定
● 縦軸: 偽陽性εを得るために必要なbit数
● 偽陽性が高い設定だとBFに負ける
○ Bloom filterはハッシュ関数の数 (k),すなわち
insertするbit数で偽陽性を操作するため,偽
陽性が高いとき bit数は下がっていく
● 3% 以下のfalse positive rate ではCuckooの
勝利
● semisort: 12ビットにencodeする最適化
Comparison with Bloom Filter
細かい論点:
1. Memory References / Lookup:
Bloom filterは偽陽性を減らすと ハッシュ関数の数 k が増える.そしてlookupにもinsertionにも k回のメモリアクセスを
要する.Cuckoo は常に定数回 (2回).
2. Value Association:
Cuckoo はもともとhash tableなので, lookup(x) が true のときには (外部にある) xへのポインタも付けて返す,といった
こともできる.(# entryが 12bits + 64bitsになるのでは?)
3. Maximum Capacity:
Bloom Filter は際限なくbit が塗りつぶされて偽陽性が上昇していくが, Cuckooは失敗回数にしきい値がある. load
factor に保証があるようなもので,偽陽性が悪くなりすぎない.
Evaluation
● 500 lines C++ code (efficient/cuckoofilter)
# この人の libcuckoo というhash table実装はすごくいいです
● CityHash というhash関数を使用
● 64bit integersをinsertしていく
● Intel Xeon L5640@2.27GHz, 32GB DRAM
Notations:
● “CF”: cuckoo filter
● “ss-CF”: semi-sorting cuckoo filter
● “BF”: standard bloom filter. less hashing という技法を用いてハッシュ関数2つで(k>2も)実装
● “blk-BF”: blocked bloom filter. 64 bytes (CPU cacheline) にアラインされた array<BF>.
● “QF”: quotient filter
● “dl-CBF”: d-left counting bloom filter.
Evaluation: Achieved False Positive Rate
● 全フィルタを192MBで揃える.CFにおいては m=2^25 程度.
● Bloom filter は k = 9. less hashing によって 192MBの配列のうち13ビットを立てる.
● ss-CF が最も bits per item が小さく,省スペース.false positive rate も最も小さい.
○ false positiveが小さい理由は, bits per item を 12.60 にする (fingerprintsを1ビット足す)状態で実験しているから
● しかし間接参照やencoding/decoding処理のぶん,CFに速度面では劣る.
● insertの速度はblk-BFが速い.
Evaluation: Lookup Performance
● 横軸: positive/negative queryの割合
○ positive: キーがinsertされたことがある
○ negative: insertされたことがない
● キーが全く存在しない(negative) のときに比べ
ると,BFは性能が落ちていく
○ bitが立ってなかったら早期 returnするため
● blk-BFはnegativeなとき効率的だが,positive
になると性能が落ちていく
○ load factorが高いとそうなりがちなので
,practicalにはCFが優れている
● CFは定数(2)回のメモリアクセスなので性能が
落ちることはない.
○ 50%付近で性能が落ちるのは分岐予測ミス
Evaluation: Lookup Performance
● 横軸: load factor (α)
● positive lookup の性能を計測.
● CF/ss-CF の性能はstable.
○ 定数回の(以下略)
● 存在するkey をlookup するという正常系の処
理に関しては,どのfilterもstable.
Evaluation: Lookup Performance
● 横軸: load factor (α)
● negative lookup の性能を計測.
● CF/ss-CF の性能はstable.
○ 定数回の(以下略)
● 偽陽性が高いfilterだと,occupancyが増えると
アルゴリズムが最後まで進行してしまうので,性
能が落ちていく
Evaluation: Insertion Performance
● 横軸: load factor (α)
● Filter の αが高い状態は,空間効率的には好ま
しいが,これ以上のinsertが来ると偽陽性が上
がってしまうことを意味する
● α が上がっていくとinsert が失敗してくれる(性
能が落ちる)性質を持っているほうが
practically better
● CF/ss-CF/QFがそれにあたる
# Cuckoo を選んだ時点で研究の負け筋は
Insertにしかないので,そこ
にこういう理屈をつけられるのはすごく参考になった

More Related Content

PDF
プログラミングコンテストでのデータ構造 2 ~平衡二分探索木編~
PPTX
よくわかるHopscotch hashing
PPTX
充足可能性問題のいろいろ
PDF
ウェーブレット木の世界
PDF
最近のDeep Learning (NLP) 界隈におけるAttention事情
PDF
「世界モデル」と関連研究について
プログラミングコンテストでのデータ構造 2 ~平衡二分探索木編~
よくわかるHopscotch hashing
充足可能性問題のいろいろ
ウェーブレット木の世界
最近のDeep Learning (NLP) 界隈におけるAttention事情
「世界モデル」と関連研究について

What's hot (20)

PDF
プログラミングコンテストでの乱択アルゴリズム
PDF
指数時間アルゴリズム入門
PDF
SAT/SMTソルバの仕組み
PDF
PDF
リクルート式 自然言語処理技術の適応事例紹介
PDF
乱択データ構造の最新事情 -MinHash と HyperLogLog の最近の進歩-
PDF
グラフネットワーク〜フロー&カット〜
PPTX
[DL輪読会]BERT: Pre-training of Deep Bidirectional Transformers for Language Und...
PDF
TensorFlow計算グラフ最適化処理
PDF
ブースティング入門
PDF
ELBO型VAEのダメなところ
PDF
プログラミングコンテストでのデータ構造 2 ~動的木編~
PPTX
NLPにおけるAttention~Seq2Seq から BERTまで~
PPTX
【DL輪読会】SimCSE: Simple Contrastive Learning of Sentence Embeddings (EMNLP 2021)
PDF
最適輸送の解き方
PDF
最小カットを使って「燃やす埋める問題」を解く
PPTX
社会心理学者のための時系列分析入門_小森
PDF
ConvNetの歴史とResNet亜種、ベストプラクティス
PPTX
[DL輪読会]ドメイン転移と不変表現に関するサーベイ
プログラミングコンテストでの乱択アルゴリズム
指数時間アルゴリズム入門
SAT/SMTソルバの仕組み
リクルート式 自然言語処理技術の適応事例紹介
乱択データ構造の最新事情 -MinHash と HyperLogLog の最近の進歩-
グラフネットワーク〜フロー&カット〜
[DL輪読会]BERT: Pre-training of Deep Bidirectional Transformers for Language Und...
TensorFlow計算グラフ最適化処理
ブースティング入門
ELBO型VAEのダメなところ
プログラミングコンテストでのデータ構造 2 ~動的木編~
NLPにおけるAttention~Seq2Seq から BERTまで~
【DL輪読会】SimCSE: Simple Contrastive Learning of Sentence Embeddings (EMNLP 2021)
最適輸送の解き方
最小カットを使って「燃やす埋める問題」を解く
社会心理学者のための時系列分析入門_小森
ConvNetの歴史とResNet亜種、ベストプラクティス
[DL輪読会]ドメイン転移と不変表現に関するサーベイ
Ad

Similar to 論文紹介: Cuckoo filter: practically better than bloom (20)

PDF
Tezos Hands on 2019-06-15 Exercise (Japanese)
PDF
すごいH 第12章モノイド
PDF
並行プログラミングと継続モナド
PDF
エキ Py 読書会02 2010/9/7
PDF
Tezos hands-on : Tezos exercise
PPTX
C# 7.2 with .NET Core 2.1
PDF
[db tech showcase Tokyo 2016] D27: Next Generation Apache Cassandra by ヤフー株式会...
PDF
Boost tour 1_40_0
PDF
「入門Kubernetes」輪読会資料 6章
PDF
Chainerチュートリアル -v1.5向け- ViEW2015
PDF
EucalyptusのHadoopクラスタとJaqlでBasket解析をしてHiveとの違いを味わってみました
PDF
Programming Hive Reading #3
PDF
TensorFlow XLAは、 中で何をやっているのか?
PDF
2018年度 若手技術者向け講座 大量データの扱い・ストアド・メモリ管理
PDF
CouchDB JP & BigCouch
PPTX
関数型言語&形式的手法セミナー(3)
PDF
appengine ja night #4 Transaction Puzzlers
PDF
R-hpc-1 TokyoR#11
PDF
Intel TSX HLE を触ってみた x86opti
PDF
boost::shared_ptr tutorial
Tezos Hands on 2019-06-15 Exercise (Japanese)
すごいH 第12章モノイド
並行プログラミングと継続モナド
エキ Py 読書会02 2010/9/7
Tezos hands-on : Tezos exercise
C# 7.2 with .NET Core 2.1
[db tech showcase Tokyo 2016] D27: Next Generation Apache Cassandra by ヤフー株式会...
Boost tour 1_40_0
「入門Kubernetes」輪読会資料 6章
Chainerチュートリアル -v1.5向け- ViEW2015
EucalyptusのHadoopクラスタとJaqlでBasket解析をしてHiveとの違いを味わってみました
Programming Hive Reading #3
TensorFlow XLAは、 中で何をやっているのか?
2018年度 若手技術者向け講座 大量データの扱い・ストアド・メモリ管理
CouchDB JP & BigCouch
関数型言語&形式的手法セミナー(3)
appengine ja night #4 Transaction Puzzlers
R-hpc-1 TokyoR#11
Intel TSX HLE を触ってみた x86opti
boost::shared_ptr tutorial
Ad

More from Sho Nakazono (11)

PDF
述語ロックの歴史 r2
PPTX
Checkpointing Algorithms on In-memory DBMS
PDF
LineairDBの紹介 MySQL編
PDF
LineairDBの紹介
PDF
詳説データベース輪読会: 分散合意その2
PPTX
ファントム異常を排除する高速なトランザクション処理向けインデックス
PDF
LineairDB: Fast and Embedded Transactional Key-Value Storage
PPTX
輪読資料: Staring into the abyss an evaluation of concurrency control with one t...
PPTX
[xSIG 2018]InvisibleWriteRule: Extended write protocol for 1VCC
PDF
論文紹介: An empirical evaluation of in-memory multi-version concurrency control
PDF
並行実行制御の最適化手法
述語ロックの歴史 r2
Checkpointing Algorithms on In-memory DBMS
LineairDBの紹介 MySQL編
LineairDBの紹介
詳説データベース輪読会: 分散合意その2
ファントム異常を排除する高速なトランザクション処理向けインデックス
LineairDB: Fast and Embedded Transactional Key-Value Storage
輪読資料: Staring into the abyss an evaluation of concurrency control with one t...
[xSIG 2018]InvisibleWriteRule: Extended write protocol for 1VCC
論文紹介: An empirical evaluation of in-memory multi-version concurrency control
並行実行制御の最適化手法

論文紹介: Cuckoo filter: practically better than bloom

  • 1. Cuckoo Filter: Practically Better Than Bloom 紹介: nikezono Bin Fan, Dave G. Andersen, Michael Kaminsky, and Michael D. Mitzenmacher. 2014. Cuckoo Filter: Practically Better Than Bloom. In Proceedings of the 10th ACM International on Conference on emerging Networking Experiments and Technologies (CoNEXT '14). Association for Computing Machinery, New York, NY, USA, 75–88. DOI:https://doi.org/10.1145/2674005.2674994
  • 2. 概要 ● ブルームフィルタ(Bloom Filter) の改善提案 ● Hash Table の改善であるCuckoo Hashing が元ネタ ○ Cuckoo Hashing を使って Filter を作った、ということ ● Bloom Filter に比べて以下の改善点がある ○ “Delete” operationが追加 ○ Lower space overhead ○ Lower false positive rates ● 最近盛り上がりを見せている(?) ○ VLDB’21 では Cuckoo Index という Secondary Index for data skipping が提案 ○ SIGMOD’21 では Conditional Cuckoo Filters という Join 演算を可能にする variantが提案
  • 3. Cuckoo Hashing 101 まず、Cuckoo Filterの前提知識となるCuckoo Hashingについて. ● Open addressing hash table の一種.2001年に提案. ● Hash table はハッシュ関数を一つしか持たないが、 Cuckoo Hashingは2つ持つ. ● Insert(key, value) に対して: ○ よくあるHash table: Insert(key, value) => { Table [h(key) % sizeof(Table)] = value } i. 衝突したら線形リストを作ったり,線形に空きスロットを探索したり. ○ Cuckoo Hashing: i. Table[h1(key)] か Table[h2(key)] が空いている => そこに入る ii. 空いていない(衝突してる) => 入っていたやつ (key’) を追い出す! 1. key’ が h1(key’) のスロットに入っているとする : 2. Table[h2(key’)] をルックアップ.空いているならそこに key’ を引っ越し 3. 空いていない => 入っていた key (key’’) を追い出す!goto 1 iii. ループしすぎたら満員と判定して Tableをextendする
  • 4. Cuckoo Hashing 101 特徴 ● Lookupは O(1~2), 最悪計算量がO(2).こ れは強い! ● Insertionの最悪計算量は保証がない(満 員でも気付かない) ○ 無限にループできる ○ 適当なしきい値を決定してどこかで諦め る(≒ rehashする) 必要がある ○ それはオープンアドレッシング系ハッシュ テーブルの宿命で, Cuckoo特有の弱点 ではないが・・・ ○ しかし償却計算量は O(1)
  • 5. Bloom Filter 101 次に,Cuckoo Filter の元ネタとなるBloom Filter について. ● approximate set membership testing のためのデータ構造. ● k 個の ハッシュ関数を持つ. ● Insert(key) => k回 h(key)してヒットしたindexのビットを立てる ● Lookup(key) => k回 h(key) して全ビット立っていれば(maybe) True ● Delete(key) => できません! Bloom filter. (2021.09.06.). In Wikipedia. https://en.wikipedia.org/wiki/Bloom_filter
  • 6. Cuckoo Filter Bloom Filter を Cuckoo Hashing のテクニックを使って改善したもの. 貢献は以下: 1. It supports adding and removing items dynamically; 2. It provides higher lookup performance than traditional Bloom filters, even when close to full (e.g., 95% space utilized); 3. It is easier to implement than alternatives such as the quotient filter; and 4. It uses less space than Bloom filters in many practical applications, if the target false positive rate is less than 3%.
  • 7. Cuckoo Filter: Introduction A cuckoo filter is a compact variant of a cuckoo hash table [21] that stores only fingerprints—a bit string derived from the item using a hash function—for each item inserted, instead of key-value pairs. … A set membership query for item x simply searches the hash table for the fingerprint of x, and returns true if an identical fingerprint is found. Cuckoo Filterは Cuckoo Hashing をほぼそのまま使っている. Hashing は Key/Value を保存できるHash table だが, Filter のほうは Valueに fingerprint を保存する. Lookup はこの fingerprint をHash table から検索する処理になる. fingerprint をどう作るか,という設計がフィルタの性能(偽陽性)を左右する.
  • 8. Cuckoo Filter: Figure 1 ● Key: index (uint) ● Value (bucket): 4 entries ○ すべて fingerprint が保存される ○ 4回までcollision してもいいということ ○ いろいろ計算量理論的な話が出てきますが, 実験に使っているのはこの構造です
  • 9. Cuckoo Filter: Introduction Interestingly, while we show that cuckoo filters are practically better than Bloom filters for many real workloads, they are asymptotically worse: the minimum fingerprint size used in the cuckoo filter grows logarithmically with the number of entries in the table. Cuckoo Filterは Practical にはBloomより性能が良いが,テーブルサイズが増大すると漸近的に性能が悪 くなっていく.fingerprint の最小サイズがテーブルサイズに対して増大していく. (ので,空間効率もキャッシュ効率も悪くなる) ここでいう Practical は < billion items
  • 10. Cuckoo Filter: Related Work ● Cuckoo は 削除ができてかつ空間計算量が 少ない.キャッシュミス回数も少ない. 各手法の(雑な)説明 ● blocked: CPUキャッシュラインにサイズを合わせた複数 の配列で構成する BF ● counting: 各bucketをboolから4bit以上のuintに変更し て削除可能にする BF ● d-left: counting + fingerprint. ● quotient: hash table (linear probing) で実装するfilter?
  • 11. 2.2 Using Cuckoo Hashing for Set-membership もと, cuckoo hash tableを set membership testing に使う例は過去にもいくつかある.この論文の著者陣はも ともと cuckoo hash table を使ってset-membership testing の研究をしていた. partial-key cuckoo hashing と呼ばれるテクニックを使ってhash table / NW switch を改善してきたが, そのテクニックをBloom Filter 化したCuckoo に用いる,というのが今回の論旨. Recently, standard cuckoo hash tables have been used to provide set membership information in a few applications. … Our previous study in building high-speed and memory efficient key-value stores [17, 11] and software-based Ethernet switches [26] all applied cuckoo hash tables as internal data structures. That work was motivated by and also focused on improving hash table performance by an optimization called partial-key cuckoo hashing. However, as we show in this paper, this technique also enabled a new approach to build a Bloom filter replacement which has not been studied before.
  • 12. Cuckoo Filter: Insert 1. hash 関数を用いてindexを2つ作る. 2. どちらかのbucketが空いていたら終了      # 「同じfingerprintがあれば終了」ではないのがポイント.後述. 3. 両方埋まっている: a. どちらかのbucketを引っ越し. b. 以下ループ・・・は Cuckoo Hashingと同じ 問題はreallocateの際にある. fingerprint しか保存していない ため,オリジナルのキーの rehash ができない … i.e., h1(key) の 結果と keyの断片しか持っていない状態で, h2(key) を求めなく てはならない. ここでは partial-key cuckoo hashing という手法を使う.
  • 13. Partial-key Cuckoo Hashing The xor operation … ensures an important property: h1(x) can also be calculated from h2(x) and the fingerprint using the same formula. In other words, to displace a key originally in bucket i (no matter if i is h1(x) or h2(x)), we directly calculate its alternate bucket j from the current bucket index i and the fingerprint stored in this bucket by このやり方でh1(x), h2(x) を作ると,片方のbucket (h1(x) or h2(x))とfingerprintがわかっていれば,もう片方 のbucket が求められる.ハッシュ関数2つを使うのと異なり,衝突もしない.さらに `sizeof(fingerprint)` ビット 離れたindexとなることが保証されるため,空間効率も良くなる.( #?)
  • 14. Cuckoo Filter: Lookup Notice that this ensures no false negatives as long as bucket overflow never occurs.
  • 15. Cuckoo Filter: Delete 削除もシンプル. 1. Lookup(x) を行う. 2. fingerprint がマッチするエントリがあれば,削除す る. Notes: ● fingeprint collisionが起きている場合, false deletion problem は起きない.Insert(x) のときに重 複挿入を許しているため,削除一回につき同じ bucket の entry は一つしか消さないので,bucket が溢れない限り問題ない.
  • 16. Cuckoo Filter: Asymptotic Behavior Minimal Fingerprint Size: ● f bits のfingerprint size を選択すると,hashの結果は2^f 通り ● m buckets 用意したtable で, 2^f < m ならば綺麗に収まる ● Delete も Lookup も最悪時間計算量O(2)で終わるので,重要なのは Insert(x) の性能 ● f or m が小さいとcollision が増える=> Insert(x) の償却計算量が増えてしまう ● 充分に長い2つのkey x, y のfingerprints がcollision する確率は1/(2^f) ● fingerprintsはcollisionしていないが同じbucketが割り当てられてしまう確率は2/m ● したがってq のitemsが bucket を共有(collision)してしまう確率は ● The construction process (#? スミマセン...) の結果 n: number of items. b: number of entries per bucket. `n` に応じてfingerprint size が増えていくのは(著者陣含め)懸念点. Bloom Filterは各 entry で 1bit しか要求しない. が, `b` を調整すればfingerprintは (practicalには) 小さく保たれる.
  • 17. Cuckoo Filter: Asymptotic Behavior Empirical Evaluation: ● 64bit random key insertion で実験. ● Kick のしきい値は 500; これに到達したら実験終 了 ● m (テーブルサイズ) も変えて実験. ○ 実験環境の制約から m=2^30 以上はできなかっ たらしい ● load factor: 占有率はfingerprintが一定以上長け れば充分に理想的(95%) ● むしろ fingerprint > 4 にする意義は2^30≒40億 行までのテーブルに対してはほとんどない ○ 偽陽性を削減するという別の意義はある bucket size b = 8 のときも傾向はほぼ同じ.
  • 18. Cuckoo Filter: Space Optimizations 前項はtable size m と bucket size b を定数にして,最適なfingerprint size f を調べた. 実際には,finger print size は 6bits くらいがよかろうということで,そこで最適なm / b を考える. filter の空間効率は(埋まったentry数の平均/全entry数) で求まる.
  • 19. Cuckoo Filter: Optimal Bucket Size 今度はテーブルサイズを固定して計算・考察した結果,以下の結論が得られた : 1. Larger buckets improve table occupancy bucket size を増やせば増やすほど,collision を許容できるので,load factorが上がる. 2. Larger buckets require longer fingerprints to retain the same false positive rate bucket size を増やすと,同じbucket (hashed key) に多くのentriesが入る.したがってLookupの偽陽性 も上がる.fingerprints を伸ばせばこれに対処できる. 偽陽性とload factorを両立させるbucket size の最適な設定値は・・・?
  • 20. Cuckoo Filter: Optimal Bucket Size ● false positive rate ε を得るための space-optimal bucket size を調べる. ● 縦軸は1 item あたりの償却空間計算量 ● 横軸は偽陽性発生率 ● 0.2 % (ε 0.002) 以上でいいなら,bucket = 2 で 充分. ● 0.00001 < ε < 0.002 まではbucket=4 でいい ● それ以上の精度を求めるなら, bucketを増やし ていくことになるが... (inpractical) ● practical に最適な設定値をまとめると : ○ fingerprint size: 4 bits ○ bucket size: 4
  • 21. Semi-sorting Buckets to Save Space bucket size = 4 のときに使える最適化. ● bucket内のentries をソートする. ● entries を単一の変数にencodingする.(4x4 = 16bits) ● 4ビット fingerprints 4つをソートした際の組み合わせの数は 3876通り. ● あらかじめ定数表として全組合わせを定義しておき, entryには定数表におけるindexを入れる ● 3876エントリは12ビット (4096) で表わせるので,16ビットのbucketが12ビットになった! ● このメモリ節約がキャッシュ効率に効いてくるらしい( # 評価は先行研究[5]にある) ○ # 間接参照を一個挟むことになるし,素直に vector<uint16> で表現すればいいのでは・・・?
  • 22. Comparison with Bloom Filter: Space efficiency ● 横軸: 偽陽性εの設定 ● 縦軸: 偽陽性εを得るために必要なbit数 ● 偽陽性が高い設定だとBFに負ける ○ Bloom filterはハッシュ関数の数 (k),すなわち insertするbit数で偽陽性を操作するため,偽 陽性が高いとき bit数は下がっていく ● 3% 以下のfalse positive rate ではCuckooの 勝利 ● semisort: 12ビットにencodeする最適化
  • 23. Comparison with Bloom Filter 細かい論点: 1. Memory References / Lookup: Bloom filterは偽陽性を減らすと ハッシュ関数の数 k が増える.そしてlookupにもinsertionにも k回のメモリアクセスを 要する.Cuckoo は常に定数回 (2回). 2. Value Association: Cuckoo はもともとhash tableなので, lookup(x) が true のときには (外部にある) xへのポインタも付けて返す,といった こともできる.(# entryが 12bits + 64bitsになるのでは?) 3. Maximum Capacity: Bloom Filter は際限なくbit が塗りつぶされて偽陽性が上昇していくが, Cuckooは失敗回数にしきい値がある. load factor に保証があるようなもので,偽陽性が悪くなりすぎない.
  • 24. Evaluation ● 500 lines C++ code (efficient/cuckoofilter) # この人の libcuckoo というhash table実装はすごくいいです ● CityHash というhash関数を使用 ● 64bit integersをinsertしていく ● Intel Xeon L5640@2.27GHz, 32GB DRAM Notations: ● “CF”: cuckoo filter ● “ss-CF”: semi-sorting cuckoo filter ● “BF”: standard bloom filter. less hashing という技法を用いてハッシュ関数2つで(k>2も)実装 ● “blk-BF”: blocked bloom filter. 64 bytes (CPU cacheline) にアラインされた array<BF>. ● “QF”: quotient filter ● “dl-CBF”: d-left counting bloom filter.
  • 25. Evaluation: Achieved False Positive Rate ● 全フィルタを192MBで揃える.CFにおいては m=2^25 程度. ● Bloom filter は k = 9. less hashing によって 192MBの配列のうち13ビットを立てる. ● ss-CF が最も bits per item が小さく,省スペース.false positive rate も最も小さい. ○ false positiveが小さい理由は, bits per item を 12.60 にする (fingerprintsを1ビット足す)状態で実験しているから ● しかし間接参照やencoding/decoding処理のぶん,CFに速度面では劣る. ● insertの速度はblk-BFが速い.
  • 26. Evaluation: Lookup Performance ● 横軸: positive/negative queryの割合 ○ positive: キーがinsertされたことがある ○ negative: insertされたことがない ● キーが全く存在しない(negative) のときに比べ ると,BFは性能が落ちていく ○ bitが立ってなかったら早期 returnするため ● blk-BFはnegativeなとき効率的だが,positive になると性能が落ちていく ○ load factorが高いとそうなりがちなので ,practicalにはCFが優れている ● CFは定数(2)回のメモリアクセスなので性能が 落ちることはない. ○ 50%付近で性能が落ちるのは分岐予測ミス
  • 27. Evaluation: Lookup Performance ● 横軸: load factor (α) ● positive lookup の性能を計測. ● CF/ss-CF の性能はstable. ○ 定数回の(以下略) ● 存在するkey をlookup するという正常系の処 理に関しては,どのfilterもstable.
  • 28. Evaluation: Lookup Performance ● 横軸: load factor (α) ● negative lookup の性能を計測. ● CF/ss-CF の性能はstable. ○ 定数回の(以下略) ● 偽陽性が高いfilterだと,occupancyが増えると アルゴリズムが最後まで進行してしまうので,性 能が落ちていく
  • 29. Evaluation: Insertion Performance ● 横軸: load factor (α) ● Filter の αが高い状態は,空間効率的には好ま しいが,これ以上のinsertが来ると偽陽性が上 がってしまうことを意味する ● α が上がっていくとinsert が失敗してくれる(性 能が落ちる)性質を持っているほうが practically better ● CF/ss-CF/QFがそれにあたる # Cuckoo を選んだ時点で研究の負け筋は Insertにしかないので,そこ にこういう理屈をつけられるのはすごく参考になった