-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tramchamploo
committed
Apr 13, 2018
1 parent
aa08a73
commit c38b0b1
Showing
28 changed files
with
4,647 additions
and
17 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
116 changes: 116 additions & 0 deletions
116
benchmark/src/main/java/io/github/tramchamploo/bufferslayer/AbstractBatchJedisBenchmark.java
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package io.github.tramchamploo.bufferslayer; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import org.openjdk.jmh.annotations.AuxCounters; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Group; | ||
import org.openjdk.jmh.annotations.GroupThreads; | ||
import org.openjdk.jmh.annotations.Level; | ||
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 redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.JedisPool; | ||
|
||
/** | ||
* Jedis benchmark that executing jedis commands. | ||
*/ | ||
public abstract class AbstractBatchJedisBenchmark { | ||
|
||
private JedisPool unbatch; | ||
private BatchJedis batch; | ||
private Reporter<RedisCommand, Object> reporter; | ||
private static SenderProxy<RedisCommand, Object> proxy; | ||
private static AtomicLong counter = new AtomicLong(); | ||
|
||
static String propertyOr(String key, String fallback) { | ||
return System.getProperty(key, fallback); | ||
} | ||
|
||
protected abstract Reporter<RedisCommand, Object> reporter(Sender<RedisCommand, Object> sender); | ||
|
||
@Setup | ||
public void setup() { | ||
unbatch = new JedisPool(propertyOr("redisHost", "127.0.0.1"), | ||
Integer.parseInt(propertyOr("redisPort", "6379"))); | ||
|
||
proxy = new SenderProxy<>(new JedisSender(unbatch)); | ||
proxy.onMessages(updated -> counter.addAndGet(updated.size())); | ||
|
||
reporter = reporter(proxy); | ||
batch = new BatchJedis(unbatch, reporter); | ||
} | ||
|
||
@TearDown(Level.Iteration) | ||
public void flushDB() { | ||
try (Jedis jedis = unbatch.getResource()) { | ||
jedis.flushDB(); | ||
} | ||
} | ||
|
||
@AuxCounters | ||
@State(Scope.Thread) | ||
public static class AtomicLongCounter { | ||
|
||
public long updated() { | ||
return counter.get(); | ||
} | ||
|
||
@Setup(Level.Iteration) | ||
public void clean() { | ||
counter.set(0); | ||
} | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
public static class Lagging { | ||
|
||
@Setup(Level.Iteration) | ||
public void lag() throws InterruptedException { | ||
TimeUnit.SECONDS.sleep(1); | ||
} | ||
} | ||
|
||
static String randomString() { | ||
return String.valueOf(ThreadLocalRandom.current().nextLong()); | ||
} | ||
|
||
@Benchmark @Group("no_contention_batched") @GroupThreads(1) | ||
public void no_contention_batched_set(Lagging l, AtomicLongCounter counters) { | ||
batch.set(randomString(), randomString()); | ||
} | ||
|
||
@Benchmark @Group("no_contention_unbatched") @GroupThreads(1) | ||
public void no_contention_unbatched_set(Lagging l) { | ||
try (Jedis jedis = unbatch.getResource()) { | ||
jedis.set(randomString(), randomString()); | ||
} | ||
} | ||
|
||
@Benchmark @Group("mild_contention_batched") @GroupThreads(2) | ||
public void mild_contention_batched_set(Lagging l, AtomicLongCounter counters) { | ||
batch.set(randomString(), randomString()); | ||
} | ||
|
||
@Benchmark @Group("mild_contention_unbatched") @GroupThreads(2) | ||
public void mild_contention_unbatched_set(Lagging l) { | ||
try (Jedis jedis = unbatch.getResource()) { | ||
jedis.set(randomString(), randomString()); | ||
} | ||
} | ||
|
||
@Benchmark @Group("high_contention_batched") @GroupThreads(8) | ||
public void high_contention_batched_set(Lagging l, AtomicLongCounter counters) { | ||
batch.set(randomString(), randomString()); | ||
} | ||
|
||
@Benchmark @Group("high_contention_unbatched") @GroupThreads(8) | ||
public void high_contention_unbatched_set(Lagging l) { | ||
try (Jedis jedis = unbatch.getResource()) { | ||
jedis.set(randomString(), randomString()); | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
benchmark/src/main/java/io/github/tramchamploo/bufferslayer/AsyncBatchJedisBenchmark.java
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.tramchamploo.bufferslayer; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
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; | ||
|
||
@Measurement(iterations = 5, time = 1) | ||
@Warmup(iterations = 3, time = 1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Group) | ||
public class AsyncBatchJedisBenchmark extends AbstractBatchJedisBenchmark { | ||
|
||
protected Reporter<RedisCommand, Object> reporter(Sender<RedisCommand, Object> sender) { | ||
return AsyncReporter.builder(sender) | ||
.pendingKeepalive(1, TimeUnit.SECONDS) | ||
.build(); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(".*" + AsyncBatchJedisBenchmark.class.getSimpleName() + ".*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
machine: | ||
java: | ||
version: oraclejdk8 | ||
services: | ||
- redis | ||
|
||
dependencies: | ||
pre: | ||
- openssl aes-256-cbc -d -in .buildscript/secret-env-cipher -k $KEY >> ~/.circlerc | ||
override: | ||
- mvn --fail-never dependency:go-offline || true | ||
cache_directories: | ||
- "~/.m2" | ||
|
||
test: | ||
post: | ||
- mkdir -p $CIRCLE_TEST_REPORTS/junit/ | ||
- find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; | ||
- .buildscript/release.sh |
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>bufferslayer-parent</artifactId> | ||
<groupId>io.github.tramchamploo</groupId> | ||
<version>1.4.4-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>bufferslayer-jedis</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>bufferslayer-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>bufferslayer-boundedqueue</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>redis.clients</groupId> | ||
<artifactId>jedis</artifactId> | ||
<version>2.9.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Oops, something went wrong.