310 likes | 486 Views
Concurrent AVL Trees. Implementation and Comparison Of course-grained and fine-grained. Brian Cheng bcheng@vt.edu. Jeremy Tate jtate09@vt.edu. |. Agenda. Introduction Solution Approach Analysis Future Work and Difficulties Encountered Conclusion. Agenda. Introduction
E N D
Concurrent AVL Trees Implementation and Comparison Of course-grained and fine-grained Brian Cheng bcheng@vt.edu Jeremy Tate jtate09@vt.edu |
Agenda • Introduction • Solution Approach • Analysis • Future Work and Difficulties Encountered • Conclusion
Agenda • Introduction • Solution Approach • Analysis • Future Work and Difficulties Encountered • Conclusion
Introduction • Binary Search Tree: data structure • Standard operations: • Add – Add a node to the tree • Remove – Remove a node from the tree • Contains – Determine whether the tree contains a node • Benefits: • Logarithmic in time complexity
Introduction • AVL Tree • Balanced tree where the height of any two leaf nodes do not differ by more than 1 • Benefits: • Height of tree is carefully managed to reduce the number of nodes to traverse; therefore, faster in operation (O(log(n))) • Concurrent AVL Tree • Course-grained lock - one lock for the tree • Fine-grained lock - one lock for each node in the tree
Introduction • Project Goals/Objectives: • Implement the following: • AVL Tree • Concurrent AVL Tree with Course-grained locks • Concurrent AVL Tree with Fine-grained locks • Test the two Concurrent implementations • Compare and analyze the test results
Past Efforts • Hanke [1] showed improved performance with a relaxed balance red-black tree in a concurrent context • Ellis [2] and Nurmi et. al [3] used sentinel nodes with "real" nodes as all being leaf nodes • Relax balance requirements
Agenda • Introduction • Solution Approach • Analysis • Future Work and Difficulties Encountered • Conclusion
Solution Approach • Reduce size of tree by not using sentinel nodes • Induce higher cost from lock contention • Gain performance from shorter tree • Relax balance requirements of nodes
Add() • General steps for adding a new item to the tree • Lock nodes in a hand-over-hand manner working down the tree going left or right depending on value comparison • Lock the tree before obtaining the next child node lock • Uses lock coupling to prevent deadlocks • If not able to lock both curr and next, release both locks and retry • Insert new node as specified child of parent • Test for rebalance
Contains() • Search for key • If search key less than current key, go left • Else go right • If search key is less than current key and current does not have a left child, key is not in the tree
Remove() • Search for key in tree • If found not found, return • Find replacement value giving preference to left subtree • Lock tree • Lock both curr and next • Unlock tree • Copy value of replacement • Remove replacement node from tree • Overwrite removed key with replacement
Rebalance Overview • Rebalance required if node balance outside of [-2,2] • Balance factor = left subtree height - right subtree height • Two rotations • Single • Double • Each rotation type has a mirrored version for left and right • Four total
Single Rotation • Blue’s child red is promoted to parent • Blue made right child of red
Double Rotation • "C" shape • Single rotate green node to be parent of red node • Green > red • Single rotation from original parent node • Blue node demoted to right child of green
Rebalance() • Lock tree • Test each node for imbalance • If unbalanced, rebalance • If balance factor outside of normal range, rebalance on child node • Relaxed height requirement • Unlock tree
Agenda • Introduction • Solution Approach • Analysis • Future Work and Difficulties Encountered • Conclusion
Analysis • Measured unit: Throughput (operations/milliseconds) • Number of operations per thread: 50,000 • Operation set for each thread • Add = 100% • Add = 80% Contains = 20% • Add = 50% Contains = 50% • Add = 20% Contains = 80% • Vary thread count for each set of operations • 1, 2, 5, 8, 10 Threads • Each test iteration was repeated five times and averaged
Analysis • Course-grained lock implementation produced higher throughput for a majority of tests • Fine-grained lock implementation with more contains() calls produced higher results for low thread counts • Possible Reasons: • Implementation of how a thread traverses a tree • Rebalance halts all other threads • Rebalance may cause other threads to restart operation
Agenda • Introduction • Solution Approach • Analysis • Future Work and Difficulties Encountered • Conclusion
Future Work • Finalize remove() • Extend the fine-grained implementation to remove nodes • Optimistic Approach • Instead of halting on rebalance to finish, assume it is correct and verify before returning • ReentrantReadWrite Lock • Use a read lock for when traversing and a write lock for when modifying the node
Difficulties Encountered • Below is a list of difficulties encountered during implementation: • Mutual exclusion • Fairness • Deadlocks on trees • Deadlocks on nodes • Validating tree state
Agenda • Introduction • Solution Approach • Analysis • Future Work and Difficulties Encountered • Conclusion
Conclusion • Measured throughput of the fine-grained lock did not meet theoretical expectations • Overhead induced by maintaining fine-grained locks could potentially outweigh the benefit of having several threads act on the same resource • Do not reinvent the wheel
References • S. Hanke, "The Performance of Concurrent Red-Black Tree Algorithms," Proceedings of the 3rd International Workshop on Algorithm Engineering, LNCS, vol. 1668, pp. 286-300, 1999. • C. S. Ellis, "Concurrent Search and Insertion in AVL Trees," IEEE Transactions on Computers, Vols. C-29, no. 9, pp. 811-817, 1980. • O. Nurmi, E. S. Soininen and D. Wood, "Relaxed AVL trees, main-memory databases and concurrency," International journal of computer mathematics, vol. 62, pp. 23-44, 1996.