Concurrent Hashing and Natural Parallelism Chapter 13 in The Art of Multiprocessor Programming Instructor: Erez Petrank Presented by Tomer Hermelin.

Slides:



Advertisements
Similar presentations
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Advertisements

Hash Tables and Sets Lecture 3. Sets A set is simply a collection of elements Unlike lists, elements are not ordered Very abstract, general concept with.
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
Monitors & Blocking Synchronization 1. Producers & Consumers Problem Two threads that communicate through a shared FIFO queue. These two threads can’t.
Data Structures Using C++ 2E
Concurrency 101 Shared state. Part 1: General Concepts 2.
Hashing21 Hashing II: The leftovers. hashing22 Hash functions Choice of hash function can be important factor in reducing the likelihood of collisions.
Data Structures Hash Tables
Lock-free Cuckoo Hashing Nhan Nguyen & Philippas Tsigas ICDCS 2014 Distributed Computing and Systems Chalmers University of Technology Gothenburg, Sweden.
Maps, Dictionaries, Hashtables
hashing1 Hashing It’s not just for breakfast anymore!
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
CS 261 – Data Structures Hash Tables Part II: Using Buckets.
FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.
Chapter 13.4 Hash Tables Steve Ikeoka ID: 113 CS 257 – Spring 2008.
1 Hash-Based Indexes Chapter Introduction : Hash-based Indexes  Best for equality selections.  Cannot support range searches.  Static and dynamic.
Art of Multiprocessor Programming1 Concurrent Hashing Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Lecture 11 oct 7 Goals: hashing hash functions chaining closed hashing application of hashing.
Hashing General idea: Get a large array
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Programming Logic and Design Fourth Edition, Comprehensive
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
TECH Computer Science Dynamic Sets and Searching Analysis Technique  Amortized Analysis // average cost of each operation in the worst case Dynamic Sets.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Hashing as a Dictionary Implementation Chapter 19.
CSC 427: Data Structures and Algorithm Analysis
Chapter 12 Hash Table. ● So far, the best worst-case time for searching is O(log n). ● Hash tables  average search time of O(1).  worst case search.
WEEK 1 Hashing CE222 Dr. Senem Kumova Metin
Chapter 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
CS162 Week 5 Kyle Dewey. Overview Announcements Reactive Imperative Programming Parallelism Software transactional memory.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11 Modified by Donghui Zhang Jan 30, 2006.
Hashing and Natural Parallism Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Indexed Sequential Access Method.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
A Introduction to Computing II Lecture 11: Hashtables Fall Session 2000.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
CPSC 252 Hashing Page 1 Hashing We have already seen that we can search for a key item in an array using either linear or binary search. It would be better.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Hashing. Search Given: Distinct keys k 1, k 2, …, k n and collection T of n records of the form (k 1, I 1 ), (k 2, I 2 ), …, (k n, I n ) where I j is.
An algorithm of Lock-free extensible hash table Yi Feng.
CS 261 – Data Structures Hash Tables Part II: Using Buckets.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
Chapter 5 Record Storage and Primary File Organizations
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Lecture 9 : Concurrent Data Structures Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Database Management 7. course. Reminder Disk and RAM RAID Levels Disk space management Buffering Heap files Page formats Record formats.
Slides by Steve Armstrong LeTourneau University Longview, TX
Hashing CENG 351.
Hashing and Natural Parallism
Hash tables Hash table: a list of some fixed size, that positions elements according to an algorithm called a hash function … hash function h(element)
Concurrent Hashing and Natural Parallelism
Tim Ehrlich Growing Arrays in C.
Java Concurrency 17-Jan-19.
Database Design and Programming
Java Concurrency.
Java Concurrency.
Java Concurrency 29-May-19.
Presentation transcript:

Concurrent Hashing and Natural Parallelism Chapter 13 in The Art of Multiprocessor Programming Instructor: Erez Petrank Presented by Tomer Hermelin

Hash-table Recap Int hash_function(T item) Void add(T item) Void remove(T item) Bool contains(T item) resize and resize policy. Closed address vs open address

Agenda ● Closed address:  3 gradually improvements  Lock free model ● Open address  2 gradually improvements

Some notations: ● N – Current capacity ● k – Hash-code of the given item ● IC – Initial capacity (constructor argument)

Concurrent Closed address

Base class - abstract ● Constructor(int capacity): init –  int setSize  array of lists in size capacity ● Contains(T x):  acquire (x)  Checks for x  release (x) ● Add/remove(T x):  acquires (x)  Adds and inc size if not already in list  release (x)  Check policy and resize if needed

Name of the game: ● acquire(T x): acquires the locks necessary to manipulate item x. ● release(T x) releases the relevant locks. ● policy() decides whether to resize the set. ● resize() doubles the capacity of the table.

Coarse-Grained Hash Set

Coarse-Grained The naïve solution: Add one main lock, to lock for each method. The only thing to do: When resize, after locking, make sure no one has already resized. Why shouldn’t we do that for add, remove and contains? Easy to understand and implement. But every thread stops all the other threads…

