-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some benchmarks for Tarantool cluster with proxy client
The new benchmark tries to measure the following things: - cost of allocating a new space object for the proxy client - cost of writing data to two different spaces (with different mappers) - cost of reading data from two different spaces (with diferent mappers) To get some useful results for memory profiling run this benchmark as follows: mvn exec:exec -Pbenchmark -Dbenchmark="ClusterBenchmarkRunner" -DbenchmarkArgs="-prof=jfr" To analyze these results use the JMC plug-in for Eclipse. You may use the other profiler types and pass additional arguments to the JMC tool.
- Loading branch information
Showing
5 changed files
with
236 additions
and
15 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
134 changes: 134 additions & 0 deletions
134
src/test/java/io/tarantool/driver/benchmark/ClusterBenchmarkRunner.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,134 @@ | ||
package io.tarantool.driver.benchmark; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import io.tarantool.driver.api.TarantoolResult; | ||
import io.tarantool.driver.api.conditions.Conditions; | ||
import io.tarantool.driver.api.space.TarantoolSpaceOperations; | ||
import io.tarantool.driver.api.tuple.TarantoolTuple; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Fork(value = 1, jvmArgsAppend = "-Xmx1G") | ||
public class ClusterBenchmarkRunner { | ||
private static final String TEST_SPACE = "test_space"; | ||
private static final String TEST_PROFILE = "test__profile"; | ||
|
||
public static void main(String[] args) throws Exception { | ||
org.openjdk.jmh.Main.main(args); | ||
} | ||
|
||
@Benchmark | ||
@Measurement(iterations = 10) | ||
@OperationsPerInvocation(2) | ||
public void getSpaceObject(ClusterTarantoolSetup plan, Blackhole bh) { | ||
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> testSpace = | ||
plan.tarantoolClient.space(TEST_SPACE); | ||
bh.consume(testSpace); | ||
|
||
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace = | ||
plan.tarantoolClient.space(TEST_PROFILE); | ||
bh.consume(profileSpace); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@Measurement(iterations = 10) | ||
@OperationsPerInvocation(2000) | ||
public void writeData(ClusterTarantoolSetup plan, FuturesHolder futuresHolder, Spaces spaces, Blackhole bh) { | ||
// Fill 10000 rows into both spaces | ||
TarantoolTuple tarantoolTuple; | ||
String uuid; | ||
int nextId = 0; | ||
for (int i = 0; i < 1_000; i++) { | ||
uuid = UUID.randomUUID().toString(); | ||
nextId = plan.nextTestSpaceId + i; | ||
tarantoolTuple = plan.tupleFactory.create(1_000_000 + nextId, null, uuid, 200_000 + nextId); | ||
futuresHolder.allFutures.add(spaces.testSpace.insert(tarantoolTuple)); | ||
tarantoolTuple = plan.tupleFactory.create(1_000_000 + nextId, null, uuid, 50_000 + nextId, 100_000 + i); | ||
futuresHolder.allFutures.add(spaces.profileSpace.insert(tarantoolTuple)); | ||
} | ||
nextId++; | ||
plan.nextTestSpaceId = nextId; | ||
plan.nextProfileSpaceId = nextId; | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@Measurement(iterations = 10) | ||
@OperationsPerInvocation(1000) | ||
public void readDataUsingCallAPI(ClusterTarantoolSetup plan, FuturesHolder futuresHolder, Blackhole bh) { | ||
boolean coin = Math.random() - 0.5 > 0; | ||
String spaceName = coin ? TEST_SPACE : TEST_PROFILE; | ||
long nextId; | ||
for (int i = 0; i < 1_000; i++) { | ||
nextId = Math.round(Math.random() * 10_000) + 1_000_000; | ||
futuresHolder.allFutures.add( | ||
plan.tarantoolClient.callForSingleResult( | ||
"custom_crud_get_one_record", Arrays.asList(spaceName, nextId), List.class) | ||
); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@Measurement(iterations = 10) | ||
@OperationsPerInvocation(1000) | ||
public void readDataUsingSpaceAPI( | ||
ClusterTarantoolSetup plan, FuturesHolder futuresHolder, Spaces spaces, Blackhole bh) { | ||
boolean coin = Math.random() - 0.5 > 0; | ||
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> space = coin ? | ||
spaces.testSpace : spaces.profileSpace; | ||
String pkFieldName = coin ? "id" : "profile_id"; | ||
long nextId; | ||
for (int i = 0; i < 1_000; i++) { | ||
nextId = Math.round(Math.random() * 10_000) + 1_000_000; | ||
futuresHolder.allFutures.add( | ||
space.select(Conditions.indexEquals(pkFieldName, Collections.singletonList(nextId))) | ||
); | ||
} | ||
} | ||
|
||
@State(Scope.Thread) | ||
public static class FuturesHolder { | ||
final List<CompletableFuture<?>> allFutures = new ArrayList<>(2_000); | ||
|
||
@Setup(Level.Invocation) | ||
public void doSetup() { | ||
allFutures.clear(); | ||
} | ||
|
||
@TearDown(Level.Invocation) | ||
public void doTeardown() { | ||
allFutures.forEach(CompletableFuture::join); | ||
} | ||
} | ||
|
||
@State(Scope.Thread) | ||
public static class Spaces { | ||
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> testSpace; | ||
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace; | ||
|
||
@Setup(Level.Iteration) | ||
public void doSetup(ClusterTarantoolSetup plan) { | ||
testSpace = plan.tarantoolClient.space(TEST_SPACE); | ||
profileSpace = plan.tarantoolClient.space(TEST_PROFILE); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/test/java/io/tarantool/driver/benchmark/ClusterTarantoolSetup.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,80 @@ | ||
package io.tarantool.driver.benchmark; | ||
|
||
import java.time.Duration; | ||
|
||
import io.tarantool.driver.api.TarantoolClient; | ||
import io.tarantool.driver.api.TarantoolClientFactory; | ||
import io.tarantool.driver.api.TarantoolResult; | ||
import io.tarantool.driver.api.TarantoolServerAddress; | ||
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory; | ||
import io.tarantool.driver.api.tuple.TarantoolTuple; | ||
import io.tarantool.driver.api.tuple.TarantoolTupleFactory; | ||
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; | ||
import io.tarantool.driver.mappers.MessagePackMapper; | ||
|
||
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 org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.TarantoolCartridgeContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
@State(Scope.Benchmark) | ||
public class ClusterTarantoolSetup { | ||
public Logger logger = LoggerFactory.getLogger(ClusterTarantoolSetup.class); | ||
|
||
final MessagePackMapper defaultMapper = | ||
DefaultMessagePackMapperFactory.getInstance().defaultComplexTypesMapper(); | ||
final TarantoolTupleFactory tupleFactory = new DefaultTarantoolTupleFactory(defaultMapper); | ||
|
||
final TarantoolCartridgeContainer tarantoolContainer = | ||
new TarantoolCartridgeContainer( | ||
"Dockerfile", | ||
"cartridge-java-test", | ||
"cartridge/instances.yml", | ||
"cartridge/topology.lua") | ||
.withDirectoryBinding("cartridge") | ||
.withLogConsumer(new Slf4jLogConsumer(logger)) | ||
.waitingFor(Wait.forLogMessage(".*Listening HTTP on.*", 5)) | ||
.withStartupTimeout(Duration.ofMinutes(2)); | ||
|
||
TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> tarantoolClient; | ||
|
||
int nextTestSpaceId; | ||
int nextProfileSpaceId; | ||
|
||
private void initClient() { | ||
tarantoolClient = TarantoolClientFactory.createClient() | ||
.withAddresses( | ||
new TarantoolServerAddress(tarantoolContainer.getRouterHost(), tarantoolContainer.getMappedPort(3301)), | ||
new TarantoolServerAddress(tarantoolContainer.getRouterHost(), tarantoolContainer.getMappedPort(3302)), | ||
new TarantoolServerAddress(tarantoolContainer.getRouterHost(), tarantoolContainer.getMappedPort(3303)) | ||
) | ||
.withCredentials(tarantoolContainer.getUsername(), tarantoolContainer.getPassword()) | ||
.withConnections(10) | ||
.withEventLoopThreadsNumber(10) | ||
.withRequestTimeout(10000) | ||
.withProxyMethodMapping() | ||
.build(); | ||
} | ||
|
||
@Setup(Level.Trial) | ||
public void doSetup() { | ||
System.out.println("Do Setup"); | ||
if (!tarantoolContainer.isRunning()) { | ||
tarantoolContainer.start(); | ||
} | ||
initClient(); | ||
} | ||
|
||
@TearDown(Level.Trial) | ||
public void doTearDown() throws Exception { | ||
System.out.println("Do TearDown"); | ||
tarantoolClient.close(); | ||
tarantoolContainer.close(); | ||
} | ||
} |
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