Skip to content
Open
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
2 changes: 0 additions & 2 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ val nettyVersion = project.ext["nettyVersion"] as String
val assertjVersion = project.ext["assertjVersion"] as String
val lombokVersion = project.ext["lombokVersion"] as String
val jmhSdkVersion = project.ext["jmhVersion"] as String
val rocksdbVersion = project.ext["rocksdbVersion"] as String
val ehcacheVersion = project.ext["ehcacheVersion"] as String
val guavaVersion = project.ext["guavaVersion"] as String

Expand Down Expand Up @@ -66,7 +65,6 @@ dependencies {

implementation("org.openjdk.jmh:jmh-core:${jmhSdkVersion}")

implementation("org.rocksdb:rocksdbjni:${rocksdbVersion}")
implementation("org.ehcache:ehcache:${ehcacheVersion}")

implementation("org.assertj:assertj-core:${assertjVersion}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.corfudb.benchmarks.runtime.collections;

import org.apache.commons.lang3.RandomStringUtils;
import org.corfudb.benchmarks.runtime.collections.helper.CorfuTableBenchmarkHelper;
import org.corfudb.benchmarks.runtime.collections.state.RocksDbState.RocksDbStateForPut;
import org.openjdk.jmh.annotations.Benchmark;
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.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
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.rocksdb.RocksDB;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;

public class ExtensibleCacheBenchmark {
static {
RocksDB.loadLibrary();
}

public static final Path dbPath = Paths.get(
"/tmp",
"corfu",
"extensible_cache",
RandomStringUtils.randomAlphabetic(10)
);

public static void main(String[] args) throws RunnerException {
String benchmarkName = ExtensibleCacheBenchmark.class.getSimpleName();

Options opt = new OptionsBuilder()
.include(benchmarkName)
.shouldFailOnError(true)
.build();

new Runner(opt).run();
}

@Benchmark
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 1, time = 3)
@Measurement(iterations = 1, time = 3, timeUnit = TimeUnit.SECONDS)
@Threads(8)
@Fork(value = 1, jvmArgsAppend = {"-Xms4g", "-Xmx4g"})
public void put(RocksDbStateForPut state, Blackhole blackhole) {
CorfuTableBenchmarkHelper helper = state.getHelper();
Integer key = helper.generate();
helper.getCache().put(key, helper.generateValue());
String value = helper.getCache().get(key);
blackhole.consume(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import lombok.Builder.Default;
import lombok.Getter;
import lombok.NonNull;
import org.corfudb.common.util.ClassUtils;
import org.corfudb.runtime.collections.ICorfuTable;
import org.corfudb.runtime.collections.cache.ExtensibleCache;

import java.util.Map;
import java.util.Random;

/**
Expand All @@ -21,7 +19,7 @@ public class CorfuTableBenchmarkHelper {
private final Random random = new Random();

@NonNull
private final ICorfuTable<Integer, String> table;
private final ExtensibleCache<Integer, String> cache;

@NonNull
protected ValueGenerator valueGenerator;
Expand Down Expand Up @@ -49,7 +47,7 @@ public CorfuTableBenchmarkHelper fillTable() {
check();

for (int i = 0; i < getTableSize(); i++) {
table.insert(i, valueGenerator.value());
cache.put(i, valueGenerator.value());
}

return this;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,84 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.corfudb.benchmarks.runtime.collections.experiment.rocksdb.RocksDbMap;
import org.apache.commons.lang3.RandomStringUtils;
import org.corfudb.benchmarks.runtime.collections.ExtensibleCacheBenchmark;
import org.corfudb.benchmarks.runtime.collections.helper.CorfuTableBenchmarkHelper;
import org.corfudb.benchmarks.runtime.collections.helper.ValueGenerator.StaticValueGenerator;
import org.corfudb.benchmarks.util.SizeUnit;
import org.corfudb.runtime.CorfuRuntime;
import org.corfudb.runtime.collections.DiskBackedCorfuTable;
import org.corfudb.runtime.collections.ICorfuTable;
import org.corfudb.runtime.collections.PersistedCorfuTable;
import org.corfudb.runtime.collections.cache.ExtensibleCache;
import org.corfudb.runtime.object.PersistenceOptions;
import org.corfudb.runtime.object.RocksDbStore;
import org.corfudb.runtime.object.RocksDbStore.IndexMode;
import org.corfudb.runtime.object.RocksDbStore.StoreMode;
import org.corfudb.util.serializer.Serializers;
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.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.WriteOptions;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Supplier;

@Slf4j
public abstract class RocksDbState {
private static final String TMP_DIR = System.getProperty("java.io.tmpdir");

@Getter
CorfuRuntime corfuRuntime;
static {
RocksDB.loadLibrary();
}

@Getter
CorfuTableBenchmarkHelper helper;

private final String tableName = "DiskBackedTable";
ExtensibleCache<Integer, String> getCache() throws Exception {
PersistenceOptions persistenceOptions = PersistenceOptions.builder()
.dataPath(ExtensibleCacheBenchmark.dbPath)
.storeMode(StoreMode.PERSISTENT)
.indexMode(IndexMode.NON_INDEX)
.build();

private final Path dbPath = Paths.get(
FilenameUtils.getName(TMP_DIR), "corfu", "rt", "persistence", "rocks_db"
);
WriteOptions writeOptions = new WriteOptions()
.setDisableWAL(true)
.setSync(false);

RocksDbMap<Integer, String> getRocksDbMap() {
return RocksDbMap.<Integer, String>builder()
.dbPath(dbPath)
.keyType(Integer.class)
.valueType(String.class)
.build();
}
Options defaultOptions = new Options()
.setUseFsync(false)
.setCreateIfMissing(true);
RocksDbStore<DiskBackedCorfuTable<Integer, String>> rocksDbStore = new RocksDbStore<>(
defaultOptions, writeOptions, persistenceOptions
);

private void cleanDbDir() throws IOException {
File dbDir = dbPath.toFile();
FileUtils.deleteDirectory(dbDir);
FileUtils.forceMkdir(dbDir);
return new ExtensibleCache<>(rocksDbStore, Serializers.getDefaultSerializer());
}

void init(int dataSize, int tableSize) throws IOException, RocksDBException {
void init(int dataSize, int tableSize) throws Exception {
log.info("Initialization...");

cleanDbDir();
ExtensibleCache<Integer, String> cache = getCache();

PersistenceOptions.PersistenceOptionsBuilder persistenceOptions = PersistenceOptions.builder()
.dataPath(dbPath);
StaticValueGenerator valueGenerator = new StaticValueGenerator(dataSize);
ICorfuTable<Integer, String> table = corfuRuntime.getObjectsView().build()
.setTypeToken(PersistedCorfuTable.<Integer, String>getTypeToken())
.setArguments(persistenceOptions.build(), DiskBackedCorfuTable.defaultOptions, Serializers.PRIMITIVE)
.setStreamName(tableName)
.setSerializer(Serializers.PRIMITIVE)
.open();

helper = CorfuTableBenchmarkHelper.builder()
.valueGenerator(valueGenerator)
.table(table)
.cache(cache)
.dataSize(dataSize)
.tableSize(tableSize)
.build()
.check();
}

void stop() throws RocksDBException, IOException {
helper.getTable().close();
cleanDbDir();
void stop() throws Exception {
helper.getCache().close();
//cleanDbDir();
}

@State(Scope.Benchmark)
Expand All @@ -100,13 +98,13 @@ public static class RocksDbStateForGet extends RocksDbState {
protected int tableSize;

@Setup
public void init() throws IOException, RocksDBException {
public void init() throws Exception {
init(dataSize, tableSize);
helper.fillTable();
}

@TearDown
public void tearDown() throws RocksDBException, IOException {
public void tearDown() throws Exception {
stop();
}
}
Expand All @@ -115,7 +113,7 @@ public void tearDown() throws RocksDBException, IOException {
@State(Scope.Benchmark)
public static class RocksDbStateForPut extends RocksDbState {

@Param({"64", "256"})
@Param({"512", "1024", "4096"})
@Getter
public int dataSize;

Expand All @@ -126,12 +124,12 @@ public static class RocksDbStateForPut extends RocksDbState {
protected int tableSize = SizeUnit.HUNDRED_K.getValue();

@Setup
public void init() throws IOException, RocksDBException {
public void init() throws Exception {
init(dataSize, tableSize);
}

@TearDown
public void tearDown() throws IOException, RocksDBException {
public void tearDown() throws Exception {
stop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public Set<Entry<K, V>> entrySet() {
}

/**
* https://github.com/facebook/rocksdb/blob/master/include/rocksdb/db.h
* <a href="https://github.com/facebook/rocksdb/blob/master/include/rocksdb/db.h">Db stats</a>
*
* @return database statistics
* @throws RocksDBException db exception
Expand Down