Cuckoo Hashing and CAMs Michael Mitzenmacher. Background For the past several years, I have had funding from Cisco to research hash tables and related.

Slides:



Advertisements
Similar presentations
Multiple Choice Hash Tables with Moves on Deletes and Inserts Adam Kirsch Michael Mitzenmacher.
Advertisements

Hash Tables.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Why Simple Hash Functions Work : Exploiting the Entropy in a Data Stream Michael Mitzenmacher Salil Vadhan.
Hash-Based Indexes The slides for this text are organized into chapters. This lecture covers Chapter 10. Chapter 1: Introduction to Database Systems Chapter.
CSCE 3400 Data Structures & Algorithm Analysis
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11.
Lecture 11 oct 6 Goals: hashing hash functions chaining closed hashing application of hashing.
Optimal Fast Hashing Yossi Kanizo (Technion, Israel) Joint work with Isaac Keslassy (Technion, Israel) and David Hay (Hebrew Univ., Israel)
A Look at Modern Dictionary Structures & Algorithms Warren Hunt.
Hashing21 Hashing II: The leftovers. hashing22 Hash functions Choice of hash function can be important factor in reducing the likelihood of collisions.
Randomized Algorithms Lecturer: Moni Naor Cuckoo Hashing.
Cuckoo Hashing : Hardware Implementations Adam Kirsch Michael Mitzenmacher.
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 3 Tuesday, 2/9/10 Amortized Analysis.
1 Hash-Based Indexes Yanlei Diao UMass Amherst Feb 22, 2006 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Hash Tables With Finite Buckets Are Less Resistant to Deletions Yossi Kanizo (Technion, Israel) Joint work with David Hay (Columbia U. and Hebrew U.) and.
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Lecture 3 Tuesday, 2/10/09 Amortized Analysis.
Why Simple Hash Functions Work : Exploiting the Entropy in a Data Stream Michael Mitzenmacher Salil Vadhan.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.
Advanced Algorithms for Massive Datasets Basics of Hashing.
Optimal Fast Hashing Yossi Kanizo (Technion, Israel) Joint work with Isaac Keslassy (Technion, Israel) and David Hay (Politecnico di Torino, Italy)
Some Open Questions Related to Cuckoo Hashing Michael Mitzenmacher Harvard University.
Tirgul 7. Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys.
Lecture 11 oct 7 Goals: hashing hash functions chaining closed hashing application of hashing.
Hashing General idea: Get a large array
L. Grewe. Computing hash function for a string Horner’s rule: (( … (a 0 x + a 1 ) x + a 2 ) x + … + a n-2 )x + a n-1 ) int hash( const string & key )
History-Independent Cuckoo Hashing Weizmann Institute Israel Udi WiederMoni NaorGil Segev Microsoft Research Silicon Valley.
Hashing and Packet Level Algorithms
Data Structures Hashing Uri Zwick January 2014.
1. 2 Problem RT&T is a large phone company, and they want to provide enhanced caller ID capability: –given a phone number, return the caller’s name –phone.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
Trevor Brown – University of Toronto B-slack trees: Space efficient B-trees.
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
1 HashTable. 2 Dictionary A collection of data that is accessed by “key” values –The keys may be ordered or unordered –Multiple key values may/may-not.
Appendix E-A Hashing Modified. Chapter Scope Concept of hashing Hashing functions Collision handling – Open addressing – Buckets – Chaining Deletions.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
10/18: Lecture topics Memory Hierarchy –Why it works: Locality –Levels in the hierarchy Cache access –Mapping strategies Cache performance Replacement.
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
CSE373: Data Structures & Algorithms Lecture 17: Hash Collisions Kevin Quinn Fall 2015.
CS201: Data Structures and Discrete Mathematics I Hash Table.
Ihab Mohammed and Safaa Alwajidi. Introduction Hash tables are dictionary structure that store objects with keys and provide very fast access. Hash table.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Indexed Sequential Access Method.
Hash Table March COP 3502, UCF 1. Outline Hash Table: – Motivation – Direct Access Table – Hash Table Solutions for Collision Problem: – Open.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision handling Separate chaining.
Cuckoo Filter: Practically Better Than Bloom Author: Bin Fan, David G. Andersen, Michael Kaminsky, Michael D. Mitzenmacher Publisher: ACM CoNEXT 2014 Presenter:
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
Hashing (part 2) CSE 2011 Winter March 2018.
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
Algorithmic Improvements for Fast Concurrent Cuckoo Hashing
Hash table CSC317 We have elements with key and satellite data
Hashing - resolving collisions
Hashing Exercises.
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Resolving collisions: Open addressing
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Data Structures and Algorithms
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Database Systems (資料庫系統)
EMOMA- Exact Match in One Memory Access
Collision Handling Collisions occur when different elements are mapped to the same cell.
CSE 373: Data Structures and Algorithms
Presentation transcript:

