-
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.
Rewrote the stack to support elimination & combining backoff strategies
Eliminaton cancels out opposite operations (push and pop). Combining merges similar operations (pushes) into a batch operation. Both use an arena to transfer elements between threads as a backoff strategy when the stack's top reference is contended (CAS failed). This greatly improves scalability by reducing the number of threads contending on a shared reference. The approach taken is much simpler than the previous EliminationStack or the DECS paper's algorithm. Both of the alternatives rely on multiple arena states to model different scenarios. In this version, the arena slot is either empty or full. The consumer may receive multiple elements and it mimics a producer after taking one of the elements for itself. This greatly simplifies the DECS algorithm, resulting in higher performance despite a penalty incurred by the consumer when producing.
- Loading branch information
Showing
16 changed files
with
989 additions
and
722 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,8 @@ | |
* @author [email protected] (Ben Manes) | ||
*/ | ||
@State(Scope.Group) | ||
public class EliminationStackBenchmark { | ||
@Param({"EliminationStack", "ConcurrentLinkedQueue", "ArrayBlockingQueue", | ||
"LinkedBlockingQueueBenchmark", "LinkedTransferQueue", "SynchronousQueue", | ||
"SynchronizedArrayDeque"}) | ||
public class ConcurrentLinkedStackBenchmark { | ||
@Param({"ConcurrentLinkedStack_linearizable", "ConcurrentLinkedQueue"}) | ||
QueueType queueType; | ||
|
||
Queue<Boolean> queue; | ||
|
@@ -44,23 +42,23 @@ public void setup() { | |
queue = queueType.create(); | ||
} | ||
|
||
@Benchmark @Group("no_contention") @GroupThreads(1) | ||
public void no_contention_offer() { | ||
@Benchmark @Group("low_contention") @GroupThreads(1) | ||
public void low_contention_offer() { | ||
queue.offer(Boolean.TRUE); | ||
} | ||
|
||
@Benchmark @Group("no_contention") @GroupThreads(1) | ||
public void no_contention_poll() { | ||
@Benchmark @Group("low_contention") @GroupThreads(1) | ||
public void low_contention_poll() { | ||
queue.poll(); | ||
} | ||
|
||
@Benchmark @Group("mild_contention") @GroupThreads(4) | ||
public void mild_contention_offer() { | ||
@Benchmark @Group("medium_contention") @GroupThreads(4) | ||
public void medium_contention_offer() { | ||
queue.offer(Boolean.TRUE); | ||
} | ||
|
||
@Benchmark @Group("mild_contention") @GroupThreads(4) | ||
public void mild_contention_poll() { | ||
@Benchmark @Group("medium_contention") @GroupThreads(4) | ||
public void medium_contention_poll() { | ||
queue.poll(); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -17,15 +17,15 @@ | |
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import com.github.benmanes.caffeine.EliminationStack; | ||
import com.github.benmanes.caffeine.ConcurrentLinkedStack; | ||
|
||
/** | ||
* @author Ben Manes ([email protected]) | ||
*/ | ||
public final class EliminationStackProfiler extends ProfilerHook { | ||
public final class ConcurrentLinkedStackProfiler extends ProfilerHook { | ||
static final Integer ELEMENT = 1; | ||
|
||
final EliminationStack<Integer> stack = new EliminationStack<>(); | ||
final ConcurrentLinkedStack<Integer> stack = ConcurrentLinkedStack.linearizable(); | ||
|
||
@Override | ||
protected void profile() { | ||
|
@@ -41,7 +41,7 @@ protected void profile() { | |
} | ||
|
||
public static void main(String[] args) { | ||
ProfilerHook profile = new EliminationStackProfiler(); | ||
ProfilerHook profile = new ConcurrentLinkedStackProfiler(); | ||
profile.run(); | ||
} | ||
} |
Oops, something went wrong.