Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {

api(project(":polaris-persistence-nosql-api"))
api(project(":polaris-persistence-nosql-impl"))
api(project(":polaris-persistence-nosql-benchmark"))
api(project(":polaris-persistence-nosql-standalone"))
api(project(":polaris-persistence-nosql-testextension"))

Expand Down
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ polaris-nodes-spi=persistence/nosql/nodes/spi
# persistence / database agnostic
polaris-persistence-nosql-api=persistence/nosql/persistence/api
polaris-persistence-nosql-impl=persistence/nosql/persistence/impl
polaris-persistence-nosql-benchmark=persistence/nosql/persistence/benchmark
polaris-persistence-nosql-standalone=persistence/nosql/persistence/standalone
polaris-persistence-nosql-testextension=persistence/nosql/persistence/testextension
polaris-persistence-nosql-varint=persistence/nosql/persistence/varint
Expand Down
41 changes: 41 additions & 0 deletions persistence/nosql/persistence/benchmark/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

Some container run commands...

```bash
podman run --rm -ti \
--name demo_mongo \
-p 27017:27017 \
docker.io/library/mongo:8.0.5
```

```bash
./gradlew :polaris-persistence-nosql-benchmark:jmhJar && java \
-Dpolaris.persistence.backend.type=InMemory \
-jar persistence/benchmark/build/libs/polaris-persistence-nosql-benchmark-1.0.0-incubating-SNAPSHOT-jmh.jar
```

```bash
./gradlew :polaris-persistence-nosql-benchmark:jmhJar && java \
-Dpolaris.persistence.backend.type=MongoDb \
-Dpolaris.persistence.backend.mongodb.connection-string=mongodb://localhost:27017/ \
-Dpolaris.persistence.backend.mongodb.database-name=test \
-jar persistence/benchmark/build/libs/polaris-persistence-nosql-benchmark-1.0.0-incubating-SNAPSHOT-jmh.jar
```
62 changes: 62 additions & 0 deletions persistence/nosql/persistence/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("polaris-server")
id("com.gradleup.shadow")
alias(libs.plugins.jmh)
}

description = "Polaris NoSQL persistence benchmarks, no production code"

dependencies {
implementation(project(":polaris-persistence-nosql-api"))
implementation(project(":polaris-persistence-nosql-impl"))
implementation(project(":polaris-persistence-nosql-standalone"))
implementation(project(":polaris-idgen-api"))
implementation(project(":polaris-idgen-impl"))
implementation(project(":polaris-idgen-spi"))

compileOnly(project(":polaris-immutables"))
annotationProcessor(project(":polaris-immutables", configuration = "processor"))

compileOnly(platform(libs.jackson.bom))
compileOnly("com.fasterxml.jackson.core:jackson-annotations")
compileOnly("com.fasterxml.jackson.core:jackson-databind")

compileOnly(libs.jakarta.annotation.api)
compileOnly(libs.jakarta.validation.api)

jmhImplementation(libs.jmh.core)
jmhAnnotationProcessor(libs.jmh.generator.annprocess)

jmhRuntimeOnly(project(":polaris-persistence-nosql-inmemory"))
jmhRuntimeOnly(testFixtures(project(":polaris-persistence-nosql-inmemory")))

jmhRuntimeOnly(project(":polaris-persistence-nosql-mongodb"))
jmhRuntimeOnly(testFixtures(project(":polaris-persistence-nosql-mongodb")))
}

