Skip to content

Commit

Permalink
Small benchmark updates (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest authored Dec 27, 2024
2 parents 561af9a + 5f29c84 commit 9d7565c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
25 changes: 24 additions & 1 deletion benchmarks/src/main/java/stormpot/benchmarks/ClaimRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@
package stormpot.benchmarks;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import stormpot.Expiration;
import stormpot.Pool;
import stormpot.PoolTap;
import stormpot.Timeout;

import java.util.concurrent.TimeUnit;

@Fork(jvmArgsAppend = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints"})
@Threads(12)
@State(Scope.Benchmark)
public class ClaimRelease {
Expand Down Expand Up @@ -56,10 +63,13 @@ public static class PerThread {
PoolTap<GenericPoolable> sequential;

@Setup
public void setUp(ClaimRelease bench) {
public void setUp(ClaimRelease bench) throws InterruptedException {
threadLocal = bench.pool.getThreadSafeTap();
vthreadSafe = bench.pool.getVirtualThreadSafeTap();
sequential = bench.pool.getSingleThreadedTap();
threadLocal.claim(timeout).release();
vthreadSafe.claim(timeout).release();
sequential.claim(timeout).release();
}
}

Expand All @@ -82,4 +92,17 @@ public void virtThreadSafe(PerThread state) throws InterruptedException {
public void sequential(PerThread state) throws InterruptedException {
state.sequential.claim(timeout).release();
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(ClaimRelease.class.getSimpleName())
.measurementTime(TimeValue.seconds(1))
.measurementIterations(10)
.warmupTime(TimeValue.seconds(1))
.warmupIterations(20)
// .forks(0) // For debugging.
.build();

new Runner(opt).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(ThreadTransfer.class.getSimpleName())
.measurementTime(TimeValue.seconds(1))
.measurementIterations(10)
.warmupTime(TimeValue.seconds(1))
.forks(0) // For debugging.
.warmupIterations(20)
// .forks(0) // For debugging.
.threads(4)
.build();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/stormpot/internal/BlazePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public PoolTap<T> getVirtualThreadSafeTap() {

@Override
public PoolTap<T> getSingleThreadedTap() {
return new BlazePoolSingleThreadedTap<>(this);
return new BlazePoolSingleThreadedTap<>(this, optimizeForMemory);
}

@Override
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/stormpot/internal/BlazePoolSingleThreadedTap.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@
*/
public final class BlazePoolSingleThreadedTap<T extends Poolable> implements PoolTap<T> {
private final BlazePool<T> pool;
private final BSlotCache<T> cache = new BSlotCache<>();
private final BSlotCache<T> cache;

/**
* Create a sequential (only usable by one thread at a time) tap for the given pool.
* @param pool The pool to tap from.
*
* @param pool The pool to tap from.
* @param optimizeForMemory {@code true} to optimise for lower memory usage,
* otherwise {@code false} to prioritize performance.
*/
public BlazePoolSingleThreadedTap(BlazePool<T> pool) {
public BlazePoolSingleThreadedTap(BlazePool<T> pool, boolean optimizeForMemory) {
this.pool = pool;
cache = optimizeForMemory ? new BSlotCache<>() : new BSlotCachePadded<>();
}

@Override
Expand Down

0 comments on commit 9d7565c

Please sign in to comment.