Hashing and Natural Parallism. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Size: px
Start display at page:

Download "Hashing and Natural Parallism. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit"

Transcription

1 Hashing and Natural Parallism Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

2 Sequential Closed Hash Map buckets 2 Items h(k) = k mod 4 Art of Multiprocessor Programming 2

3 Add an Item Items h(k) = k mod 4 Art of Multiprocessor Programming 3

4 Add Another: Collision Items h(k) = k mod 4 Art of Multiprocessor Programming 4

5 More Collisions Items h(k) = k mod 4 Art of Multiprocessor Programming 5

6 More Collisions Problem: buckets becoming too long 5 Items h(k) = k mod 4 Art of Multiprocessor Programming 6

7 Resizing Items h(k) = k mod 4 7 Grow the array Art of Multiprocessor Programming 7

8 Resizing Adjust hash function 5 Items h(k) = k mod 8 7 Art of Multiprocessor Programming 8

9 Resizing h(4) = 4 mod h(k) = k mod 8 7 Art of Multiprocessor Programming 9

10 Resizing h(4) = 4 mod 8 h(k) = k mod 8 Art of Multiprocessor Programming 10

11 Resizing h(7) = h(15) = 7 mod h(k) = k mod 8 7 Art of Multiprocessor Programming 11

12 Resizing h(15) = 7 mod 8 h(k) = k mod 8 Art of Multiprocessor Programming 12

