SkipLists and Balanced Search The Art Of MultiProcessor Programming Maurice Herlihy & Nir Shavit Chapter 14 Avi Kozokin.

Slides:



Advertisements
Similar presentations
CS16: Introduction to Data Structures & Algorithms
Advertisements

David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing.
CMSC420: Skip Lists Kinga Dobolyi Based off notes by Dave Mount.
CS 225 Lab #11 – Skip Lists.
Fast and Lock-Free Concurrent Priority Queues for Multi-Thread Systems Håkan Sundell Philippas Tsigas.
The Dictionary ADT: Skip List Implementation
Multicore Programming Skip list Tutorial 10 CS Spring 2010.
Alon Efrat Computer Science Department University of Arizona SkipList.
CSC 172 DATA STRUCTURES. SKIP LISTS Read Weiss
Chapter 4: Trees Part II - AVL Tree
Scalable and Lock-Free Concurrent Dictionaries
Skip List & Hashing CSE, POSTECH.
Data Structures: A Pseudocode Approach with C
Linked Lists: Lazy and Non-Blocking Synchronization Based on the companion slides for The Art of Multiprocessor Programming (Maurice Herlihy & Nir Shavit)
Search Trees: BSTs and B-Trees David Kauchak cs302 Spring 2013.
Locality-Conscious Lock-Free Linked Lists Anastasia Braginsky & Erez Petrank 1.
Data Structures Hash Tables
CMPT 225 Priority Queues and Heaps. Priority Queues Items in a priority queue have a priority The priority is usually numerical value Could be lowest.
TDDB56 DALGOPT-D TDDB57 DALG-C Lecture 6 Jan Maluszynski - HT TDDB56 TDDB57 Lecture 6 Search Trees: AVL-Trees, Multi-way Search Trees, B-Trees.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Lecture 6: Linked Lists Linked lists Insert Delete Lookup Doubly-linked lists.
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Fundamentals of Python: From First Programs Through Data Structures
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Programming Logic and Design Fourth Edition, Comprehensive
1 HEAPS & PRIORITY QUEUES Array and Tree implementations.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
More on Linked List Algorithms. Linked List and Template Remember the implementation of a double linked list we learned before. Some of methods are shown.
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
P p Chapter 10 has several programming projects, including a project that uses heaps. p p This presentation shows you what a heap is, and demonstrates.
Eric Chang and Rutwik Parikh. Goal: Determine the largest subset of edges in a graph such that no vertex of the graph is touched by more than one edge.
B-Trees. CSM B-Trees 2 Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so.
CS 361 – Chapter 3 Sorted dictionary ADT Implementation –Sorted array –Binary search tree.
1 Searching Searching in a sorted linked list takes linear time in the worst and average case. Searching in a sorted array takes logarithmic time in the.
1 Lock-Free concurrent algorithm for Linked lists: Verification CSE-COSC6490A : Concurrent Object-Oriented Languages York University - W09 Speaker: Alexandre.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
1 Heaps and Priority Queues v2 Starring: Min Heap Co-Starring: Max Heap.
Skip Lists 二○一七年四月二十五日
Advanced Locking Techniques
Skiplist-based Concurrent Priority Queues Itay Lotan Stanford University Nir Shavit Sun Microsystems Laboratories.
A Simple Optimistic skip-list Algorithm Maurice Herlihy Brown University & Sun Microsystems Laboratories Yossi Lev Brown University & Sun Microsystems.
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
Data StructuresData Structures Priority Queue. Recall Queues FIFO:First-In, First-Out Some contexts where this seems right? Some contexts where some things.
Copyright © 0 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
Tree Data Structures. Heaps for searching Search in a heap? Search in a heap? Would have to look at root Would have to look at root If search item smaller.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
Priority Queues Dan Dvorin Based on ‘The Art of Multiprocessor Programming’, by Herlihy & Shavit, chapter 15.
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Chapter 3 The easy stuff. Lists If you only need to store a few things, the simplest and easiest approach might be to put them in a list Only if you need.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Counting and Distributed Coordination BASED ON CHAPTER 12 IN «THE ART OF MULTIPROCESSOR PROGRAMMING» LECTURE BY: SAMUEL AMAR.
2/19/2016 3:18 PMSkip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
1 Chapter 4 Unordered List. 2 Learning Objectives ● Describe the properties of an unordered list. ● Study sequential search and analyze its worst- case.
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Skip Lists. Linked Lists Fast modifications given a pointer Slow traversals to random point.
Lecture 9 : Concurrent Data Structures Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Problems with Linked List (as we’ve seen so far…)
Concurrent Data Structures Concurrent Algorithms 2017
Heaps Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates.
Binary Search Trees.
Data Structures and Analysis (COMP 410)
A Concurrent Lock-Free Priority Queue for Multi-Thread Systems
Multicore programming
Mark Redekopp David Kempe
B-Trees.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

SkipLists and Balanced Search The Art Of MultiProcessor Programming Maurice Herlihy & Nir Shavit Chapter 14 Avi Kozokin

Intro Introduction: SkipList – what, why & how. a reminder LazySkipList – a lock based concurrent SkipList LockFreeSkipList – lock free concurrent SkipList

SkipList – what Collection of unique keys Comprised of levels – each level is a sorted linked list. Level - O contains all nodes, and each level is a subset of the lower levels. Mimics a balanced search tree. Height is logarithmic. Each link at level i skips roughly nodes. Probabilistic data structure. We assume that contains() is called more than the rest of the methods

