This project is a Java-based benchmarking tool for evaluating the performance of different queue implementations.
The project includes the following interfaces:
The Queue
interface defines the basic operations for a queue, including:
try_push
: Attempts to add an element to the queue, if successful, returns true.try_pop
: Attempts to remove an element from the queue, if successful, returns the element.
The ConcurrentQueue
interface extends the Queue
interface, it does not provide additional methods but indicates that the queue is designed for concurrent access without blocking.
The BlockingQueue
interface extends the ConcurrentQueue
interface and provides additional methods for blocking operations:
wait_push
: Blocks until an element can be added to the queue.wait_pop
: Blocks until an element can be removed from the queue.
The QueueFactory
interface provides a method for creating instances of queues:
create
: Creates a new instance of a queue.
The ConcurrentQueueFactory
interface extends the QueueFactory
interface and specializes the create
method for creating concurrent queues.
The BlockingQueueFactory
interface extends the ConcurrentQueueFactory
interface and specializes the create
method for creating blocking queues.
The QueueFactoryDecorator
interface provides a method for creating decorated queue factories with additional functionality:
decorate
: Decorates a queue factory with additional functionality and returns a new instance of the decorated factory or null if the factory cannot be decorated.
The Bench
interface provides methods for running benchmarks on queue implementations:
run
: Runs the benchmark on the specified queue implementation and returns an array of results or null if the benchmark does not support the specified queue.
A wrapper around java.util.concurrent.ArrayBlockingQueue
that implements the BlockingQueue
interface.
A wrapper around java.util.ArrayDeque
that implements the Queue
interface.
A wrapper around java.util.concurrent.ConcurrentLinkedQueue
that implements the ConcurrentQueue
interface.
A wrapper around java.util.concurrent.LinkedBlockingQueue
that implements the BlockingQueue
interface.
A wrapper around java.util.LinkedList
that implements the Queue
interface.
A concurrent lock-free array-based queue implementation that implements the ConcurrentQueue
interface.
A linked list-based queue implementation that implements the Queue
interface.
A spinlock implementation, using a single AtomicBoolean
, that can be used to enhance queue operations with lock-free behavior.
A ticket lock implementation that can be used to enhance queue operations with lock-free behavior.
A synchronized decorator that provides thread-safe access to queue operations using Java's built-in synchronization mechanisms.
A lock decorator that provides thread-safe access to queue operations using Java's ReentrantLock
.
A lock decorator that provides thread-safe access to queue operations using Java's ReentrantLock
with two Condition
objects,
one to wait when the queue is full and the other to wait when the queue is empty.
A simple benchmark measuring the performance of queue operations in a single-threaded environment.
A benchmark with r+w
threads, where r
are readers and w
are writers.
It measures the performance of concurrent queue operations with backlogged readers and writers.
Analogous benchmarks is available for BackloggedBlockingBench(r,w)
.
A benchmark with w+1
threads.
w
threads are repeatedly writing to a blocking queue, while one thread is reading one element every 10us.
It measures the performance of each read operation.
Analogous benchmarks are available for BurstBlockingWriteBench(w)
, BurstConcurrentReadBench(r)
and BurstConcurrentWriteBench(w)
.
After looking at the benchmarks the following implementations have been observed delivering consistent good performance.
For basic single-threaded operations: java.util.ArrayDeque.
.
For concurrent non-blocking operations: java.util.concu.ConcurrentLinkedQueue
.
For blocking operations: java.util.concurrent.LinkedBlockingQueue
.