160 likes | 538 Views
A Java Implementation of a Lock-Free Concurrent Priority Queue. Bart Verzijlenberg. Agenda. Algorithm Review Implementation Java Package used Testing Conclusion Questions. Algorithm Review. Priority Queue Lock-free Relies on atomic Compare and Swap operations. Algorithm Review.
E N D
A Java Implementation of a Lock-Free Concurrent Priority Queue Bart Verzijlenberg
Agenda • Algorithm Review • Implementation • Java Package used • Testing • Conclusion • Questions
Algorithm Review • Priority Queue • Lock-free • Relies on atomic Compare and Swap operations
Algorithm Review • The algorithm uses the Skip-List data structure • Extends the Skip-List for concurrent use • The Skip-List is sorted on the priority of the nodes • The algorithm is lock-free • No blocking • Prevent dead locks • Always progress by at least one operation • Risk of starvation
Algorithm ReviewSkip-List • Multi-layer linked list • Probabilistic alternative to balanced trees • H forward pointer for a node of height h • Each pointer i points to the next node with a height of at least i • Probabilistic time complexity log(N) for N nodes
Inserting in a Skip-List Inserting 17 in the list
Implementation • Two classes • Node • Represents an entry in the queue • SkipQueue • Contains the algorithm logic
Java Package Used • AtomicMarkableReference • In Java.util.concurrent.atomic • Stores • A reference to an object • A boolean flag • Provides ability to • Atomically set both the flag and reference • Compare and Swap (CAS) the flag and reference
Testing • Multi-threaded • 10 insert threads • Each inserting 100,000 objects with random integer keys • 10 delete threads • Each deleting while the queue is not empty • If the queue is empty, sleep for a bit and try again
Testing • Maintain a counter • Stores the number of nodes dequeued • When 1,000,000 nodes removed • Stop the delete threads • Check that • the queue is empty • removed exactly 1,000,000 nodes
Testing • 10 insert threads • Each inserting 100,000 random integer numbers • When all numbers have been inserted • Remove them one at a time. • Making sure the nodes come out sorted
Removing Atomicity • Do atomic references make a difference • i.e. does concurrency come into play, or are we just lucky • Replace each AtomicMarkableReference with a similar class • Same functions • But they are not atomic • The queue becomes locked after a small number of concurrent deletes.
Conclusion • Further testing is needed to verify the correctness of the implementation • Tests so far are positive • But cannot be certain there are no problems