Cuckoo Hashing and CAMs Michael Mitzenmacher

Background For the past several years, I have had funding from Cisco to research hash tables and related data structures for approximate measuring/monitoring on routers. Extreme conditions: –Limited space. –Limited # of memory accesses. –Amenable to hardware implementation. Hardware setting allows CAMs. Question: what are the extreme conditions for hashing applications at Google?

Theme of The Talk How can we use CAMs (content addressable memories) to improve and make more practical cuckoo hashing, a potentially breakthrough hashing approach.

CAMs CAM = content addressable memory –Fully associative lookup. –Usually expensive, so must be kept small. Not usually considered in theoretical work, but very useful in practice. Can we bridge this gap? –What can CAMs do for us?

Cuckoo Hashing [Pagh,Rodler] Basic scheme: each element gets two possible locations. To insert x, check both locations for x. If one is empty, insert. If both are full, x kicks out an old element y. Then y moves to its other location. If that location is full, y kicks out z, and so on, until an empty slot is found.

Cuckoo Hashing Examples ABC ED

ABC ED F

ABFC ED

ABFC ED G

EGBFC AD

ABC ED F G

Good Properties of Cuckoo Hashing Worst case constant lookup time. Simple to build, design.

Cuckoo Hashing Failures Bad case 1: inserted element runs into cycles. Bad case 2: inserted element has very long path before insertion completes. –Could be on a long cycle. Bad cases occur with very small probability when load is sufficiently low. Theoretical solution: re-hash everything if a failure occurs.

Basic Performance For 2 choices, load less than 50%, n elements gives failure rate of  (1/n); maximum insert time O(log n). Generalizations for more than 2 choices possible. –Place if possible; if not, place by kicking out a random choice, and so on. –Random walk multi-choice variant not fully analyzed; lots of open questions. –Good empirical performance. –An “impractical” BFS variant has failure rate  (1/n d-1 ) for d choices.

Problems to be Considered Reduce the failure probability. –Re-hashing generally not an option in router setting, and very expensive in other settings. Reduce number of moves per insert. –Insert times may need to be bounded by constant in router setting. CAMs provide help for both problems.

Failure Probability Reduction Failure occurs when an element cannot be placed in one of its choices within a certain number (O(log n)) moves. Standard cuckoo hashing: failure rate is too high for many applications. –Even with multiple choices per element. –Re-hashing an expensive option, although theoretically appealing.

A CAM-Stash Use a CAM to stash away elements that would cause failure. Intuition: if failures were independent, probability that s elements cause failures goes to  (1/n s ). –Failures not independent, but nearly so. –A stash holding a constant number of elements greatly reduces failure probability. –Implemented as a CAM in hardware, or a cache line in hardware/software. Lookup requires also looking at stash.

Analysis Method Treat cells as vertices, elements as edges in bipartite graph. Count components that have excess edges to be placed in stash. Random graph analysis to bound excess edges. 6 vertices, 7 edges: 1 edge must go into stash.

A Simple Experiment 10,000 items, table of size 24,000, 2 choices per element, 10 7 trials. Stash SizeFailures

Generalizations Can similarly generalize known results for cuckoo hashing with more than 2 choices, more than 1 element per bucket. Stash of size s reduces failure exponent linearly in s. Intuition: random graph analysis exposes “bottleneck” in cuckoo hashing. Stashes relieve the bottleneck.

Summary A CAM-stash greatly improves potential utility of cuckoo hashing. –Drives failures down to ignorable levels. –Constant-sized, so cheap. More details in ESA 2008 paper (Kirsch/Mitzenmacher/Wieder). Applies to other uses of cuckoo hashing. –History-independent cuckoo hashing, Naor/Segev/Wieder.

Insertion Time Problems Lots of moves per insert in worst case. –Average is constant. –But maximum is  (log n) with non-trivial (inverse-poly) probability. Router hardware setting: may need bounded number of memory accesses per insert.

A CAM-Queue Insertion is a sequence of suboperations. –Of form “Move x to position H j (x).” Use the CAM as a queue for pending suboperations. Perform suboperations from queue as available. –Move attempt = 1 lookup/write. –A suboperation may cause another suboperation to go on the queue. Lookup: check the hash table and the CAM-queue. De-amortization –Use queue to turn worst-case performance into average- case performance.

