Skip to content

Commit

Permalink
Add combining arena to single consumer queue (closes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Apr 9, 2015
1 parent 610ea88 commit 8b64e61
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 186 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ compile 'com.github.ben-manes.caffeine:jcache:1.0.1'
compile 'com.github.ben-manes.caffeine:tracing-async:1.0.1'
```

Snapshots of the development version is available in
Snapshots of the development version are available in
[Sonatype's snapshots repository](https://oss.sonatype.org/content/repositories/snapshots).

### Cache: Features at a Glance
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ subprojects { proj ->
group = 'com.github.ben-manes.caffeine'
version.with {
major = 1 // incompatible API changes
minor = 0 // backwards-compatible additions
patch = 2 // backwards-compatible bug fixes
minor = 1 // backwards-compatible additions
patch = 0 // backwards-compatible bug fixes
releaseBuild = rootProject.hasProperty('release')
}
archivesBaseName = path[1..-1].replaceAll(':', '-').toLowerCase()
Expand Down
61 changes: 20 additions & 41 deletions caffeine/src/jmh/java/com/github/benmanes/caffeine/QueueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -70,6 +72,6 @@ public void high_contention_offer() {

@Benchmark @Group("high_contention") @GroupThreads(1)
public void high_contention_poll() {
queue.poll();
queue.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public final class CacheProfiler extends ProfilerHook {
static final int NUM_THREADS = 25;
static final int MAX_SIZE = 2 * NUM_THREADS;
static final CacheType type = CacheType.ConcurrentLinkedHashMap;
static final CacheType type = CacheType.Caffeine;

final Map<Long, Long> map;
final boolean reads;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 8b64e61

Please sign in to comment.