SlideShare a Scribd company logo
1 of 46
Parallel Hashing Algorithms
Prepared By :
Akash Panchal (14MCEC17) & Nisarg Patel (14MCEC20)
@Nirma University, Ahmedabad
Concurrent hash table
•Indexing key-value objects
• Lookup(key)
• Insert(key, value)
• Delete(key)
•Fundamental building block for modern systems
• System applications (e.g., kernel caches)
• Concurrent user-level applications
Goal: memory-efficient and high-throughput
• Memory efficient (e.g., > 90% space utilized)
• Fast concurrent reads (scale with # of cores/threads)
• Fast concurrent writes (scale with # of cores/threads)
separate chaining hash table
K V
K V
K V
K V
K V
Chaining items hashed in same bucket
lookup K V
separate chaining hash table
- Acquiring a Linked List Node Location
- Only one thread should insert new node.
- find the end of the linked list, lock out other
threads.
- Make sure we are still at the end of the linked
list.
- Then allocate a new node from the unfilled
region, and finally link it in.
Good: simple
Bad: poor cache locality
Bad: pointers cost space
separate chaining hash table
open addressing hash table
Probing alternate locations for vacancy
e.g., linear/quadratic probing, double hashing
- Inserting a Key :
- 1) The bucket is empty.
- Must acquire a location.
- TwoStepAcquireAttempt algorithm is used.
- Insert the key.
- 2) The bucket is already filled.
- Find next possible bucket using any probing
method.
Procedure: TwoStepAcquireAttempt
Parameters: (location, key)
// first check without locking
1: if location is empty then
2: lock(location)
// then check with the lock
3: if location is still empty then
4: Reserve location for key
5: unlock(location)
6: return true
7: end if
// Another thread modified the structure before we could acquire location
8: unlock(location)
9: end if
10: return false . // Caller needs to continue searching
open addressing hash table
Probing alternate locations for vacancy
lookup
Good: cache friendly
Bad: poor memory efficiency
- performance dramatically degrades when the
usage grows beyond 70% capacity or so
- e.g., Google dense_hash_map wastes 50%
memory by default.
Linear Hashing with linear Probing
H1 H2 H3 H4 H5 H6 H7 H8 H9 h10
Parallel Insert :
Case 1 : Two keys are inserted at different location.
xH1 = insert( ) yH5 = insert( )
Pass : Pass 1
Linear Hashing with linear Probing
H1 H2 H3 H4 H5 H6 H7 H8 H9 h10
s u t
Parallel Insert :
Case 2 : Two keys are inserted at different location but collision occurs.
xH1 = insert( ) yH5 = insert( )
Pass : Pass 1 Pass 2 Pass 3
Linear Hashing with linear Probing
H1 H2 H3 H4 H5 H6 H7 H8 H9 h10
xH1 = insert( ) yH1 = insert( )
Pass : Pass 1
Parallel Insert :
Case 3 : Two keys tried to insert at same location and contention occurred.
x y
Pass 2
Analysis : linear hashing
Serial Approach Parallel Approach
Lookup : Best case : O(n)
Worst Case : O(n2)
Best case : O(1),
Worst case : O(n)
Insert Best Case : O(n),
Worst Case : O(n2)
Best case : O(1)
Worst Case : O(n)
Removal : Best case : O(n),
Worst Case : O(n2)
Best case : O(1)
Worst case : O(n)
Cuckoo hashing
• Use two hash tables and two hash functions
• Each element will have exactly one “nest” (hash location) in each table
• Guarantee that any element will only ever exist in one of its “nests”.
• Lookup/delete are O(1) because we can check 2 locations (“nests”) in O(1) time.
Cuckoo hashing
Insertion :
1. Insert an element by finding one of its “nests” and
putting it there
• This may evict another element!
2. Insert the evicted element into its *other* “nest”
This may evict another element!
X
Cuckoo hashing in Sequential: ‘X’ is inserted by moving ‘Y’ and ‘Z’
Cuckoo hashing
Asymmetric cuckoo hashing :
• Choose one (the first) table to be larger than
the other
– Improves the probability that we get a hit on the
first lookup
– Only a minor slowdown on insert
Cuckoo hashing
Same Table cuckoo Hashing :
• We didn’t actually need two separate tables.
– It made the analysis much easier.
– But… In practice, we just need two hash functions.
Cuckoo hashing
Each bucket has b slots for items (b-way set-associative)
Each key is mapped to two random buckets
• stored in one of them
buckets
0
1
2
3
4
5
6
7
8
key x
hash1(x)
hash2(x)
Predictable and fast lookup
• Lookup: read 2 buckets in parallel
• constant time in the worst case
x
0
1
2
3
4
5
6
7
8
Lookup x
0
1
2
3
4
5
6
7
8
move keys to alternate buckets
Insert may need “cuckoo move”
• Insert:
Both are full?
Insert y a
x
b
k
r
c
s
e
n
f
x
a
bWrite to an empty slot in
one of the
possible
locations
x
a
b possible
locations
possible
locations
Insert may need “cuckoo move”
• Insert: move keys to alternate buckets
• find a “cuckoo path” to an empty slot
• move hole backwards
0
1
2
3
4
5
6
7
8
Insert y
x
a
b
y
b
a
x
Case 1 : Inserting ‘a’ and ‘b’ in parallel, ‘b’ find its place in 1st hash function and ‘a’
has to evict value.
k
Case 2 : Inserting ‘a’ and ‘b’ in parallel, ‘a’ and ‘b’ has to evict value.
Algorithmic optimizations
• Lock after discovering a cuckoo path
• minimize critical sections
• But…
• Decreases parallelization
Previous approach: writer locks the table
during the whole insert process
lock();
Search for a cuckoo path;
Cuckoo move and insert;
unlock();
All Insert operations of other threads are blocked
Case 3 : Inserting ‘a’ and ‘b’ in parallel, ‘a’ and ‘b’ has to evict value.
But they are having same path, so contention will occur on path.
while(1) {
Search for a cuckoo path;
lock();
Cuckoo move and insert;
if(success)
unlock();
break;
}
This algo will work to avoid
contention on path and one who
came first will be completing the
process and other will try after
some time.
Lock after discovering a cuckoo path
while(1) {
Search for a cuckoo path;
lock();
Cuckoo move and insert;
if(success)
unlock();
break;
}
// no locking required
Multiple Insert threads can look for cuckoo paths concurrently
←collision
Cuckoo move and insert;
Analysis : parallel cuckoo hashing
Serial Approach Parallel Approach
Lookup : Best case : O(n)
Worst Case : O(n2)
Best case : O(1),
Worst case : O(n)
Insert : Best Case : O(n),
Worst Case : O(n),
Best case : O(1)
Worst Case : O(n),
Removal : Best case : O(n),
Worst Case : O(n2)
Best case : O(1)
Worst case : O(n)
Cuckoo with 2 hash function performs well until 50% load.
Cuckoo with 3 hash function performs well until 90% load.
Lock-free Cuckoo Hashing
• The algorithm allows mutating operations to operate concurrently with
query ones and requires only single word compare-and-swap primitives.
• When an insertion triggers a sequence of key displacements, instead of
locking the whole cuckoo path, this algorithm breaks down the chain of
relocations into several single relocations which can be executed
independently and concurrently with other operations.
Lock-free Cuckoo Hashing
• Here, concurrent cuckoo hashing contains two hash tables (sub-tables),
which correspond to two independent hash functions.
• Each key can be stored at one of its two possible positions, one in each
sub-table called primary and secondary respectively.
Lock-free Cuckoo Hashing
• Problem :
• The original cuckoo approach inserts the new key to the primary sub-table
by evicting a collided key and re-inserting it to the other sub-table.
• This approach, however, causes the evicted key to be “nestless”, i.e. absent
from both sub-tables, until the re-insertion is completed.
• This might be an issue in concurrent environments: the “nestless” key is
unreachable by other concurrent operations which want to operate on it.
Lock-free Cuckoo Hashing
• Problem :
• Moving key problem :
• The key present in table[1] is relocated to table[0], meanwhile search reads
from table[0] and then table[1].
• To avoid such missing, search performs the second round query.
• Another issue with insertion operations is that a key can be inserted to two
sub-tables simultaneously.
• Since concurrent insertions can operate independently on two sub-tables, they can
both succeed. This results in two existing instances of one key, possibly mapped to
different values.
• To prevent such a case to happen, one can use a lock during insertion to lock both
slots so that only one instance of a key is successfully added to the table at a time.
Lock-free Cuckoo Hashing
• Searching :
• Searching for a key in our lock-free cuckoo hash table includes querying for
the existence of the key in two sub-tables.
• A key is available if it is found in one of them. A search operation starts
with the first query round by reading from the possible slots in the primary
sub-table and then in the secondary sub-table
• If the key is found in one of them, the value mapped to key is returned.
Search(x) : Case 1 : Value found in the Primary sub-table.
x
Primary sub-table Secondary sub-table
H1 = hash1(x)
h1
Search(x) : Case 2: Value found in the secondary sub-table.
Primary sub-table Secondary sub-table
x
H2= hash2(x)
h2
Lock-free Cuckoo Hashing
• Insert :
• Find :
• It examines both sub-tables to discover if two instances of the key exist in two
sub-tables. When the same key is found on both sub-tables, the one in the
secondary sub-table is deleted.
Find(x) :
Case 1 : If key already exist then update & return.
Primary sub-table Secondary sub-table
x
H1 = hash1(x)
Find(x) :
Case 2 : If the same key found on both then one from
secondary sub-table gets deleted.
Primary sub-table Secondary sub-table
x
H1 = hash1(x)
x
H2= hash2(x)
h1
h2
Find(x) :
Case 3 : returns current items which are stored at possible
slots where key should be hashed to.
Primary sub-table Secondary sub-table
y
H1 = hash1(x)
z
H2= hash2(x)
return y;
return z;
Lock-free Cuckoo Hashing
• Insert :
• Insert a new value using CAS( Compare-And-Swap) primitives.
• CAS is a synchronization primitive available in most modern processors. It
compares the content of a memory word to a given value and, only if they
are the same, modifies the content of that word to a given new value.
y
Insert (x) :
Case 1 : If one of the two slots is empty, the new entry is
inserted with a CAS.
Primary sub-table Secondary sub-table
H1 = hash1(x)
x
H2 = hash2(x)
x
h1
h2
r
e
c
a
b
n
Insert (x) :
Case 2 : If both the slots are occupied then relocation
process initiated using the cuckoo path.
Primary sub-table Secondary sub-table
H1 = hash1(x)
x
Cuckoo Path : s y k
s
y k
ys
k
k
y
s
f
X
Cuckoo hash : Problem while Cycle
Solution : After Threshold time, use another hash function or extend the size of
hash table.
S T
U
Z
Y V
Analysis : lock-free cuckoo
Serial Approach Parallel Approach
Lookup Best Case : O(n)
Worst Case : O(d*n)
Best Case : O(1)
Worst Case : O(d)
Insert Best Case : O(n),
Worst Case : > O(d*n),
Best case : O(1)
Worst case : > O(d),
Removal Best Case : O(n)
Worst Case : O(d*n)
Best Case : O(1)
Worst Case : O(d)
Where, d>2 is number of hash functions and sub table
Concurrent cuckoo hash table
- high memory efficiency
- fast concurrent writes and reads
References
1. Eric L. Goodman, David J. Hagliny, Chad Scherrer,Daniel Chavarr´ia-
Miranda, Jace Mogil, John Feo, “Hashing Strategies for the Cray XMT”
2. Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring
2012) Lectured by Margaret Reid-Miller — 26 April 2012.
3. Xiaozhou Li, David G. Andersen, Michael Kaminsky, Michael J. Freedman,
“Algorithmic Improvements for Fast Concurrent Cuckoo Hashing”,
“Princeton University, Carnegie Mellon University, Intel Labs.”
4. Nhan Nguyen, Philippas Tsigas,Chalmers University of Technology
Gothenburg, Sweden, “Lock-free Cuckoo Hashing”.