Queue Policy Can reorder suboperations and maintain correctness. Key point: better to give priority to “new” insertions over moves. –New insertions have d choices; moves effectively have d – 1. Intuition suggests older elements may be less likely to be successfully placed. –True in practice. Full priority queue may be too complex. Simple strategy: new elements placed at front, failed moves places at back.

Experimental Evaluation Table of size 32768, 4 subtables. Target utilization u. Insert 32678u elements, then alternate insertions/deletions to get to steady state. Allow ops queue operations (parallel memory operations) per insertion.

Moves Needed per Insertion

Probability of Success vs. Age

Queue Sizes Need CAM sized to overflow with negligible probability. Maximum queue size much bigger than average. Currently no analysis. Experiments suggest queues of size in small 100s possible, with 4+ suboperations per insert, in practice.

Summary A CAM-queue can allow effective deamortization of cuckoo hashing. –Insertion time constant at expense of a CAM to hold pending suboperations. –Could other data structures use this deamortization technique? More details in Allerton 2008 paper (Kirsch/Mitzenmacher).

Insertion Time Problems Lots of moves per insert in worst case. –Average is constant. –But maximum is  (log n) with non-trivial (inverse-poly) probability. Router hardware settings: may need bounded number of memory accesses per insert.

Alternative Approach : Power of One Move Limit to just one additional move per insert. –One move likely to be possible in practice. –Simple for hardware. –Some analysis possible via differential equations. Insertions only case can be analyzed; deletions approximated. Easier to analyze than cuckoo hashing. But with limited inserts, will need a CAM to hold a non-trivial number of elements that cannot be placed.

Multilevel Hash Table [BK90] Use a multilevel hash table (MHT) –Can store n elements with d = log log n + O(1) levels in O(n) space with high probability –Example with d = 4 hash functions Skew: more elements placed by early hash functions (double exponential decay) x Level

A CAM-Stash Redux In practice, want d to be a constant. Constant number of levels implies constant probability of an overflow per element. –But probability is very small. Need a stash to hold a constant fraction of the elements. Aim for small constant fraction, e.g. expected 0.2% of the elements overflow.

Example Schemes Standard: MHT with no moves. Conservative : Place element if possible. If not, try to move earliest element that has not already replaced another element to make room. Otherwise spill over. Second chance : Read all possible locations, and for each location with an element, check it it can be placed in the next subtable. Place new element as early as possible, moving up to 1 element left 1 level. Second chance 2: Second chance with 2 elements/bucket.

Second Chance (SC) Scheme Standard MHT fills from top down –elements cascade from table to table. –We try to slow cascade at every step. Standard MHT Insertion x

Second Chance (SC) Scheme Standard MHT fills from top down –elements cascade from table to table. –We try to slow cascade at every step. x

Second Chance (SC) Scheme Standard MHT fills from top down –elements cascade from table to table. –We try to slow cascade at every step. x

Implementing SC in Hardware 1.Read x’s d hash locations in parallel. x

Implementing SC in Hardware 1.Read x’s d hash locations in parallel. 2.Hash discovered elements in parallel. x

Implementing SC in Hardware 1.Read x ’s d hash locations in parallel. 2.Hash discovered elements in parallel. 3.Insert x, performing a move if necessary. x

Results of Moves : Insertions Only Space overhead, balanced Space overhead, skewed Fraction moved, skewed No moves % Conservative % Second Choice % Second Choice, %

Performance with Deletions

Stash Size Distribution Number of elements at each level is approximately a sum of independent Poisson trials. When mean is large, approximately normal. When mean is small, approximately Poisson. –Use Poisson distribution to approximate stash size distribution, to roughly estimate needed stash size for a failure probability.

Poisson Distributed Stash

Summary Even one move saves significant space. But with deletions things are more complex, more space required. Some schemes amenable to fluid limit, differential equation analysis. CAM-stash has different asymptotics in this setting. –Linear size vs. constant-sized.

Conclusions CAMs a very powerful tool for hash-based data structures. –Flexible uses: stash, queue. –Deal effectively with low probability events. Generally not considered in theoretical analysis. –But should be! –Scaling: linear, logarithmic, constant size CAMs? Can help give high-performance, space-efficient hash tables. –Cuckoo hashing: constant time lookups, good space utilization, low failure probability, simple and flexible.

Open Questions and Future Work Analyze practical multiple choice cuckoo hashing variants for d > 2 choices. Analysis of CAM-queue for cuckoo hashing. Better methods of dealing with settings with frequent deletions. Your question here…