Striped Hash set

acquire: given item with hash-code k, we’ll lock the lock in index k (mod IC) Lets say we create a Hash Table with capacity 8, and it was double in size once. Then: Can modify Buckets 0 and 5 in parallel Can’t modify Buckets 0 with two threads in parallel Can’t modify Buckets 0 and 8 in parallel 

Locks Table Resizing Save table size Validate table size

No Deadlock contains, add, or remove cannot deadlock (also with resize), because they require only one lock to operate. A resize call cannot deadlock with another resize call because both calls start without holding any locks, and acquire the locks in the same order

Draw back After multiple resizing there would be large groups of cells that cannot be modified in parallel.

Reasons not to grow the locks array? 1. Associating a lock with every table entry could consume too much space, especially when tables are large and contention is low. 2. While resizing the table is straightforward, resizing the lock array (while in use) is more complex.

Striped Hash set - summary ● Striped locking permits some concurrency. ● add(), contains(), and remove() methods take constant expected time. ● After multiple resizing, not ideal locks-buckets ratio.

Refinable Hash set

Propose: Refine the resolution of locking when resizing The main step – Making sure the lock array is not in use, while resizing.

Atomic Markable Reference Add AtomicMarkableReference owner We use the owner as a mutual exclusion flag between the resize() call and all other calls (including other resizes)

acquire() Locks Table Owner + Validate

Resize() Locks Table Owner R R + - C R’ Locks Table

Resize() Locks Table Owner R R1R1 R

Striped Hash set - summary ● Control over the locks array and table size ratio. ● Resize is ‘stop the world’ method.

Lock free Models We want to not “stop-the world” in order to resize, while still doing contains, add, and remove in constant time Atomic operations work only on a single memory location. Resizing is really really not the case. We’ll take care of resizing incrementally, during add, remove and contains.

Recursive Split-Ordering

A list structure ● All the bucket are part of one long list. ● Add(), remove() and contains() through pointers in table. ● To make our life easy, we make special nodes. ● Initialize when first accessed.

The order of the items We want items not to move in resizing! Every item is inserted according to the reverse order of its hash-code bit representation.

The order of the items 0010 Size of the table = 2^n n= n=

Triggered only by a small action – change bucketSize. The table is in fixed size, and each cell points to the correct ‘logical bucket’ in the list (a pointer is initialized when first accessed). Resize()

Adding Example

Resizing Example When the capacity is 2, to add item with hash-code = 3, we would be directed by the table with index no. 1. after changing the capacity from 2 to 4, we’ll access for the same item with index no. 3

So how do we implement? The list is almost the same as LockFreeList: ● The items are sorted in recursive-split order ● While the LockFreeList class uses only two sentinels, we place a sentinel at the start of each new bucket.

So how do we implement? 0 Table AtomicInteger bucketSize AtomicInteger setSize

An item inserted before the table was resized must be accessible afterwards from both its previous and current buckets. With our ordering, we ensure that these two groups of items are positioned one after the other in the list. This organization keeps each item in the second group accessible from bucket b. Correctness while Resizing

Open-Addressed Hash Set

Cuckoo Hashing Some Cuckoos are nest parasites: they lay their eggs in other birds’ nests. Cuckoo chicks hatch early, and quickly push the other eggs out of the nest.

Sequential Cuckoo ● Two tables, each with own hash function. ● Remove and contains: simply check in both tables. ● Add method is done by ‘kicking out’ the item in the way and letting him find a new cell. If no free cell can be found, we resize.

● add() ● remove() ● contains() ● relocate() The main problem in making the sequential Cuckoo concurrent is the add method Concurrent Base Class - abstract

probe sets: a constant-sized set of items with the same hash code. we use a two-dimensional table of probe sets X 2

Concurrent Cuckoo Hashing remove() and contains(): k Table 1 Table 0 check

Add() Table 0 Table 1 threshold k k k k k Resize!! Relocate!! acquire(k)

relocation Table 0 Table 1 threshold n k s acquire(s) a c b r acquire(a) And we start all over again!

Name of the game: ● acquire(T x): acquires the locks necessary to manipulate item x. ● release(T x) releases the relevant locks. ● resize() doubles the capacity of the table. ● policy() decides whether to resize the set.

Striped Concurrent Cuckoo Hashing

Striped Concurrent Cuckoo Adding a fixed 2-by-L array of reentrant locks As before, lock[i][j] protects table[i][k], where k (mod L) = j Table 1 Table 0 Locks 0 Locks 1

Still no deadlock The acquire() method locks lock[0][h0(x)] and only then lock[1][h1(x)], to avoid deadlock. When resizing we only acquire the locks in lock[0].

Refinable Concurrent Cuckoo Hashing

Refinable Concurrent Cuckoo Owner Table 1 Table 0 Locks 0 Locks 1

The end Questions?