More Related Content

What's hot

The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationNorman Richards
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of AbstractionAlex Miller
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Flink Forward
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic SyntaxAdil Jafri
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepSylvain Hallé
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJason Swartz
 
java 8 Hands on Workshop
java 8 Hands on Workshopjava 8 Hands on Workshop
java 8 Hands on WorkshopJeanne Boyarsky
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & DeletionAfaq Mansoor Khan
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructuresmartha leon
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsBaruch Sadogursky
 

What's hot (20)

Into Clojure
Into ClojureInto Clojure
Into Clojure
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unification
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of Abstraction
 
37c
37c37c
37c
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Lec4
Lec4Lec4
Lec4
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic Syntax
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeep
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason Swartz
 
Python_ 3 CheatSheet
Python_ 3 CheatSheetPython_ 3 CheatSheet
Python_ 3 CheatSheet
 
java 8 Hands on Workshop
java 8 Hands on Workshopjava 8 Hands on Workshop
java 8 Hands on Workshop
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructures
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 

Viewers also liked

I Jornades Gastronòmiques d'Osona
I Jornades Gastronòmiques d'OsonaI Jornades Gastronòmiques d'Osona
I Jornades Gastronòmiques d'OsonaSerafi Parxet
 
Commendation Email from Dr. R. Kaminski
Commendation Email from Dr. R. KaminskiCommendation Email from Dr. R. Kaminski
Commendation Email from Dr. R. KaminskiMeranda Sizer
 
