A Transaction-Friendy Binary Search Tree Tyler C RAIN Vincent G - - PowerPoint PPT Presentation
A Transaction-Friendy Binary Search Tree Tyler C RAIN Vincent G - - PowerPoint PPT Presentation
A Transaction-Friendy Binary Search Tree Tyler C RAIN Vincent G RAMOLI Michel R AYNAL { tyler.crain|raynal } @irisa.fr { vincent.gramoli } @epfl.ch TM Theory Workshop 2011 ASAP team, IRISA, Rennes, France & Distributed Programming Laboratory,
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Existing Data Structures
Preserving structural invariants
- Balanced Binary Trees
- Rotations keep the tree balanced
- Skiplist
- Node levels follow some fixed distribution
- Hashtable
- Bucket size must not exceed some threshold
2 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Using data structures with TM
Simple!
- Copy-paste into transactions (more or less)
+ Easy to program/use + The TM system ensures safety
- Are there disadvantages?
3 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Concurrent Data Structures
Balanced Binary Tree
- Specially designed for concurrency
- Hand-over-hand locking
- O(log n)
4 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Data Structures in TM (So far)
Balanced Binary Tree
- (Mostly) Unmodified from their original versions
- Not designed for concurrency or transactions
- Could lead to unnecessary conflicts and aborts.
- Ω(r log n)
5 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Ω(r log n)
What is r?
- The number of restarts
- Depends on the contention of the workload
- Depends on the conflicts between transactions
⇒ r depends on n
6 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Aborts and wasted work
- Still O(log n) operations?
Update 0% 10% 20% 30% 40% 50% AVL tree 29 415 711 1008 1981 2081 Sun red-black tree 31 573 965 1108 1484 1545
Table: Maximum #reads/op in 212 sized trees
- Can we relax some invariants in order to reduce conflicts?
7 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Example
- 3 operations
- 1 → insert, 2 → delete, 3 → contains
- 1
2 3
8 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Where they can conflict
- Along their entire path
- 1
2 3
9 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Goal
- Minimize conflicts
- 1
2 3
10 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Rotations
Correctness & Conflicts
- Rotations are not required for correctness
- There will be concurrent insertions/deletions
- Concurrent insertions/deletions might have conflicting
rotations
- They might cancel each other out
- A later insert/deletion might invalidate these rotations
- Idea: relax the balance requirement in order to allow more
concurrency
11 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Rotations cont.
Solution
- Separate rotations from insert/delete operations
- Perform rotations in their own thread
- Each rotation is a single transaction
12 / 38
Boug´ e L., Gabarro J., Messeguer X., Schabanel N., Height-relaxed AVL rebalancing: A unified, fine-grained approach to concurrent dictionaries. Tech Report RR1998-18, INRIA, 1998
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Deletions
Reducing conflicts further
- A delete operation can still modify the tree structure
- A successor must be found to replace the node being
deleted
13 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Deletions cont.
Solution
- Logical deletions
- Each node has a deleted boolean flag
- Initialized as false
- Set to true on deletion
- Allows concurrent operations to traverse the node being
deleted without conflicting
14 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Removals
- Logically deleted nodes must be removed from the tree
- Done in a separate thread
- Only nodes with 1 or 0 children are removed
15 / 38
Bronson N., Casper J., Chafi H., Olukotun K., A Practical Concurrent Binary Search Tree, PPoPP ’10
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Contains
- Each diagram is a single transaction
Traverse Traverse
16 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Insert
- Each diagram is a single transaction
Traverse Rotate ... Rotate Insert
Performed in separate thread
Traverse Insert + Rotate Propogate + + + Rotate
17 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Delete
- Each diagram is a single transaction
Traverse + Rotate Propogate + + Traverse Find Successor Remove/Swap Rotate Rotate ... Mark + Remove
Performed in separate thread
18 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Now we have
Abstract transaction conflicts
- 1
2 3
19 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Impact on read size
Update 0% 10% 20% 30% 40% 50% AVL tree 29 415 711 1008 1981 2081 Sun red-black tree 31 573 965 1108 1484 1545 Tx-friendly tree 29 75 123 120 144 180
Table: Maximum #reads/op in 212 sized trees
20 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Conclusion
Benefits of a Transaction Friendly Data Structure
- Improved Performance
- No difference to the programmer using the tree as a library
- Uses normal transactional reads/writes
- Compatible with many TMs
- Tested on TinySTM and E-STM
- Independent of TM specifications
- Tested using CTL/ETL, different contention managers
21 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Reusability
Move operation
22 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Future Work
Other structures
- Transaction friendly skip list
- Transaction friendly hash table
- Transaction friendly . . .
23 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
- There’s more?
24 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
TM Optimizations
Optional
- Certain TMs give mechanisms for improved performance
at the cost of safety
- Early-release
- E-STM
- View transactions
- Unit reads
25 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Unit Reads
- Returns the latest value written by a committed transaction
- Does not add the location to the read set or perform
validation
26 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
- How can unit reads be used to improve performance of the
algorithm?
27 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Current Situation
- Rotations can still conflict with concurrent
insert/delete/contains operations
- Rotation 1
Rotation 2
1 2 3
28 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Solution
- Use unit reads during the tree traversal
- Advantages:
- Faster traversals (unit reads are cheaper)
- Avoid during traversal
- Smaller read set
29 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Result
Abstract + Structural Transactions
- Rotation 1
Rotation 2
1 2 4
30 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
- What about safety?
- Algorithm becomes a bit more complicated to ensure
safety
31 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
New rotations
32 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
New removals
p j i i p j (a) Before removal NULL (b) After removal
33 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Traversals
- Mostly unit reads
- Transactional reads performed at bottom to ensure safety
- Each node has a removed flag
- Used to ensure traversal does not finish on a node that no
longer in the tree
34 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Impact on read size
Update 0% 10% 20% 30% 40% 50% AVL tree 29 415 711 1008 1981 2081 Sun red-black tree 31 573 965 1108 1484 1545 Tx-friendly tree 29 75 123 120 144 180 Unit read tree 2 5 6 13 15 18
Table: Maximum #reads/op in 212 sized trees
35 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
- Performance Results: Some graphs from benchmarks
36 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Microbench
5 10 15 1 8 16 24 32 40 48 5% update Normal RBtree TFtree NRtree AVLtree 5 10 15 1 8 16 24 32 40 48 Bias 2 4 6 8 10 1 8 16 24 32 40 48 10% update 2 4 6 8 10 1 8 16 24 32 40 48 2 4 6 8 1 8 16 24 32 40 48 15% update Throughput (ops/microsec) 2 4 6 8 1 8 16 24 32 40 48 2 4 6 8 1 8 16 24 32 40 48 20% update Number of threads 2 4 6 8 1 8 16 24 32 40 48 Number of threads
37 / 38
Data Structures Binary Trees Binary Search Tree for TM Conclusion Optional Optimizations Results
Vacation (STAMP)
1 2 3 4 5 6 7 1 8 16 24 32 40 48 10 20 30 40 50 60 70 1x transactions Vacation high contention RBtree speedup TFtree speedup NRtree speedup RBtree duration TFtree duration NRtree duration 1 2 3 4 5 6 7 1 8 16 24 32 40 48 10 20 30 40 50 Vacation low contention 1 2 3 4 5 6 1 8 16 24 32 40 48 200 400 600 800 1000 8x transactions Speedup 1 2 3 4 5 6 7 8 1 8 16 24 32 40 48 100 200 300 400 500 Duration (sec) 1 2 3 4 5 6 1 8 16 24 32 40 48 500 1000 1500 2000 2500 16x transactions Number of threads 1 2 3 4 5 6 7 8 9 1 8 16 24 32 40 48 500 1000 1500 Number of threads
38 / 38