Presentation is loading. Please wait.

Presentation is loading. Please wait.

November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.

Similar presentations


Presentation on theme: "November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg."— Presentation transcript:

1 November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg

2 November 15, 20071 Agenda Algorithm Review Algorithm Review Implementation Implementation Java Package used Java Package used Testing Testing Conclusion Conclusion Questions Questions

3 November 15, 20072 Algorithm Review Priority Queue Priority Queue Lock-free Lock-free Relies on atomic Compare and Swap operations Relies on atomic Compare and Swap operations

4 November 15, 20073 Algorithm Review The algorithm uses the Skip-List data structure The algorithm uses the Skip-List data structure Extends the Skip-List for concurrent use Extends the Skip-List for concurrent use The Skip-List is sorted on the priority of the nodes The Skip-List is sorted on the priority of the nodes The algorithm is lock-free The algorithm is lock-free No blocking No blocking Prevent dead locks Prevent dead locks Always progress by at least one operation Always progress by at least one operation Risk of starvation Risk of starvation

5 November 15, 20074 Algorithm Review Skip-List Multi-layer linked list Multi-layer linked list Probabilistic alternative to balanced trees Probabilistic alternative to balanced trees H forward pointer for a node of height h H forward pointer for a node of height h Each pointer i points to the next node with a height of at least i Each pointer i points to the next node with a height of at least i Probabilistic time complexity log(N) for N nodes Probabilistic time complexity log(N) for N nodes

6 November 15, 20075 Inserting in a Skip-List Inserting 17 in the list

7 November 15, 20076 Implementation Two classes Two classes Node Node Represents an entry in the queue Represents an entry in the queue SkipQueue SkipQueue Contains the algorithm logic Contains the algorithm logic

8 November 15, 20077 Node Class

9 November 15, 20078 SkipQueue Class

10 November 15, 20079 Java Package Used AtomicMarkableReference AtomicMarkableReference In Java.util.concurrent.atomic In Java.util.concurrent.atomic Stores Stores A reference to an object A reference to an object A boolean flag A boolean flag Provides ability to Provides ability to Atomically set both the flag and reference Atomically set both the flag and reference Compare and Swap (CAS) the flag and reference Compare and Swap (CAS) the flag and reference

11 November 15, 200710 Testing Multi-threaded Multi-threaded 10 insert threads 10 insert threads Each inserting 100,000 objects with random integer keys Each inserting 100,000 objects with random integer keys 10 delete threads 10 delete threads Each deleting while the queue is not empty Each deleting while the queue is not empty If the queue is empty, sleep for a bit and try again If the queue is empty, sleep for a bit and try again

12 November 15, 200711 Testing Maintain a counter Maintain a counter Stores the number of nodes dequeued Stores the number of nodes dequeued When 1,000,000 nodes removed When 1,000,000 nodes removed Stop the delete threads Stop the delete threads Check that Check that the queue is empty the queue is empty removed exactly 1,000,000 nodes removed exactly 1,000,000 nodes

13 November 15, 200712 Testing 10 insert threads 10 insert threads Each inserting 100,000 random integer numbers Each inserting 100,000 random integer numbers When all numbers have been inserted When all numbers have been inserted Remove them one at a time. Remove them one at a time. Making sure the nodes come out sorted Making sure the nodes come out sorted

14 November 15, 200713 Removing Atomicity Do atomic references make a difference Do atomic references make a difference i.e. does concurrency come into play, or are we just lucky i.e. does concurrency come into play, or are we just lucky Replace each AtomicMarkableReference with a similar class Replace each AtomicMarkableReference with a similar class Same functions Same functions But they are not atomic But they are not atomic The queue becomes locked after a small number of concurrent deletes. The queue becomes locked after a small number of concurrent deletes.

15 November 15, 200714 Conclusion Further testing is needed to verify the correctness of the implementation Further testing is needed to verify the correctness of the implementation Tests so far are positive Tests so far are positive But cannot be certain there are no problems But cannot be certain there are no problems

16 November 15, 2007 Questions


Download ppt "November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg."

Similar presentations


Ads by Google