Impact simulation of ecowas rice self sufficiency policy
Impact simulation of ecowas rice self sufficiency policyImpact simulation of ecowas rice self sufficiency policy
Impact simulation of ecowas rice self sufficiency policyAnatole GOUNDAN
 
ESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravas
ESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravasESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravas
ESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravasESCODI
 
Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015
Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015
Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015Cursos Witcamp
 
Empresas de transportes en Canarias,
Empresas de transportes en Canarias,Empresas de transportes en Canarias,
Empresas de transportes en Canarias,paulaacd
 
Sociedad de la información y el conocimiento
Sociedad de la información y el conocimientoSociedad de la información y el conocimiento
Sociedad de la información y el conocimientoLucia Iglesias Cabal
 
Aloha's hawaiian dream giveaway hvcb partners
Aloha's hawaiian dream giveaway hvcb partnersAloha's hawaiian dream giveaway hvcb partners
Aloha's hawaiian dream giveaway hvcb partnersBill Kennedy
 
XING at User Experience Lisbon
XING at User Experience LisbonXING at User Experience Lisbon
XING at User Experience LisbonXING AG
 

Viewers also liked (20)

SOCIOMUNDO
SOCIOMUNDOSOCIOMUNDO
SOCIOMUNDO
 
I Jornades Gastronòmiques d'Osona
I Jornades Gastronòmiques d'OsonaI Jornades Gastronòmiques d'Osona
I Jornades Gastronòmiques d'Osona
 