tasks.named<ShadowJar>("jmhJar").configure {
outputs.cacheIf { false } // do not cache uber/shaded jars
mergeServiceFiles()
isZip64 = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.persistence.nosql.benchmark;

import static java.util.function.Function.identity;

import java.util.Map;
import org.apache.polaris.ids.api.MonotonicClock;
import org.apache.polaris.ids.impl.MonotonicClockImpl;
import org.apache.polaris.ids.impl.SnowflakeIdGeneratorFactory;
import org.apache.polaris.ids.spi.IdGeneratorSource;
import org.apache.polaris.persistence.nosql.api.Persistence;
import org.apache.polaris.persistence.nosql.api.PersistenceParams;
import org.apache.polaris.persistence.nosql.api.backend.Backend;
import org.apache.polaris.persistence.nosql.standalone.PersistenceConfigurer;

class BaseParam {
Backend backend;
Persistence persistence;
MonotonicClock clock;

void setupPersistence() {
var configurer = PersistenceConfigurer.defaultBackendConfigurer();
var factory = configurer.buildBackendFactory();
this.clock = MonotonicClockImpl.newDefaultInstance();
this.backend = configurer.buildBackendFromConfiguration(factory);
var info = backend.setupSchema().orElse("");
System.out.printf("Opened new persistence backend '%s' %s%n", backend.type(), info);

var idGenerator =
new SnowflakeIdGeneratorFactory()
.buildIdGenerator(
Map.of(),
new IdGeneratorSource() {
@Override
public int nodeId() {
return 42;
}

@Override
public long currentTimeMillis() {
return clock.currentTimeMillis();
}
});
this.persistence =
backend.newPersistence(
identity(),
PersistenceParams.BuildablePersistenceParams.builder().build(),
"42",
clock,
idGenerator);

// TODO allow caching
}

void shutdownPersistence() throws Exception {
if (clock != null) {
clock.close();
}
if (backend != null) {
backend.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.persistence.nosql.benchmark;

import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import java.util.Optional;
import org.apache.polaris.persistence.nosql.api.commit.RetryConfig;
import org.apache.polaris.persistence.nosql.api.commit.RetryTimeoutException;
import org.apache.polaris.persistence.nosql.impl.commits.CommitterWithStats;
import org.apache.polaris.persistence.nosql.impl.commits.retry.RetryStatsConsumer;
import org.openjdk.jmh.annotations.AuxCounters;
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.OutputTimeUnit;
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.annotations.Warmup;

@Warmup(iterations = 4, time = 1000, timeUnit = MILLISECONDS)
@Measurement(iterations = 10, time = 10_000, timeUnit = MILLISECONDS)
@Fork(1)
@Threads(4)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(MICROSECONDS)
public class CommitBenchmark {
@State(Scope.Benchmark)
public static class BenchmarkParam extends BaseParam {

RetryConfig retryConfig;

String refName;
CommitterWithStats<SimpleCommitTestObj, String> committer;

@Setup
public void init() {
setupPersistence();

refName = "commit-bench-" + System.currentTimeMillis();
persistence.createReference(refName, Optional.empty());

committer =
(CommitterWithStats<SimpleCommitTestObj, String>)
persistence.createCommitter(refName, SimpleCommitTestObj.class, String.class);
}

@TearDown
public void tearDown() throws Exception {
shutdownPersistence();
}
}

@State(Scope.Thread)
@AuxCounters(AuxCounters.Type.EVENTS)
public static class ThreadParam implements RetryStatsConsumer {
public int timeouts;
public int success;
public int retries;
public long retrySleepMillis;

String refName;
CommitterWithStats<SimpleCommitTestObj, String> committer;

@Setup(Level.Iteration)
public void clean() {
timeouts = 0;
success = 0;
}

@Setup
public void createBranch(BenchmarkParam param) {
refName =
"commit-bench-thread-"
+ System.currentTimeMillis()
+ "-"
+ Thread.currentThread().threadId();
param.persistence.createReference(refName, Optional.empty());
committer =
(CommitterWithStats<SimpleCommitTestObj, String>)
param.persistence.createCommitter(refName, SimpleCommitTestObj.class, String.class);
}

@Override
public void retryLoopFinished(
Result result, int retries, long sleepTimeMillis, long totalDurationNanos) {
switch (result) {
case SUCCESS:
success++;
break;
case TIMEOUT:
timeouts++;
break;
case CONFLICT:
case ERROR:
break;
}
this.retries += retries;
this.retrySleepMillis += sleepTimeMillis;
}
}

@Benchmark
public Optional<String> commitSingleRef(BenchmarkParam benchParam, ThreadParam threadParam)
throws Exception {
try {
return benchParam.committer.commit(
(state, refObjSupplier) -> {
var refObj = refObjSupplier.get();
return state.commitResult(
"fooo", ImmutableSimpleCommitTestObj.builder().payload("some payload"), refObj);
},
threadParam);
} catch (RetryTimeoutException e) {
return null;
}
}

@Benchmark
public Optional<String> commitDistinctRefs(ThreadParam threadParam) throws Exception {
try {
return threadParam.committer.commit(
(state, refObjSupplier) -> {
var refObj = refObjSupplier.get();
return state.commitResult(
"foo", ImmutableSimpleCommitTestObj.builder().payload("some payload"), refObj);
},
threadParam);
} catch (RetryTimeoutException e) {
return Optional.empty();
}
}
}
Loading