13 Fields public class SimpleHashSet { protected LockFreeList[] table; public SimpleHashSet(int capacity) { table = new LockFreeList[capacity]; for (int i = 0; i < capacity; i++) table[i] = new LockFreeList(); } Array of lock-free lists Art of Multiprocessor Programming 13

14 Constructor public class SimpleHashSet { protected LockFreeList[] table; public SimpleHashSet(int capacity) { table = new LockFreeList[capacity]; for (int i = 0; i < capacity; i++) table[i] = new LockFreeList(); } Initial size Art of Multiprocessor Programming 14

15 Constructor public class SimpleHashSet { protected LockFreeList[] table; public SimpleHashSet(int capacity) { table = new LockFreeList[capacity]; for (int i = 0; i < capacity; i++) table[i] = new LockFreeList(); } Allocate memory Art of Multiprocessor Programming 15

16 Constructor public class SimpleHashSet { protected LockFreeList[] table; public SimpleHashSet(int capacity) { table = new LockFreeList[capacity]; for (int i = 0; i < capacity; i++) table[i] = new LockFreeList(); } Initialization Art of Multiprocessor Programming 16

17 Add Method public boolean add(object key) { int hash = key.hashcode() % table.length; return table[hash].add(key); } Art of Multiprocessor Programming 17

18 Add Method public boolean add(object key) { int hash = key.hashcode() % table.length; return table[hash].add(key); } Use object hash code to pick a bucket Art of Multiprocessor Programming 18

19 Add Method public boolean add(object key) { int hash = key.hashcode() % table.length; return table[hash].add(key); } Call bucket s add() method Art of Multiprocessor Programming 19

20 No Brainer? We just saw a Simple Lock-free Concurrent hash-based set implementation What s not to like? Art of Multiprocessor Programming 20

21 No Brainer? We just saw a Simple Lock-free Concurrent hash-based set implementation What s not to like? We don t know how to resize Art of Multiprocessor Programming 21

22 Is Resizing Necessary? Constant-time method calls require Constant-length buckets Table size proportional to set size As set grows, must be able to resize Art of Multiprocessor Programming 22

23 Set Method Mix Typical load 90% contains() 9% add () 1% remove() Growing is important Shrinking not so much Art of Multiprocessor Programming 23

24 When to Resize? Many reasonable policies. Here s one. Pick a threshold on num of items in a bucket Global threshold When ¼ buckets exceed this value Bucket threshold When any bucket exceeds this value Art of Multiprocessor Programming 24

25 Coarse-Grained Locking Good parts Simple Hard to mess up Bad parts Sequential bottleneck Art of Multiprocessor Programming 25

26 Fine-grained Locking root Each lock associated with one bucket Art of Multiprocessor Programming 26

27 Make sure Resize root reference This didn t change between resize decision and lock acquisition root Acquire locks in ascending order Art of Multiprocessor Programming 27

28 Resize This root Allocate new super-sized table 7 Art of Multiprocessor Programming 28

29 Resize This root Art of Multiprocessor Programming 29

30 Striped Locks: each lock now associated with two buckets Resize This root Art of Multiprocessor Programming 31

31 Observations We grow the table, but not locks Resizing lock array is tricky We use sequential lists Not LockFreeList lists If we re locking anyway, why pay? Art of Multiprocessor Programming 32

32 Fine-Grained Hash Set public class FGHashSet { protected RangeLock[] lock; protected List[] table; public FGHashSet(int capacity) { table = new List[capacity]; lock = new RangeLock[capacity]; for (int i = 0; i < capacity; i++) { lock[i] = new RangeLock(); table[i] = new LinkedList(); }} Art of Multiprocessor Programming 33

33 Fine-Grained Hash Set public class FGHashSet { protected RangeLock[] lock; protected List[] table; public FGHashSet(int capacity) { table = new List[capacity]; lock = new RangeLock[capacity]; for (int i = 0; i < capacity; i++) { lock[i] = new RangeLock(); table[i] = new LinkedList(); }} Array of locks Art of Multiprocessor Programming 34

34 Fine-Grained Hash Set public class FGHashSet { protected RangeLock[] lock; protected List[] table; public FGHashSet(int capacity) { table = new List[capacity]; lock = new RangeLock[capacity]; for (int i = 0; i < capacity; i++) { lock[i] = new RangeLock(); table[i] = new LinkedList(); }} Array of buckets Art of Multiprocessor Programming 35

35 Fine-Grained Hash Set Initially same number of public class FGHashSet { protected RangeLock[] lock; protected List[] locks table; and buckets public FGHashSet(int capacity) { table = new List[capacity]; lock = new RangeLock[capacity]; for (int i = 0; i < capacity; i++) { lock[i] = new RangeLock(); table[i] = new LinkedList(); }} Art of Multiprocessor Programming 36

36 The add() method public boolean add(object key) { int keyhash = key.hashcode() % lock.length; synchronized (lock[keyhash]) { int tabhash = key.hashcode() % table.length; return table[tabhash].add(key); } } Art of Multiprocessor Programming 37

37 Fine-Grained Locking public boolean add(object key) { int keyhash = key.hashcode() % lock.length; synchronized (lock[keyhash]) { int tabhash = key.hashcode() % table.length; return table[tabhash].add(key); } } Which lock? Art of Multiprocessor Programming 38

38 The add() method public boolean add(object key) { int keyhash = key.hashcode() % lock.length; synchronized (lock[keyhash]) { int tabhash = key.hashcode() % table.length; return table[tabhash].add(key); } } Acquire the lock Art of Multiprocessor Programming 39

39 Fine-Grained Locking public boolean add(object key) { int keyhash = key.hashcode() % lock.length; synchronized (lock[keyhash]) { int tabhash = key.hashcode() % table.length; return table[tabhash].add(key); } } Which bucket? Art of Multiprocessor Programming 40

40 The add() method public boolean add(object key) { int keyhash = key.hashcode() % lock.length; synchronized (lock[keyhash]) { int tabhash = key.hashcode() % table.length; return table[tabhash].add(key); } } Call that bucket s add() method Art of Multiprocessor Programming 41

41 Another Locking Structure add, remove, contains Lock table in shared mode resize Locks table in exclusive mode Art of Multiprocessor Programming 48

42 Read-Write Locks public interface ReadWriteLock { Lock readlock(); Lock writelock(); } Art of Multiprocessor Programming 49

43 Read/Write Locks Returns associated read lock public interface ReadWriteLock { Lock readlock(); Lock writelock(); } Art of Multiprocessor Programming 50

44 Read/Write Locks Returns associated read lock public interface ReadWriteLock { Lock readlock(); Lock writelock(); } Returns associated write lock Art of Multiprocessor Programming 51

45 Lock Safety Properties Read lock: Locks out writers Allows concurrent readers Write lock Locks out writers Locks out readers Art of Multiprocessor Programming 52

46 Lets Try to Design a Read- Write Lock Read lock: Locks out writers Allows concurrent readers Write lock Locks out writers Locks out readers Art of Multiprocessor Programming 53

47 Read/Write Lock Safety If readers > 0 then writer == false If writer == true then readers == 0 Liveness? Will a continual stream of readers Lock out writers? Art of Multiprocessor Programming 54

48 FIFO R/W Lock As soon as a writer requests a lock No more readers accepted Current readers drain from lock Writer gets in Art of Multiprocessor Programming 55

49 ByteLock Readers-Writers lock Cache-aware Fast path for slotted readers Slower path for others 56

50 ByteLock Lock Record Byte for each slotted reader W R Writer id Single cache line Count of unslotted readers 57

51 Writer Writer i W=0 W R=3 CAS 58

52 Writer Writer i W=i R=3 Wait for readers to drain out 59

53 Writer Writer i W=i R=0 proceed 60

54 Writer Writer i null R=0 release 61

55 Slotted Reader Fast Path Slotted Reader W= R=3 62

56 Slotted Reader Fast Path Slotted Reader W= R=3 63

57 Slotted Reader Fast Path Slotted Reader W= R=3 64

58 Slotted Reader Fast Path Slotted Reader W= R=3 65

59 Slotted Reader Slow Path Slotted Reader W=i R=3 66

60 Slotted Reader Slow Path Slotted Reader W=i R=3 67

61 Slotted Reader Slow Path Slotted Reader W= R=3 68

62 Slotted Reader Slow Path Slotted Reader W=i R=3 69

63 Unslotted Reader UnslottedReader W=i R=4 1R=3 CAS 70

64 Slotted Reader Slow Path Slotted Reader W=i R=3 71

65 Unslotted Reader UnslottedReader W=i R=3 1R=3 CAS 72

66 Slotted Reader Slow Path Slotted Reader W=i R=3 73

67 The Story So Far Resizing is the hard part Fine-grained locks Striped locks cover a range (not resized) Read/Write locks FIFO property tricky Art of Multiprocessor Programming 74

68 Stop The World Resizing Resizing stops all concurrent operations What about an incremental resize? Must avoid locking the table A lock-free table + incremental resizing? Art of Multiprocessor Programming 75

69 Lock-Free Resizing Problem Art of Multiprocessor Programming 76

70 Lock-Free Resizing Problem Need to extend table Art of Multiprocessor Programming 77

71 Lock-Free Resizing Problem Art of Multiprocessor Programming 78

72 Lock-Free Resizing Problem to remove and then add even a single item: single location CAS not enough We need a new idea Art of Multiprocessor Programming 79

73 Don t move the items Move the buckets instead! Keep all items in a single, lock-free list Buckets are short-cuts into the list Art of Multiprocessor Programming 80

74 Recursive Split Ordering Art of Multiprocessor Programming 81

75 Recursive Split Ordering 1/ Art of Multiprocessor Programming 82

76 Recursive Split Ordering 1/4 1/2 3/ Art of Multiprocessor Programming 83

77 Recursive Split Ordering 1/4 1/2 3/ List entries sorted in order that allows recursive splitting. How? Art of Multiprocessor Programming 84

78 Recursive Split Ordering Art of Multiprocessor Programming 85

79 Recursive Split Ordering LSB 0 LSB LSB = Least significant Bit Art of Multiprocessor Programming 86

80 Recursive Split Ordering LSB 00 LSB 10 LSB 01 LSB Art of Multiprocessor Programming 87

81 Split-Order If the table size is 2 i, Bucket b contains keys k k = b (mod 2 i ) bucket index consists of key's i LSBs Art of Multiprocessor Programming 88

82 When Table Splits Some keys stay b = k mod(2 i+1 ) Some move b+2 i = k mod(2 i+1 ) Determined by (i+1) st bit Counting backwards Key must be accessible from both Keys that will move must come later Art of Multiprocessor Programming 89

83 A Bit of Magic Real keys: Art of Multiprocessor Programming 90

84 A Bit of Magic Real keys: Real key 1 is in the 4 th location Split-order: Art of Multiprocessor Programming 91

85 A Bit of Magic Real keys: Real key 1 is in 4 th location Split-order: Art of Multiprocessor Programming 92

86 A Bit of Magic Real keys: Split-order: Art of Multiprocessor Programming 93

87 A Bit of Magic Real keys: Split-order: Just reverse the order of the key bits Art of Multiprocessor Programming 94

88 Split Ordered Hashing Order according to reversed bits Art of Multiprocessor Programming 95

89 Bucket Relations parent child Art of Multiprocessor Programming 96

90 Parent Always Provides a Short Cut search Art of Multiprocessor Programming 97

91 Sentinel Nodes Problem: how to remove a node pointed by 2 sources using CAS Art of Multiprocessor Programming 98

92 Sentinel Nodes Solution: use a Sentinel node for each bucket Art of Multiprocessor Programming 99

93 Sentinel vs Regular Keys Want sentinel key for i ordered before all keys that hash to bucket i after all keys that hash to bucket (i-1) Art of Multiprocessor Programming 100

94 Splitting a Bucket We can now split a bucket In a lock-free manner Using two CAS() calls... One to add the sentinel to the list The other to point from the bucket to the sentinel Art of Multiprocessor Programming 101

95 Initialization of Buckets Art of Multiprocessor Programming 102

96 Initialization of Buckets Need to initialize bucket 3 to split bucket 1 Art of Multiprocessor Programming 103

97 Adding hashes to Must initialize bucket 2 Before adding 10 Art of Multiprocessor Programming 104

98 Recursive Initialization To add 7 to the list 7 = 3 mod = 1 mod Could be log n depth But expected depth is constant Must initialize bucket 1 Must initialize bucket 3 Art of Multiprocessor Programming 105

99 Lock-Free List int makeregularkey(int key) { return reverse(key 0x ); } int makesentinelkey(int key) { return reverse(key); } Art of Multiprocessor Programming 106

100 Lock-Free List int makeregularkey(int key) { return reverse(key 0x ); } int makesentinelkey(int key) { return reverse(key); } Regular key: set high-order bit to 1 and reverse Art of Multiprocessor Programming 107

101 Lock-Free List int makeregularkey(int key) { return reverse(key 0x ); } int makesentinelkey(int key) { return reverse(key); } Sentinel key: simply reverse (high-order bit is 0) Art of Multiprocessor Programming 108

102 Main List Lock-Free List from earlier class With some minor variations Art of Multiprocessor Programming 109

103 Lock-Free List public class LockFreeList { public boolean add(object object, int key) {...} public boolean remove(int k) {...} public boolean contains(int k) {...} public LockFreeList(LockFreeList parent, int key) {...}; } Art of Multiprocessor Programming 110

104 Lock-Free List public class LockFreeList { public boolean add(object object, int key) {...} public boolean remove(int k) {...} public boolean contains(int k) {...} public LockFreeList(LockFreeList Change: add takes parent, key int key) {...}; } argument Art of Multiprocessor Programming 111

105 Lock-Free List Inserts sentinel with key if not public class LockFreeList { public already boolean present add(object object, int key) {...} public boolean remove(int k) {...} public boolean contains(int k) {...} public LockFreeList(LockFreeList parent, int key) {...}; } Art of Multiprocessor Programming 112

106 Lock-Free List returns new list starting with sentinel (shares with parent) public class LockFreeList { public boolean add(object object, int key) {...} public boolean remove(int k) {...} public boolean contains(int k) {...} public LockFreeList(LockFreeList parent, int key) {...}; } Art of Multiprocessor Programming 113

107 Split-Ordered Set: Fields public class SOSet { protected LockFreeList[] table; protected AtomicInteger tablesize; protected AtomicInteger setsize; public SOSet(int capacity) { table = new LockFreeList[capacity]; table[0] = new LockFreeList(); tablesize = new AtomicInteger(2); setsize = new AtomicInteger(0); } Art of Multiprocessor Programming 114

108 Fields public class SOSet { protected LockFreeList[] table; protected AtomicInteger tablesize; protected AtomicInteger setsize; public SOSet(int capacity) { table = new LockFreeList[capacity]; table[0] = new LockFreeList(); tablesize = new AtomicInteger(2); setsize = new AtomicInteger(0); array } For simplicity treat table as big Art of Multiprocessor Programming 115

109 Fields public class SOSet { protected LockFreeList[] table; protected AtomicInteger tablesize; protected AtomicInteger setsize; public SOSet(int capacity) { table = new LockFreeList[capacity]; table[0] = new LockFreeList(); tablesize = new AtomicInteger(2); setsize = grows new AtomicInteger(0); dynamically } In practice, want something that Art of Multiprocessor Programming 116

110 Fields public class SOSet { protected LockFreeList[] table; protected AtomicInteger tablesize; protected AtomicInteger setsize; public SOSet(int capacity) { table = new LockFreeList[capacity]; table[0] = new LockFreeList(); tablesize = new AtomicInteger(2); setsize = new actually AtomicInteger(0); using? } How much of table array are we Art of Multiprocessor Programming 117

111 Fields public class SOSet { protected LockFreeList[] table; protected AtomicInteger tablesize; protected AtomicInteger setsize; public SOSet(int capacity) { table = new LockFreeList[capacity]; table[0] = new LockFreeList(); tablesize = new Track AtomicInteger(2); set size setsize so = we new know AtomicInteger(0); when resize } Art of Multiprocessor Programming 118

112 Fields Initially use single bucket, public class SOSet { protected LockFreeList[] table; protected and size AtomicInteger is zero tablesize; protected AtomicInteger setsize; public SOSet(int capacity) { table = new LockFreeList[capacity]; table[0] = new LockFreeList(); tablesize = new AtomicInteger(1); setsize = new AtomicInteger(0); } Art of Multiprocessor Programming 119

113 add() public boolean add(object object) { int hash = object.hashcode(); int bucket = hash % tablesize.get(); int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; resizecheck(); return true; } Art of Multiprocessor Programming 120

114 add() public boolean add(object object) { int hash = object.hashcode(); int bucket = hash % tablesize.get(); int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; resizecheck(); return true; } Pick a bucket Art of Multiprocessor Programming 121

115 add() public boolean add(object object) { int hash = object.hashcode(); int bucket = hash % tablesize.get(); int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; } resizecheck(); return true; Non-Sentinel split-ordered key Art of Multiprocessor Programming 122

116 add() public boolean add(object object) { int hash = object.hashcode(); int bucket = hash % tablesize.get(); int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; resizecheck(); return Get true; reference to bucket s } sentinel, initializing if necessary Art of Multiprocessor Programming 123

117 add() public boolean add(object object) { Call bucket s add() method with int hash = object.hashcode(); int bucket reversed = hash % tablesize.get(); key int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; resizecheck(); return true; } Art of Multiprocessor Programming 124

118 add() public boolean add(object object) { No change? We re done. int hash = object.hashcode(); int bucket = hash % tablesize.get(); int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; resizecheck(); return true; } Art of Multiprocessor Programming 125

119 add() public boolean add(object object) { Time to resize? int hash = object.hashcode(); int bucket = hash % tablesize.get(); int key = makeregularkey(hash); LockFreeList list = getbucketlist(bucket); if (!list.add(object, key)) return false; resizecheck(); return true; } Art of Multiprocessor Programming 126

120 Resize Divide set size by total number of buckets If quotient exceeds threshold Double tablesize field Up to fixed limit Art of Multiprocessor Programming 127

121 Initialize Buckets Buckets originally null If you find one, initialize it Go to bucket s parent Earlier nearby bucket Recursively initialize if necessary Constant expected work Art of Multiprocessor Programming 128

122 Recall: Recursive Initialization To add 7 to the list 7 = 3 mod = 1 mod expected Could depth be log n is depth constant Must initialize bucket 1 Must initialize bucket 3 Art of Multiprocessor Programming 129

123 Initialize Bucket void initializebucket(int bucket) { int parent = getparent(bucket); if (table[parent] == null) initializebucket(parent); int key = makesentinelkey(bucket); LockFreeList list = new LockFreeList(table[parent], key); } Art of Multiprocessor Programming 130

124 Initialize Bucket void initializebucket(int bucket) { int parent = getparent(bucket); if (table[parent] == null) initializebucket(parent); int key = makesentinelkey(bucket); LockFreeList list = new LockFreeList(table[parent], key); } Find parent, recursively initialize if needed Art of Multiprocessor Programming 131

125 Initialize Bucket void initializebucket(int bucket) { int parent = getparent(bucket); if (table[parent] == null) initializebucket(parent); int key = makesentinelkey(bucket); LockFreeList list = new LockFreeList(table[parent], key); } Prepare key for new sentinel Art of Multiprocessor Programming 132

126 Initialize Bucket void initializebucket(int bucket) { int parent = getparent(bucket); if (table[parent] back reference == to null) rest of list initializebucket(parent); int key = makesentinelkey(bucket); LockFreeList list = new LockFreeList(table[parent], key); } Insert sentinel if not present, and get Art of Multiprocessor Programming 133

127 Correctness Linearizable concurrent set Theorem: O(1) expected time No more than O(1) items expected between two sentinels on average Lazy initialization causes at most O(1) expected recursion depth in initializebucket() Can eliminate use of sentinels Art of Multiprocessor Programming 134

128 Closed (Chained) Hashing Advantages: with N buckets, M items, Uniform h retains good performance as table density (M/N) increases less resizing Disadvantages: dynamic memory allocation bad cache behavior (no locality) Oh, did we mention that cache behavior matters on a multicore?

129 Open Addressed Hashing Keep all items in an array One per bucket If you have collisions, find an empty bucket and use it Must know how to find items if they are outside their bucket

130 Linear Probing* h(x) z z H =7 contains(x) search linearly from h(x) to h(x) + H recorded in bucket. x *Attributed to Amdahl

131 Linear Probing z z z z h(x) z z z z z x z z z z z H =3 =6 add(x) put in first empty bucket, and update H.

132 Linear Probing Open address means M N Expected items in bucket same as Chaining Expected distance till open slot: M/N M/N = 0.5 search 2.5 buckets M/N = 0.9 search 50 buckets 2

133 Linear Probing Advantages: Good locality fewer cache misses Disadvantages: As M/N increases more cache misses searching 10s of unrelated buckets Clustering of keys into neighboring buckets As computation proceeds Contamination by deleted items more cache misses

134 But cycles can form z z z Cuckoo Hashing z h 1 (x) z yx z z z z z z z z z z z z z zw z z z z z h 2 (y) h 2 (x) add(x) if h 1 (x) and h 2 (x) full evict y and move it to h 2 (y) h 2 (x). Then place x in its place.

135 Cuckoo Hashing Advantages: contains(x): deterministic 2 buckets No clustering or contamination Disadvantages: 2 tables h i (x) are complex As M/N increases relocation cycles Above M/N = 0.5 Add() does not work!

136 Concurrent Cuckoo Hashing Need to either lock whole chain of displacements (see book) or have extra space to keep items as they are displaced step by step.

137 Hopscotch Hashing Single Array, Simple hash function Idea: define neighborhood of original bucket In neighborhood items found quickly Use sequences of displacements to move items into their neighborhood

138 Hopscotch Hashing h(x) z x H=4 contains(x) search in at most H buckets (the hop-range) based on hop-info bitmap. In practice pick H to be 32.

139 Hopscotch Hashing h(x) uwv x z r s add(x) probe linearly to find open slot. Move the empty slot via sequence of displacements into the hop-range of h(x).

140 Hopscotch Hashing contains wait-free, just look in neighborhood

141 Hopscotch Hashing contains wait-free, just look in neighborhood add expected distance same as in linear probing

142 Hopscotch Hashing contains wait-free, just look in neighborhood add Expected distance same as in linear probing resize neighborhood full less likely as H log n one word hop-info bitmap, or use smaller H and default to linear probing of bucket

143 Advantages Good locality and cache behavior As table density (M/N) increases less resizing Move cost to add()from contains(x) Easy to parallelize

144 Recall: Concurrent Chained Hashing Striped Locks Lock for add() and unsuccessful contains()

145 Concurrent Simple Hopscotch h(x) contains() is wait-free

146 Concurrent Simple Hopscotch u zv x r ts add(x) lock bucket, mark empty slot using CAS, add x erasing mark

147 Concurrent Simple Hopscotch u zv r s ts ts+1 add(x) lock bucket, mark empty slot using CAS, lock bucket and update timestamp of bucket being displaced before erasing old value

148 Concurrent Simple Hopscotch u zv s r x not found ts Contains(x) traverse using bitmap and if ts has not changed after traversal item not found. If ts changed, after a few tries traverse through all items.

149 Is performance dominated by cache behavior? Test on multicores and uniprocessors: Sun 64 way Niagara II, and Intel 3GHz Xeon Benchmarks pre-allocated memory to eliminate effects of memory management

150 ops /ms 5000 Sequential SPARC Throughput 90% contain, 5% insert, 5% remove Hopscotch_D Hopscotch_ND LinearProbing Chained Cuckoo table density with memory pre-allocated

151 ops /ms Sequential SPARC High-Density;Throuthput 90% contain, 5% insert,5% remove Hopscotch_D Hopscotch_ND LinearProbing Chained table density

152 ops /ms Sequential CoreDuo; Throughput 90% contain, 5% insert, 5% remove Cuckoo stops here Hopscotch_D Hopscotch_ND 2000 LinearProbing Chained Cuckoo table density

153 ops /ms Concurrent SPARC Throughput 90% density; 70% contain, 15% insert, 15% remove Hopscotch_D Chained_PRE Chained_MTM with memory pre-allocated with allocation CPUs

154 miss / ops 3 Concurrent SPARC Throughput 90% density; Cache-Miss per UnSuccessful-Lookup Hopscotch_D Chained_PRE 0 Chained_MTM CPUs

155 Summary Chained hash with striped locking is simple and effective in many cases Hopscotch with striped locking great cache behavior If incremental resizing needed go for split-ordered

156 This work is licensed under a Creative Commons Attribution- ShareAlike 2.5 License. You are free: to Share to copy, distribute and transmit the work to Remix to adapt the work Under the following conditions: Attribution. You must attribute the work to The Art of Multiprocessor Programming (but not in any way that suggests that the authors endorse you or your use of the work). Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to Any of the above conditions can be waived if you get permission from the copyright holder. Nothing in this license impairs or restricts the author's moral rights. Art of Multiprocessor Programming 165

Concurrency. Part 2, Chapter 10. Roger Wattenhofer. ETH Zurich Distributed Computing

Concurrency. Part 2, Chapter 10. Roger Wattenhofer. ETH Zurich Distributed Computing Concurrency Part 2, Chapter 10 Roger Wattenhofer ETH Zurich Distributed Computing www.disco.ethz.ch Overview Concurrent Linked List Fine-grained synchronization Optimistic synchronization Lazy synchronization

More information

Concurrent Data Structures

Concurrent Data Structures Concurrent Data Structures Chapter 8 Roger Wattenhofer ETH Zurich Distributed Computing www.disco.ethz.ch Overview Concurrent Linked List Fine-grained synchronization Optimistic synchronization Lazy synchronization

More information

Design and Evaluation of Scalable Software

Design and Evaluation of Scalable Software Design and Evaluation of Scalable Software Damian Dechev 1,2 1: University of Central Florida, CSE S3 Lab, http://cse.eecs.ucf.edu Orlando, FL 2: Sandia Labs, Livermore, CA Traditional Scaling Process

More information

Locking. Part 2, Chapter 7. Roger Wattenhofer. ETH Zurich Distributed Computing

Locking. Part 2, Chapter 7. Roger Wattenhofer. ETH Zurich Distributed Computing Locking Part 2, Chapter 7 Roger Wattenhofer ETH Zurich Distributed Computing www.disco.ethz.ch Overview Introduction Spin Locks Test-and-Set & Test-and-Test-and-Set Backoff lock Queue locks Concurrent

More information

Practice: Small Systems Part 2, Chapter 3

Practice: Small Systems Part 2, Chapter 3 Practice: Small Systems Part 2, Chapter 3 Roger Wattenhofer Overview Introduction Spin Locks Test and Set & Test and Test and Set Backoff lock Queue locks Concurrent Linked List Fine grained synchronization

More information

Linked Lists: Locking, Lock-Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Linked Lists: Locking, Lock-Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Linked Lists: Locking, Lock-Free, and Beyond Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Objects Adding threads should not lower throughput Contention

More information

Concurrent Skip Lists. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Concurrent Skip Lists. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists Companion slides for The by Maurice Herlihy & Nir Shavit Set Object Interface Collection of elements No duplicates Methods add() a new element remove() an element contains() if element

More information

Linked Lists: Locking, Lock- Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Linked Lists: Locking, Lock- Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Linked Lists: Locking, Lock- Free, and Beyond Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Coarse-Grained Synchronization Each method locks the object Avoid

More information

Introduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Introduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Introduction Companion slides for The by Maurice Herlihy & Nir Shavit Moore s Law Transistor count still rising Clock speed flattening sharply 2 Moore s Law (in practice) 3 Nearly Extinct: the Uniprocesor

More information

Programming Paradigms for Concurrency Lecture 3 Concurrent Objects

Programming Paradigms for Concurrency Lecture 3 Concurrent Objects Programming Paradigms for Concurrency Lecture 3 Concurrent Objects Based on companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Thomas Wies New York University

More information

Solution: a lock (a/k/a mutex) public: virtual void unlock() =0;

Solution: a lock (a/k/a mutex) public: virtual void unlock() =0; 1 Solution: a lock (a/k/a mutex) class BasicLock { public: virtual void lock() =0; virtual void unlock() =0; ; 2 Using a lock class Counter { public: int get_and_inc() { lock_.lock(); int old = count_;

More information

Coarse-grained and fine-grained locking Niklas Fors

Coarse-grained and fine-grained locking Niklas Fors Coarse-grained and fine-grained locking Niklas Fors 2013-12-05 Slides borrowed from: http://cs.brown.edu/courses/cs176course_information.shtml Art of Multiprocessor Programming 1 Topics discussed Coarse-grained

More information

Spin Locks and Contention

Spin Locks and Contention Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified for Software1 students by Lior Wolf and Mati Shomrat Kinds of Architectures

More information

Spin Locks and Contention. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Spin Locks and Contention. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Focus so far: Correctness and Progress Models Accurate (we never lied to you) But idealized

More information

Spin Locks and Contention. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Spin Locks and Contention. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Real world concurrency Understanding hardware architecture What is contention How to

More information

Hopscotch Hashing. 1 Introduction. Maurice Herlihy 1, Nir Shavit 2,3, and Moran Tzafrir 3

Hopscotch Hashing. 1 Introduction. Maurice Herlihy 1, Nir Shavit 2,3, and Moran Tzafrir 3 Hopscotch Hashing Maurice Herlihy 1, Nir Shavit 2,3, and Moran Tzafrir 3 1 Brown University, Providence, RI 2 Sun Microsystems, Burlington, MA 3 Tel-Aviv University, Tel-Aviv, Israel Abstract. We present

More information

Introduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far

Introduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far Chapter 5 Hashing 2 Introduction hashing performs basic operations, such as insertion, deletion, and finds in average time better than other ADTs we ve seen so far 3 Hashing a hash table is merely an hashing

More information

Locking Granularity. CS 475, Spring 2019 Concurrent & Distributed Systems. With material from Herlihy & Shavit, Art of Multiprocessor Programming

Locking Granularity. CS 475, Spring 2019 Concurrent & Distributed Systems. With material from Herlihy & Shavit, Art of Multiprocessor Programming Locking Granularity CS 475, Spring 2019 Concurrent & Distributed Systems With material from Herlihy & Shavit, Art of Multiprocessor Programming Discussion: HW1 Part 4 addtolist(key1, newvalue) Thread 1

More information

Chapter 5 Hashing. Introduction. Hashing. Hashing Functions. hashing performs basic operations, such as insertion,

Chapter 5 Hashing. Introduction. Hashing. Hashing Functions. hashing performs basic operations, such as insertion, Introduction Chapter 5 Hashing hashing performs basic operations, such as insertion, deletion, and finds in average time 2 Hashing a hash table is merely an of some fixed size hashing converts into locations

More information

Split-Ordered Lists: Lock-Free Extensible Hash Tables. Pierre LaBorde

Split-Ordered Lists: Lock-Free Extensible Hash Tables. Pierre LaBorde 1 Split-Ordered Lists: Lock-Free Extensible Hash Tables Pierre LaBorde Nir Shavit 2 Tel-Aviv University, Israel Ph.D. from Hebrew University Professor at School of Computer Science at Tel-Aviv University

More information

Concurrent Queues, Monitors, and the ABA problem. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Concurrent Queues, Monitors, and the ABA problem. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Queues, Monitors, and the ABA problem Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Queues Often used as buffers between producers and consumers

More information

Lecture 7: Mutual Exclusion 2/16/12. slides adapted from The Art of Multiprocessor Programming, Herlihy and Shavit

Lecture 7: Mutual Exclusion 2/16/12. slides adapted from The Art of Multiprocessor Programming, Herlihy and Shavit Principles of Concurrency and Parallelism Lecture 7: Mutual Exclusion 2/16/12 slides adapted from The Art of Multiprocessor Programming, Herlihy and Shavit Time Absolute, true and mathematical time, of

More information

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course Today s Topics Review Uses and motivations of hash tables Major concerns with hash tables Properties Hash function Hash

More information

Multiprocessor Cache Coherency. What is Cache Coherence?

Multiprocessor Cache Coherency. What is Cache Coherence? Multiprocessor Cache Coherency CS448 1 What is Cache Coherence? Two processors can have two different values for the same memory location 2 1 Terminology Coherence Defines what values can be returned by

More information

Universality of Consensus. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Universality of Consensus. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Universality of Consensus Companion slides for The by Maurice Herlihy & Nir Shavit Turing Computability 1 0 1 1 0 1 0 A mathematical model of computation Computable = Computable on a T-Machine 2 Shared-Memory

More information

Hashing Techniques. Material based on slides by George Bebis

Hashing Techniques. Material based on slides by George Bebis Hashing Techniques Material based on slides by George Bebis https://www.cse.unr.edu/~bebis/cs477/lect/hashing.ppt The Search Problem Find items with keys matching a given search key Given an array A, containing

More information

! A Hash Table is used to implement a set, ! The table uses a function that maps an. ! The function is called a hash function.

! A Hash Table is used to implement a set, ! The table uses a function that maps an. ! The function is called a hash function. Hash Tables Chapter 20 CS 3358 Summer II 2013 Jill Seaman Sections 201, 202, 203, 204 (not 2042), 205 1 What are hash tables?! A Hash Table is used to implement a set, providing basic operations in constant

More information

General Idea. Key could be an integer, a string, etc e.g. a name or Id that is a part of a large employee structure

General Idea. Key could be an integer, a string, etc e.g. a name or Id that is a part of a large employee structure Hashing 1 Hash Tables We ll discuss the hash table ADT which supports only a subset of the operations allowed by binary search trees. The implementation of hash tables is called hashing. Hashing is a technique

More information

Introduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Introduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Introduction Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Moore s Law Transistor count still rising Clock speed flattening sharply Art of Multiprocessor Programming

More information

Linked Lists: The Role of Locking. Erez Petrank Technion

Linked Lists: The Role of Locking. Erez Petrank Technion Linked Lists: The Role of Locking Erez Petrank Technion Why Data Structures? Concurrent Data Structures are building blocks Used as libraries Construction principles apply broadly This Lecture Designing

More information

Question Bank Subject: Advanced Data Structures Class: SE Computer

Question Bank Subject: Advanced Data Structures Class: SE Computer Question Bank Subject: Advanced Data Structures Class: SE Computer Question1: Write a non recursive pseudo code for post order traversal of binary tree Answer: Pseudo Code: 1. Push root into Stack_One.

More information

Introduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit. Art of Multiprocessor Programming

Introduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit. Art of Multiprocessor Programming Introduction Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Art of Multiprocessor Programming Moore s Law Transistor count still rising Clock speed flattening

More information

Chapter 12: Indexing and Hashing. Basic Concepts

Chapter 12: Indexing and Hashing. Basic Concepts Chapter 12: Indexing and Hashing! Basic Concepts! Ordered Indices! B+-Tree Index Files! B-Tree Index Files! Static Hashing! Dynamic Hashing! Comparison of Ordered Indexing and Hashing! Index Definition

More information

Database Technology. Topic 7: Data Structures for Databases. Olaf Hartig.

Database Technology. Topic 7: Data Structures for Databases. Olaf Hartig. Topic 7: Data Structures for Databases Olaf Hartig olaf.hartig@liu.se Database System 2 Storage Hierarchy Traditional Storage Hierarchy CPU Cache memory Main memory Primary storage Disk Tape Secondary

More information

Chapter 12: Indexing and Hashing

Chapter 12: Indexing and Hashing Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree Index Files Static Hashing Dynamic Hashing Comparison of Ordered Indexing and Hashing Index Definition in SQL

More information

PERFORMANCE ANALYSIS AND OPTIMIZATION OF SKIP LISTS FOR MODERN MULTI-CORE ARCHITECTURES

PERFORMANCE ANALYSIS AND OPTIMIZATION OF SKIP LISTS FOR MODERN MULTI-CORE ARCHITECTURES PERFORMANCE ANALYSIS AND OPTIMIZATION OF SKIP LISTS FOR MODERN MULTI-CORE ARCHITECTURES Anish Athalye and Patrick Long Mentors: Austin Clements and Stephen Tu 3 rd annual MIT PRIMES Conference Sequential

More information

MemC3: MemCache with CLOCK and Concurrent Cuckoo Hashing

MemC3: MemCache with CLOCK and Concurrent Cuckoo Hashing MemC3: MemCache with CLOCK and Concurrent Cuckoo Hashing Bin Fan (CMU), Dave Andersen (CMU), Michael Kaminsky (Intel Labs) NSDI 2013 http://www.pdl.cmu.edu/ 1 Goal: Improve Memcached 1. Reduce space overhead

More information

Extra: B+ Trees. Motivations. Differences between BST and B+ 10/27/2017. CS1: Java Programming Colorado State University

Extra: B+ Trees. Motivations. Differences between BST and B+ 10/27/2017. CS1: Java Programming Colorado State University Extra: B+ Trees CS1: Java Programming Colorado State University Slides by Wim Bohm and Russ Wakefield 1 Motivations Many times you want to minimize the disk accesses while doing a search. A binary search

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

CSC 261/461 Database Systems Lecture 17. Fall 2017

CSC 261/461 Database Systems Lecture 17. Fall 2017 CSC 261/461 Database Systems Lecture 17 Fall 2017 Announcement Quiz 6 Due: Tonight at 11:59 pm Project 1 Milepost 3 Due: Nov 10 Project 2 Part 2 (Optional) Due: Nov 15 The IO Model & External Sorting Today

More information

Programming Paradigms for Concurrency Introduction

Programming Paradigms for Concurrency Introduction Programming Paradigms for Concurrency Introduction Based on companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Thomas Wies New York University Moore

More information

UNIT III BALANCED SEARCH TREES AND INDEXING

UNIT III BALANCED SEARCH TREES AND INDEXING UNIT III BALANCED SEARCH TREES AND INDEXING OBJECTIVE The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions and finds in constant

More information

Data and File Structures Chapter 11. Hashing

Data and File Structures Chapter 11. Hashing Data and File Structures Chapter 11 Hashing 1 Motivation Sequential Searching can be done in O(N) access time, meaning that the number of seeks grows in proportion to the size of the file. B-Trees improve

More information

Hashing. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Hashing. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Hashing CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Overview Hashing Technique supporting insertion, deletion and

More information

CITS2200 Data Structures and Algorithms. Topic 15. Hash Tables

CITS2200 Data Structures and Algorithms. Topic 15. Hash Tables CITS2200 Data Structures and Algorithms Topic 15 Hash Tables Introduction to hashing basic ideas Hash functions properties, 2-universal functions, hashing non-integers Collision resolution bucketing and

More information

15 418/618 Project Final Report Concurrent Lock free BST

15 418/618 Project Final Report Concurrent Lock free BST 15 418/618 Project Final Report Concurrent Lock free BST Names: Swapnil Pimpale, Romit Kudtarkar AndrewID: spimpale, rkudtark 1.0 SUMMARY We implemented two concurrent binary search trees (BSTs): a fine

More information

Goldibear and the 3 Locks. Programming With Locks Is Tricky. More Lock Madness. And To Make It Worse. Transactional Memory: The Big Idea

Goldibear and the 3 Locks. Programming With Locks Is Tricky. More Lock Madness. And To Make It Worse. Transactional Memory: The Big Idea Programming With Locks s Tricky Multicore processors are the way of the foreseeable future thread-level parallelism anointed as parallelism model of choice Just one problem Writing lock-based multi-threaded

More information

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum Table ADT and Sorting Algorithm topics continuing (or reviewing?) CS 24 curriculum A table ADT (a.k.a. Dictionary, Map) Table public interface: // Put information in the table, and a unique key to identify

More information

Symbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management

Symbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management Hashing Symbol Table Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management In general, the following operations are performed on

More information

Module 2: Classical Algorithm Design Techniques

Module 2: Classical Algorithm Design Techniques Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module

More information

Chapter 11: Indexing and Hashing

Chapter 11: Indexing and Hashing Chapter 11: Indexing and Hashing Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 11: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files B-Tree

More information

Linked Lists: Locking, Lock- Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Linked Lists: Locking, Lock- Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Linked Lists: Locking, Lock- Free, and Beyond Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Last Lecture: Spin-Locks CS. spin lock critical section Resets lock

More information

Hash[ string key ] ==> integer value

Hash[ string key ] ==> integer value Hashing 1 Overview Hash[ string key ] ==> integer value Hash Table Data Structure : Use-case To support insertion, deletion and search in average-case constant time Assumption: Order of elements irrelevant

More information

Shared-Memory Computability

Shared-Memory Computability Shared-Memory Computability 10011 Universal Object Wait-free/Lock-free computable = Threads with methods that solve n- consensus Art of Multiprocessor Programming Copyright Herlihy- Shavit 2007 93 GetAndSet

More information

Distributed Computing Group

Distributed Computing Group Distributed Computing Group HS 2009 Prof. Dr. Roger Wattenhofer, Thomas Locher, Remo Meier, Benjamin Sigg Assigned: December 11, 2009 Discussion: none Distributed Systems Theory exercise 6 1 ALock2 Have

More information

Chapter 11: Indexing and Hashing

Chapter 11: Indexing and Hashing Chapter 11: Indexing and Hashing Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 11: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files B-Tree

More information

COMP171. Hashing.

COMP171. Hashing. COMP171 Hashing Hashing 2 Hashing Again, a (dynamic) set of elements in which we do search, insert, and delete Linear ones: lists, stacks, queues, Nonlinear ones: trees, graphs (relations between elements

More information

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 Prof. John Park Based on slides from previous iterations of this course Today s Topics Overview Uses and motivations of hash tables Major concerns with hash

More information

Programming Paradigms for Concurrency Lecture 2 - Mutual Exclusion

Programming Paradigms for Concurrency Lecture 2 - Mutual Exclusion Programming Paradigms for Concurrency Lecture 2 - Mutual Exclusion Based on companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Thomas Wies New York University

More information

Advanced Database Systems

Advanced Database Systems Lecture IV Query Processing Kyumars Sheykh Esmaili Basic Steps in Query Processing 2 Query Optimization Many equivalent execution plans Choosing the best one Based on Heuristics, Cost Will be discussed

More information

Chapter 12: Indexing and Hashing

Chapter 12: Indexing and Hashing Chapter 12: Indexing and Hashing Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files B-Tree

More information

CSCI Analysis of Algorithms I

CSCI Analysis of Algorithms I CSCI 305 - Analysis of Algorithms I 04 June 2018 Filip Jagodzinski Computer Science Western Washington University Announcements Remainder of the term 04 June : lecture 05 June : lecture 06 June : lecture,

More information

CSE373: Data Structures & Algorithms Lecture 17: Hash Collisions. Kevin Quinn Fall 2015

CSE373: Data Structures & Algorithms Lecture 17: Hash Collisions. Kevin Quinn Fall 2015 CSE373: Data Structures & Algorithms Lecture 17: Hash Collisions Kevin Quinn Fall 2015 Hash Tables: Review Aim for constant-time (i.e., O(1)) find, insert, and delete On average under some reasonable assumptions

More information

Scalable Concurrent Hash Tables via Relativistic Programming

Scalable Concurrent Hash Tables via Relativistic Programming Scalable Concurrent Hash Tables via Relativistic Programming Josh Triplett September 24, 2009 Speed of data < Speed of light Speed of light: 3e8 meters/second Processor speed: 3 GHz, 3e9 cycles/second

More information

Chapter 11: Indexing and Hashing

Chapter 11: Indexing and Hashing Chapter 11: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files B-Tree Index Files Static Hashing Dynamic Hashing Comparison of Ordered Indexing and Hashing Index Definition in SQL

More information

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See  for conditions on re-use Chapter 11: Indexing and Hashing Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files Static

More information

Chapter 17. Disk Storage, Basic File Structures, and Hashing. Records. Blocking

Chapter 17. Disk Storage, Basic File Structures, and Hashing. Records. Blocking Chapter 17 Disk Storage, Basic File Structures, and Hashing Records Fixed and variable length records Records contain fields which have values of a particular type (e.g., amount, date, time, age) Fields

More information

lecture23: Hash Tables

lecture23: Hash Tables lecture23: Largely based on slides by Cinda Heeren CS 225 UIUC 18th July, 2013 Announcements mp6.1 extra credit due tomorrow tonight (7/19) lab avl due tonight mp6 due Monday (7/22) Hash tables A hash

More information

Programming Paradigms for Concurrency Lecture 6 Synchronization of Concurrent Objects

Programming Paradigms for Concurrency Lecture 6 Synchronization of Concurrent Objects Programming Paradigms for Concurrency Lecture 6 Synchronization of Concurrent Objects Based on companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Thomas

More information

Open Addressing: Linear Probing (cont.)

Open Addressing: Linear Probing (cont.) Open Addressing: Linear Probing (cont.) Cons of Linear Probing () more complex insert, find, remove methods () primary clustering phenomenon items tend to cluster together in the bucket array, as clustering

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Hashing & Hash Tables 1 Overview Hash Table Data Structure : Purpose To support insertion, deletion and search in average-case constant t time Assumption: Order of elements irrelevant ==> data structure

More information

Hash Table and Hashing

Hash Table and Hashing Hash Table and Hashing The tree structures discussed so far assume that we can only work with the input keys by comparing them. No other operation is considered. In practice, it is often true that an input

More information

Panu Silvasti Page 1

Panu Silvasti Page 1 Multicore support in databases Panu Silvasti Page 1 Outline Building blocks of a storage manager How do existing storage managers scale? Optimizing Shore database for multicore processors Page 2 Building

More information

Module 5: Hashing. CS Data Structures and Data Management. Reza Dorrigiv, Daniel Roche. School of Computer Science, University of Waterloo

Module 5: Hashing. CS Data Structures and Data Management. Reza Dorrigiv, Daniel Roche. School of Computer Science, University of Waterloo Module 5: Hashing CS 240 - Data Structures and Data Management Reza Dorrigiv, Daniel Roche School of Computer Science, University of Waterloo Winter 2010 Reza Dorrigiv, Daniel Roche (CS, UW) CS240 - Module

More information

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable Hashing Dynamic Dictionaries Operations: create insert find remove max/ min write out in sorted order Only defined for object classes that are Comparable Hash tables Operations: create insert find remove

More information

Chapter 12: Indexing and Hashing (Cnt(

Chapter 12: Indexing and Hashing (Cnt( Chapter 12: Indexing and Hashing (Cnt( Cnt.) Basic Concepts Ordered Indices B+-Tree Index Files B-Tree Index Files Static Hashing Dynamic Hashing Comparison of Ordered Indexing and Hashing Index Definition

More information

Problem. Context. Hash table

Problem. Context. Hash table Problem In many problems, it is natural to use Hash table as their data structures. How can the hash table be efficiently accessed among multiple units of execution (UEs)? Context Hash table is used when

More information

Peterson s Algorithm

Peterson s Algorithm Peterson s Algorithm public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {}; } public void unlock() { flag[i] = false; } 24/03/10 Art of Multiprocessor Programming 1 Mutual

More information

HASH TABLES. CSE 332 Data Abstractions: B Trees and Hash Tables Make a Complete Breakfast. An Ideal Hash Functions.

HASH TABLES. CSE 332 Data Abstractions: B Trees and Hash Tables Make a Complete Breakfast. An Ideal Hash Functions. -- CSE Data Abstractions: B Trees and Hash Tables Make a Complete Breakfast Kate Deibel Summer The national data structure of the Netherlands HASH TABLES July, CSE Data Abstractions, Summer July, CSE Data

More information

Algorithms and Data Structures

Algorithms and Data Structures Lesson 4: Sets, Dictionaries and Hash Tables Luciano Bononi http://www.cs.unibo.it/~bononi/ (slide credits: these slides are a revised version of slides created by Dr. Gabriele D Angelo)

More information

Chapter 11: Indexing and Hashing" Chapter 11: Indexing and Hashing"

Chapter 11: Indexing and Hashing Chapter 11: Indexing and Hashing Chapter 11: Indexing and Hashing" Database System Concepts, 6 th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Chapter 11: Indexing and Hashing" Basic Concepts!

More information

NON-BLOCKING DATA STRUCTURES AND TRANSACTIONAL MEMORY. Tim Harris, 3 Nov 2017

NON-BLOCKING DATA STRUCTURES AND TRANSACTIONAL MEMORY. Tim Harris, 3 Nov 2017 NON-BLOCKING DATA STRUCTURES AND TRANSACTIONAL MEMORY Tim Harris, 3 Nov 2017 Lecture 1/3 Introduction Basic spin-locks Queue-based locks Hierarchical locks Reader-writer locks Reading without locking Flat

More information

Chapter 20 Hash Tables

Chapter 20 Hash Tables Chapter 20 Hash Tables Dictionary All elements have a unique key. Operations: o Insert element with a specified key. o Search for element by key. o Delete element by key. Random vs. sequential access.

More information

CARNEGIE MELLON UNIVERSITY DEPT. OF COMPUTER SCIENCE DATABASE APPLICATIONS

CARNEGIE MELLON UNIVERSITY DEPT. OF COMPUTER SCIENCE DATABASE APPLICATIONS CARNEGIE MELLON UNIVERSITY DEPT. OF COMPUTER SCIENCE 15-415 DATABASE APPLICATIONS C. Faloutsos Indexing and Hashing 15-415 Database Applications http://www.cs.cmu.edu/~christos/courses/dbms.s00/ general

More information

Access Methods. Basic Concepts. Index Evaluation Metrics. search key pointer. record. value. Value

Access Methods. Basic Concepts. Index Evaluation Metrics. search key pointer. record. value. Value Access Methods This is a modified version of Prof. Hector Garcia Molina s slides. All copy rights belong to the original author. Basic Concepts search key pointer Value record? value Search Key - set of

More information

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana Introduction to Indexing 2 Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana Indexed Sequential Access Method We have seen that too small or too large an index (in other words too few or too

More information

Phase-Concurrent Hash Tables for Determinism

Phase-Concurrent Hash Tables for Determinism Phase-Concurrent Hash Tables for Determinism Julian Shun Carnegie Mellon University jshun@cs.cmu.edu Guy E. Blelloch Carnegie Mellon University guyb@cs.cmu.edu ABSTRACT We present a deterministic phase-concurrent

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 11 Synchronisation in Java II Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of this lecture Mutual exclusion in Java continued (next lecture:

More information

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions. DATA STRUCTURES COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book. Data

More information

CSE 143. Lecture 28: Hashing

CSE 143. Lecture 28: Hashing CSE 143 Lecture 28: Hashing SearchTree as a set We implemented a class SearchTree to store a BST of ints: Our BST is essentially a set of integers. Operations we support: add contains remove... -3 overallroot

More information

DATA STRUCTURES/UNIT 3

DATA STRUCTURES/UNIT 3 UNIT III SORTING AND SEARCHING 9 General Background Exchange sorts Selection and Tree Sorting Insertion Sorts Merge and Radix Sorts Basic Search Techniques Tree Searching General Search Trees- Hashing.

More information

Computer Science 136 Spring 2004 Professor Bruce. Final Examination May 19, 2004

Computer Science 136 Spring 2004 Professor Bruce. Final Examination May 19, 2004 Computer Science 136 Spring 2004 Professor Bruce Final Examination May 19, 2004 Question Points Score 1 10 2 8 3 15 4 12 5 12 6 8 7 10 TOTAL 65 Your name (Please print) I have neither given nor received

More information

Concurrent Objects. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Concurrent Objects. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Objects Companion slides for The by Maurice Herlihy & Nir Shavit Concurrent Computation memory object object 2 Objectivism What is a concurrent object? How do we describe one? How do we implement

More information

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( ) Review CSE 143 Java Hashing Want to implement Sets of objects Want fast contains( ), add( ) One strategy: a sorted list OK contains( ): use binary search Slow add( ): have to maintain list in sorted order

More information

Hash-Based Indexing 1

Hash-Based Indexing 1 Hash-Based Indexing 1 Tree Indexing Summary Static and dynamic data structures ISAM and B+ trees Speed up both range and equality searches B+ trees very widely used in practice ISAM trees can be useful

More information

Lecture 9: Multiprocessor OSs & Synchronization. CSC 469H1F Fall 2006 Angela Demke Brown

Lecture 9: Multiprocessor OSs & Synchronization. CSC 469H1F Fall 2006 Angela Demke Brown Lecture 9: Multiprocessor OSs & Synchronization CSC 469H1F Fall 2006 Angela Demke Brown The Problem Coordinated management of shared resources Resources may be accessed by multiple threads Need to control

More information

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity CS 350 Algorithms and Complexity Winter 2019 Lecture 12: Space & Time Tradeoffs. Part 2: Hashing & B-Trees Andrew P. Black Department of Computer Science Portland State University Space-for-time tradeoffs

More information

Intro to DB CHAPTER 12 INDEXING & HASHING

Intro to DB CHAPTER 12 INDEXING & HASHING Intro to DB CHAPTER 12 INDEXING & HASHING Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree Index Files Static Hashing Dynamic Hashing Comparison of Ordered Indexing

More information

NON-BLOCKING DATA STRUCTURES AND TRANSACTIONAL MEMORY. Tim Harris, 14 November 2014

NON-BLOCKING DATA STRUCTURES AND TRANSACTIONAL MEMORY. Tim Harris, 14 November 2014 NON-BLOCKING DATA STRUCTURES AND TRANSACTIONAL MEMORY Tim Harris, 14 November 2014 Lecture 6 Introduction Amdahl s law Basic spin-locks Queue-based locks Hierarchical locks Reader-writer locks Reading

More information

Modern High-Performance Locking

Modern High-Performance Locking Modern High-Performance Locking Nir Shavit Slides based in part on The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Locks (Mutual Exclusion) public interface Lock { public void lock();

More information