Commendation Email from Dr. R. Kaminski
Commendation Email from Dr. R. KaminskiCommendation Email from Dr. R. Kaminski
Commendation Email from Dr. R. Kaminski
 
Impact simulation of ecowas rice self sufficiency policy
Impact simulation of ecowas rice self sufficiency policyImpact simulation of ecowas rice self sufficiency policy
Impact simulation of ecowas rice self sufficiency policy
 
ESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravas
ESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravasESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravas
ESCODI Breve perfl profesional de los ponentes de Tripulando en aguas bravas
 
Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015
Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015
Catálogo de la Plataforma Social Learn (PSL) en Fitur 2015
 
Wellbox
WellboxWellbox
Wellbox
 
Empresas de transportes en Canarias,
Empresas de transportes en Canarias,Empresas de transportes en Canarias,
Empresas de transportes en Canarias,
 
La violencia en colombia alexa
La violencia en colombia alexaLa violencia en colombia alexa
La violencia en colombia alexa
 
Modelo IDem.mas: Gestión en Igualdad
Modelo IDem.mas: Gestión en IgualdadModelo IDem.mas: Gestión en Igualdad
Modelo IDem.mas: Gestión en Igualdad
 
Un beso y una flor de Nino Bravo
Un beso y una flor de Nino BravoUn beso y una flor de Nino Bravo
Un beso y una flor de Nino Bravo
 
