-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add combining arena to single consumer queue (closes #2)
- Loading branch information
Showing
12 changed files
with
337 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,53 +22,32 @@ | |
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.LinkedTransferQueue; | ||
import java.util.concurrent.SynchronousQueue; | ||
import java.util.function.Supplier; | ||
|
||
import com.google.common.collect.Queues; | ||
|
||
/** | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public enum QueueType { | ||
SingleConsumerQueue() { | ||
@Override public <E> Queue<E> create() { | ||
return new SingleConsumerQueue<E>(); | ||
} | ||
}, | ||
EliminationStack() { | ||
@Override public <E> Queue<E> create() { | ||
return new EliminationStack<E>().asLifoQueue(); | ||
} | ||
}, | ||
ConcurrentLinkedQueue() { | ||
@Override public <E> Queue<E> create() { | ||
return new ConcurrentLinkedQueue<E>(); | ||
} | ||
}, | ||
ArrayBlockingQueue() { | ||
@Override public <E> Queue<E> create() { | ||
return new ArrayBlockingQueue<E>(10000); | ||
} | ||
}, | ||
LinkedBlockingQueueBenchmark() { | ||
@Override public <E> Queue<E> create() { | ||
return new LinkedBlockingQueue<E>(); | ||
} | ||
}, | ||
LinkedTransferQueue() { | ||
@Override public <E> Queue<E> create() { | ||
return new LinkedTransferQueue<E>(); | ||
} | ||
}, | ||
SynchronousQueue() { | ||
@Override public <E> Queue<E> create() { | ||
return new SynchronousQueue<E>(); | ||
} | ||
}, | ||
SynchronizedArrayDeque() { | ||
@Override public <E> Queue<E> create() { | ||
return Queues.synchronizedDeque(new ArrayDeque<E>(10000)); | ||
} | ||
}; | ||
SingleConsumerQueue_optimistic(SingleConsumerQueue::optimistic), | ||
SingleConsumerQueue_linearizable(SingleConsumerQueue::linearizable), | ||
EliminationStack(() -> new EliminationStack<>().asLifoQueue()), | ||
ConcurrentLinkedQueue(ConcurrentLinkedQueue<Object>::new), | ||
ArrayBlockingQueue(() -> new ArrayBlockingQueue<>(10000)), | ||
LinkedBlockingQueueBenchmark(LinkedBlockingQueue<Object>::new), | ||
LinkedTransferQueue(LinkedTransferQueue<Object>::new), | ||
SynchronousQueue(SynchronousQueue<Object>::new), | ||
SynchronizedArrayDeque(() -> Queues.synchronizedDeque(new ArrayDeque<>(10000))); | ||
|
||
public abstract <E> Queue<E> create(); | ||
private final Supplier<Queue<Object>> factory; | ||
|
||
private QueueType(Supplier<Queue<Object>> factory) { | ||
this.factory = factory; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <E> Queue<E> create() { | ||
return (Queue<E>) factory.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,10 @@ | |
* @author [email protected] (Ben Manes) | ||
*/ | ||
@State(Scope.Group) | ||
public class SingleConsumerBenchmark { | ||
@Param({"SingleConsumerQueue", "ConcurrentLinkedQueue"}) | ||
public class SingleConsumerQueueBenchmark { | ||
@Param({"SingleConsumerQueue_optimistic", | ||
"SingleConsumerQueue_linearizable", | ||
"ConcurrentLinkedQueue"}) | ||
QueueType queueType; | ||
|
||
Queue<Boolean> queue; | ||
|
@@ -53,7 +55,7 @@ public void no_contention_poll() { | |
queue.poll(); | ||
} | ||
|
||
@Benchmark @Group("mild_contention") @GroupThreads(4) | ||
@Benchmark @Group("mild_contention") @GroupThreads(2) | ||
public void mild_contention_offer() { | ||
queue.offer(Boolean.TRUE); | ||
} | ||
|
@@ -70,6 +72,6 @@ public void high_contention_offer() { | |
|
||
@Benchmark @Group("high_contention") @GroupThreads(1) | ||
public void high_contention_poll() { | ||
queue.poll(); | ||
queue.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,6 @@ | |
* results if this collection is modified during traversal. | ||
* | ||
* @author [email protected] (Ben Manes) | ||
* @see <a href="https://github.com/ben-manes/caffeine">Caffeine</a> | ||
* @param <E> the type of elements held in this collection | ||
*/ | ||
@Beta | ||
|
Oops, something went wrong.