SkipList – what Collection of unique keys Comprised of levels – each level is a sorted linked list. Level - O contains all nodes, and each level is a subset of the lower levels. Mimics a balanced search tree. Height is logarithmic. Each link at level i skips roughly nodes. Probabilistic data structure. We assume that contains() is called more than the rest of the methods

SkipList – why Balanced search trees, (such as AVL trees) provide logarithmic performance of search, add & remove methods. The problem is the maintenance – need to rebalance the data structure after each change (rolling in AVL). SkipList provides a solution: uses randomization to achieve logarithmic performance in average. Randomization happens on insertion of an element We choose: 0<p<1 to be the probability for a node to appear in level i given that it appears in level i-1. all nodes appear in level 0. this means the probability of a node to appear in level i is. Note that if it appears in level i – it appears in all lower levels.

SkipList – how Every Node has a topLevel – index of the highest list in which it is present. Every Node has an array of references to nodes – next node on each level. SkipList has head and tail nodes, with keys smaller and bigger than any possible key, respectively. head and tail appear on every level, and initially head’s next points to tail. SkipList has a maximal level. (can be dynamically maintained). Finding nodes by traversing every list starting from the top, and descending whenever we find the largest key in the level which is not bigger than the searched node’s key.

Find() Traverses the list Fills 2 arrays: preds[] and sucss[] pred[i] is a reference to the node in level i that has the biggest key that is smaller than the searched key. succ[i] is pred[i]’s successor Returns the node’s top level if found If not found – returns -1

Find() Traverses the list Fills 2 arrays: preds[] and sucss[] pred[i] is a reference to the node in level i that has the biggest key that is smaller than the searched key. succ[i] is pred[i]’s successor

Add() Uses find() to fill the preds[] and succs[]. Generates a random topLevel. If find() returned a top level – returns false (the key is already in the list) If not found - inserts the node between preds[i] and succs[i] in every level from 0 to topLevel

Add() - example Uses find() to fill the preds[] and succs[]. Generates a random topLevel. If find() returned a top level – returns false (the key is already in the list) If not found - inserts the node between preds[i] and succs[i] in every level from 0 to topLevel

LazySkipList

A lock based concurrent SkipList Each level of the SkipList is a LazyList Add() & remove() use optimistic fine grained locking Contains() is wait-free

LazyList – a reminder Every node has a marker – if set, that means that the node was logically removed from the set. Add() & remove() methods traverse the list without locking, searching for the node’s predecessor and successor (the node itself incase of remove) After finding the predecessor and successor, locking them Validating – both pred and curr aren’t marked, and preds next is in fact curr. If validation succeeds – continue with method. If validation failed – go again.

LazySkipList Maintains the SkipList property – each level is a subset of it’s lower levels Using locks near the modified node to achieve this property. Every node has an additional indicator if the node is fullyLinked – meaning that the node is linked in every level it should be linked (up to it’s top level) We delay access to a node until it is fullyLinked

LazySkipList

Add() Calls find() to fill preds[] and succs[] (find is the same as sequential find) Locks preds[] Checks if the node is already in the set (spins if not fully linked) and returns false if so. Validates preds[]. If validation fails – tries again. Makes preds[] point to our node and the node to point to the sucss[] Sets fullyLinked

example

Find() Keeps pred’s key strictly smaller than searched key

Find()

If the node is found And unmarked we wait until it’s Fully linked and then finish

Remove() Uses find as well Locks the node, and checks if it is unmarked, and if the node is fully linked and at it’s top level (if not – not yet fully linked or marked and is being removed) Locks preds[] and validates. If fails – tries again. Removes from top to bottom to maintain the SkipList property

Contains() Wait free Uses find() Validates result

Lock-Free Concurrent SkipList

Also based on a concurrent list implementation – LockFreeList Each level of the SkipList is a LockFreeList No locks in this implementation Only CAS operations We will achieve a wait free contains() here as well

LockFreeList Every node’s next reference is an AtomicMarkableReference CompareAndSet(expected_val,new_val,expected_mark,new_mark) Get(mark_holder[] )– returns the reference and puts mark in mark_holder attemptMark(val,mark) – if references value == val then mark. Essentially, using CASes to mark and remove: one CAS to check if the node still points to it’s successor and a second CAS to physically remove it. Find() cleans up marked nodes

LockFreeSkipList - Overview We cannot maintain the SkipList property this time. The set is defined by the bottom level – if a node is there and unmarked it’s in the set (no need for fullyLinked flag) Adding by using CAS to insert a node at each level. Removing by marking the node’s next reference. Find() fills preds[] cleans up marked nodes while traversing.

Find(x) & contains(x) Traverses the lists, from top level to bottom. Never traverses marked nodes. filling preds[] with references to nodes with largest key that’s strictly smaller than x, while using CAS to eliminate marked nodes. Contains() does the same except it doesn’t eliminate marked nodes but simply skips over them.

Add() Uses find() to check presence and to fill preds[] and sucss[] Directs new node’s nexts to sucssessors Tried to add to bottom level using CAS. If it fails – calls find again. Adds to higher levels

Add()

Remove() Also uses find(), searching for an unmarked node in the bottom level marks the node, starting from it’s top level If all marks were successful up to the bottom level, marks the bottom level Physically removed by remove itself or find() of other threads

Summary We recalled what is a SkipList Seems weird, but provides an elegant alternative to a search tree Seen 2 different concurrent SkipLists One uses locks The other doesn’t Both achieve logarithmic performance and a wait free contains() method

Thanks!