Como sacar partido a la publicidad On Line. Andrea Popa. Esfera Digital 21.
 Como sacar partido a la publicidad On Line. Andrea Popa. Esfera Digital 21. Como sacar partido a la publicidad On Line. Andrea Popa. Esfera Digital 21.
Como sacar partido a la publicidad On Line. Andrea Popa. Esfera Digital 21.
 
Sociedad de la información y el conocimiento
Sociedad de la información y el conocimientoSociedad de la información y el conocimiento
Sociedad de la información y el conocimiento
 
Servicios 3D
Servicios 3DServicios 3D
Servicios 3D
 
Mercedes salud
Mercedes saludMercedes salud
Mercedes salud
 
Kaefer Case Study
Kaefer Case StudyKaefer Case Study
Kaefer Case Study
 
Aloha's hawaiian dream giveaway hvcb partners
Aloha's hawaiian dream giveaway hvcb partnersAloha's hawaiian dream giveaway hvcb partners
Aloha's hawaiian dream giveaway hvcb partners
 
Que es AS2 y como se implementa
Que es AS2 y como se implementaQue es AS2 y como se implementa
Que es AS2 y como se implementa
 
CONSENT FORM WITH EMAIL
CONSENT FORM WITH EMAILCONSENT FORM WITH EMAIL
CONSENT FORM WITH EMAIL
 
XING at User Experience Lisbon
XING at User Experience LisbonXING at User Experience Lisbon
XING at User Experience Lisbon
 

Similar to Parallel Hashing Algorithms

Similar to Parallel Hashing Algorithms (20)

Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
 
Hash presentation
Hash presentationHash presentation
Hash presentation
 
HASHING.ppt.pptx
HASHING.ppt.pptxHASHING.ppt.pptx
HASHING.ppt.pptx
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
Hashing
HashingHashing
Hashing
 
Hash table
Hash tableHash table
Hash table
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hashing
HashingHashing
Hashing
 
ADS_Lec2_Linked_Allocation
ADS_Lec2_Linked_AllocationADS_Lec2_Linked_Allocation
ADS_Lec2_Linked_Allocation
 
session 15 hashing.pptx
session 15   hashing.pptxsession 15   hashing.pptx
session 15 hashing.pptx
 
Lec5
Lec5Lec5
Lec5
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of technic
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
Hash function
Hash functionHash function
Hash function
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
Hashing
HashingHashing
Hashing
 

Recently uploaded

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

Parallel Hashing Algorithms

  • 1. Parallel Hashing Algorithms Prepared By : Akash Panchal (14MCEC17) & Nisarg Patel (14MCEC20) @Nirma University, Ahmedabad
  • 2. Concurrent hash table •Indexing key-value objects • Lookup(key) • Insert(key, value) • Delete(key) •Fundamental building block for modern systems • System applications (e.g., kernel caches) • Concurrent user-level applications
  • 3. Goal: memory-efficient and high-throughput • Memory efficient (e.g., > 90% space utilized) • Fast concurrent reads (scale with # of cores/threads) • Fast concurrent writes (scale with # of cores/threads)
  • 4. separate chaining hash table K V K V K V K V K V Chaining items hashed in same bucket lookup K V
  • 5. separate chaining hash table - Acquiring a Linked List Node Location - Only one thread should insert new node. - find the end of the linked list, lock out other threads. - Make sure we are still at the end of the linked list. - Then allocate a new node from the unfilled region, and finally link it in.
  • 6. Good: simple Bad: poor cache locality Bad: pointers cost space separate chaining hash table
  • 7. open addressing hash table Probing alternate locations for vacancy e.g., linear/quadratic probing, double hashing - Inserting a Key : - 1) The bucket is empty. - Must acquire a location. - TwoStepAcquireAttempt algorithm is used. - Insert the key. - 2) The bucket is already filled. - Find next possible bucket using any probing method.
  • 8. Procedure: TwoStepAcquireAttempt Parameters: (location, key) // first check without locking 1: if location is empty then 2: lock(location) // then check with the lock 3: if location is still empty then 4: Reserve location for key 5: unlock(location) 6: return true 7: end if // Another thread modified the structure before we could acquire location 8: unlock(location) 9: end if 10: return false . // Caller needs to continue searching
  • 9. open addressing hash table Probing alternate locations for vacancy lookup Good: cache friendly Bad: poor memory efficiency - performance dramatically degrades when the usage grows beyond 70% capacity or so - e.g., Google dense_hash_map wastes 50% memory by default.
  • 10. Linear Hashing with linear Probing H1 H2 H3 H4 H5 H6 H7 H8 H9 h10 Parallel Insert : Case 1 : Two keys are inserted at different location. xH1 = insert( ) yH5 = insert( ) Pass : Pass 1
  • 11. Linear Hashing with linear Probing H1 H2 H3 H4 H5 H6 H7 H8 H9 h10 s u t Parallel Insert : Case 2 : Two keys are inserted at different location but collision occurs. xH1 = insert( ) yH5 = insert( ) Pass : Pass 1 Pass 2 Pass 3
  • 12. Linear Hashing with linear Probing H1 H2 H3 H4 H5 H6 H7 H8 H9 h10 xH1 = insert( ) yH1 = insert( ) Pass : Pass 1 Parallel Insert : Case 3 : Two keys tried to insert at same location and contention occurred. x y Pass 2
  • 13. Analysis : linear hashing Serial Approach Parallel Approach Lookup : Best case : O(n) Worst Case : O(n2) Best case : O(1), Worst case : O(n) Insert Best Case : O(n), Worst Case : O(n2) Best case : O(1) Worst Case : O(n) Removal : Best case : O(n), Worst Case : O(n2) Best case : O(1) Worst case : O(n)
  • 14. Cuckoo hashing • Use two hash tables and two hash functions • Each element will have exactly one “nest” (hash location) in each table • Guarantee that any element will only ever exist in one of its “nests”. • Lookup/delete are O(1) because we can check 2 locations (“nests”) in O(1) time.
  • 15. Cuckoo hashing Insertion : 1. Insert an element by finding one of its “nests” and putting it there • This may evict another element! 2. Insert the evicted element into its *other* “nest” This may evict another element!
  • 16. X Cuckoo hashing in Sequential: ‘X’ is inserted by moving ‘Y’ and ‘Z’
  • 17. Cuckoo hashing Asymmetric cuckoo hashing : • Choose one (the first) table to be larger than the other – Improves the probability that we get a hit on the first lookup – Only a minor slowdown on insert
  • 18. Cuckoo hashing Same Table cuckoo Hashing : • We didn’t actually need two separate tables. – It made the analysis much easier. – But… In practice, we just need two hash functions.
  • 19. Cuckoo hashing Each bucket has b slots for items (b-way set-associative) Each key is mapped to two random buckets • stored in one of them buckets 0 1 2 3 4 5 6 7 8 key x hash1(x) hash2(x)
  • 20. Predictable and fast lookup • Lookup: read 2 buckets in parallel • constant time in the worst case x 0 1 2 3 4 5 6 7 8 Lookup x
  • 21. 0 1 2 3 4 5 6 7 8 move keys to alternate buckets Insert may need “cuckoo move” • Insert: Both are full? Insert y a x b k r c s e n f x a bWrite to an empty slot in one of the possible locations x a b possible locations possible locations
  • 22. Insert may need “cuckoo move” • Insert: move keys to alternate buckets • find a “cuckoo path” to an empty slot • move hole backwards 0 1 2 3 4 5 6 7 8 Insert y x a b y b a x
  • 23. Case 1 : Inserting ‘a’ and ‘b’ in parallel, ‘b’ find its place in 1st hash function and ‘a’ has to evict value.
  • 24. k Case 2 : Inserting ‘a’ and ‘b’ in parallel, ‘a’ and ‘b’ has to evict value.
  • 25. Algorithmic optimizations • Lock after discovering a cuckoo path • minimize critical sections • But… • Decreases parallelization
  • 26. Previous approach: writer locks the table during the whole insert process lock(); Search for a cuckoo path; Cuckoo move and insert; unlock(); All Insert operations of other threads are blocked
  • 27. Case 3 : Inserting ‘a’ and ‘b’ in parallel, ‘a’ and ‘b’ has to evict value. But they are having same path, so contention will occur on path. while(1) { Search for a cuckoo path; lock(); Cuckoo move and insert; if(success) unlock(); break; } This algo will work to avoid contention on path and one who came first will be completing the process and other will try after some time.
  • 28. Lock after discovering a cuckoo path while(1) { Search for a cuckoo path; lock(); Cuckoo move and insert; if(success) unlock(); break; } // no locking required Multiple Insert threads can look for cuckoo paths concurrently ←collision Cuckoo move and insert;
  • 29. Analysis : parallel cuckoo hashing Serial Approach Parallel Approach Lookup : Best case : O(n) Worst Case : O(n2) Best case : O(1), Worst case : O(n) Insert : Best Case : O(n), Worst Case : O(n), Best case : O(1) Worst Case : O(n), Removal : Best case : O(n), Worst Case : O(n2) Best case : O(1) Worst case : O(n) Cuckoo with 2 hash function performs well until 50% load. Cuckoo with 3 hash function performs well until 90% load.
  • 30. Lock-free Cuckoo Hashing • The algorithm allows mutating operations to operate concurrently with query ones and requires only single word compare-and-swap primitives. • When an insertion triggers a sequence of key displacements, instead of locking the whole cuckoo path, this algorithm breaks down the chain of relocations into several single relocations which can be executed independently and concurrently with other operations.
  • 31. Lock-free Cuckoo Hashing • Here, concurrent cuckoo hashing contains two hash tables (sub-tables), which correspond to two independent hash functions. • Each key can be stored at one of its two possible positions, one in each sub-table called primary and secondary respectively.
  • 32. Lock-free Cuckoo Hashing • Problem : • The original cuckoo approach inserts the new key to the primary sub-table by evicting a collided key and re-inserting it to the other sub-table. • This approach, however, causes the evicted key to be “nestless”, i.e. absent from both sub-tables, until the re-insertion is completed. • This might be an issue in concurrent environments: the “nestless” key is unreachable by other concurrent operations which want to operate on it.
  • 33. Lock-free Cuckoo Hashing • Problem : • Moving key problem : • The key present in table[1] is relocated to table[0], meanwhile search reads from table[0] and then table[1]. • To avoid such missing, search performs the second round query. • Another issue with insertion operations is that a key can be inserted to two sub-tables simultaneously. • Since concurrent insertions can operate independently on two sub-tables, they can both succeed. This results in two existing instances of one key, possibly mapped to different values. • To prevent such a case to happen, one can use a lock during insertion to lock both slots so that only one instance of a key is successfully added to the table at a time.
  • 34. Lock-free Cuckoo Hashing • Searching : • Searching for a key in our lock-free cuckoo hash table includes querying for the existence of the key in two sub-tables. • A key is available if it is found in one of them. A search operation starts with the first query round by reading from the possible slots in the primary sub-table and then in the secondary sub-table • If the key is found in one of them, the value mapped to key is returned.
  • 35. Search(x) : Case 1 : Value found in the Primary sub-table. x Primary sub-table Secondary sub-table H1 = hash1(x) h1
  • 36. Search(x) : Case 2: Value found in the secondary sub-table. Primary sub-table Secondary sub-table x H2= hash2(x) h2
  • 37. Lock-free Cuckoo Hashing • Insert : • Find : • It examines both sub-tables to discover if two instances of the key exist in two sub-tables. When the same key is found on both sub-tables, the one in the secondary sub-table is deleted.
  • 38. Find(x) : Case 1 : If key already exist then update & return. Primary sub-table Secondary sub-table x H1 = hash1(x)
  • 39. Find(x) : Case 2 : If the same key found on both then one from secondary sub-table gets deleted. Primary sub-table Secondary sub-table x H1 = hash1(x) x H2= hash2(x) h1 h2
  • 40. Find(x) : Case 3 : returns current items which are stored at possible slots where key should be hashed to. Primary sub-table Secondary sub-table y H1 = hash1(x) z H2= hash2(x) return y; return z;
  • 41. Lock-free Cuckoo Hashing • Insert : • Insert a new value using CAS( Compare-And-Swap) primitives. • CAS is a synchronization primitive available in most modern processors. It compares the content of a memory word to a given value and, only if they are the same, modifies the content of that word to a given new value.
  • 42. y Insert (x) : Case 1 : If one of the two slots is empty, the new entry is inserted with a CAS. Primary sub-table Secondary sub-table H1 = hash1(x) x H2 = hash2(x) x h1 h2
  • 43. r e c a b n Insert (x) : Case 2 : If both the slots are occupied then relocation process initiated using the cuckoo path. Primary sub-table Secondary sub-table H1 = hash1(x) x Cuckoo Path : s y k s y k ys k k y s f
  • 44. X Cuckoo hash : Problem while Cycle Solution : After Threshold time, use another hash function or extend the size of hash table. S T U Z Y V
  • 45. Analysis : lock-free cuckoo Serial Approach Parallel Approach Lookup Best Case : O(n) Worst Case : O(d*n) Best Case : O(1) Worst Case : O(d) Insert Best Case : O(n), Worst Case : > O(d*n), Best case : O(1) Worst case : > O(d), Removal Best Case : O(n) Worst Case : O(d*n) Best Case : O(1) Worst Case : O(d) Where, d>2 is number of hash functions and sub table Concurrent cuckoo hash table - high memory efficiency - fast concurrent writes and reads
  • 46. References 1. Eric L. Goodman, David J. Hagliny, Chad Scherrer,Daniel Chavarr´ia- Miranda, Jace Mogil, John Feo, “Hashing Strategies for the Cray XMT” 2. Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2012) Lectured by Margaret Reid-Miller — 26 April 2012. 3. Xiaozhou Li, David G. Andersen, Michael Kaminsky, Michael J. Freedman, “Algorithmic Improvements for Fast Concurrent Cuckoo Hashing”, “Princeton University, Carnegie Mellon University, Intel Labs.” 4. Nhan Nguyen, Philippas Tsigas,Chalmers University of Technology Gothenburg, Sweden, “Lock-free Cuckoo Hashing”.

Editor's Notes

  1. Search operation
  2. Search operation
  3. Search operation
  4. Search operation
  5. Search operation
  6. Search operation
  7. Search operation