diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 0baf5967..7b3ea84e 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -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 @@ -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}") diff --git a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/ExtensibleCacheBenchmark.java b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/ExtensibleCacheBenchmark.java new file mode 100644 index 00000000..dc60b0d9 --- /dev/null +++ b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/ExtensibleCacheBenchmark.java @@ -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); + } + +} diff --git a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/helper/CorfuTableBenchmarkHelper.java b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/helper/CorfuTableBenchmarkHelper.java index 978da84e..bad9df4e 100644 --- a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/helper/CorfuTableBenchmarkHelper.java +++ b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/helper/CorfuTableBenchmarkHelper.java @@ -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; /** @@ -21,7 +19,7 @@ public class CorfuTableBenchmarkHelper { private final Random random = new Random(); @NonNull - private final ICorfuTable table; + private final ExtensibleCache cache; @NonNull protected ValueGenerator valueGenerator; @@ -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; diff --git a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/HashMapState.java b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/HashMapState.java deleted file mode 100644 index cd5f7b54..00000000 --- a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/HashMapState.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.corfudb.benchmarks.runtime.collections.state; - -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -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.ICorfuTable; -import org.corfudb.runtime.collections.PersistedCorfuTable; -import org.corfudb.runtime.collections.PersistentCorfuTable; -import org.corfudb.util.serializer.ISerializer; -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; - - -@Slf4j -public abstract class HashMapState { - - @Getter - CorfuRuntime corfuRuntime; - - @Getter - CorfuTableBenchmarkHelper helper; - - private final String tableName = "InMemoryTable"; - - void init(int dataSize, int tableSize) { - log.info("Initialization..."); - - StaticValueGenerator valueGenerator = new StaticValueGenerator(dataSize); - ICorfuTable table = corfuRuntime.getObjectsView().build() - .setTypeToken(PersistentCorfuTable.getTypeToken()) - .setStreamName(tableName) - .setSerializer(Serializers.PRIMITIVE) - .open(); - - helper = CorfuTableBenchmarkHelper.builder() - .valueGenerator(valueGenerator) - .table(table) - .dataSize(dataSize) - .tableSize(tableSize) - .build() - .check(); - } - - @State(Scope.Benchmark) - @Getter - @Slf4j - public static class HashMapStateForGet extends HashMapState { - - @Param({"64", "256", "1024"}) - @Getter - public int dataSize; - - @Getter - @Param({"10000"}) - protected int inMemTableSize; - - @Setup - public void init() { - init(dataSize, inMemTableSize); - helper.fillTable(); - } - } - - @State(Scope.Benchmark) - @Slf4j - public static class HashMapStateForPut extends HashMapState { - - @Param({"64", "256"}) - @Getter - public int dataSize; - - @Getter - protected int tableSize = SizeUnit.HUNDRED_K.getValue(); - - @Setup - public void init() { - init(dataSize, tableSize); - } - } -} diff --git a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/RocksDbState.java b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/RocksDbState.java index 1dc1bc5e..aacd4128 100644 --- a/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/RocksDbState.java +++ b/benchmarks/src/jmh/java/org/corfudb/benchmarks/runtime/collections/state/RocksDbState.java @@ -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 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 getRocksDbMap() { - return RocksDbMap.builder() - .dbPath(dbPath) - .keyType(Integer.class) - .valueType(String.class) - .build(); - } + Options defaultOptions = new Options() + .setUseFsync(false) + .setCreateIfMissing(true); + RocksDbStore> 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 cache = getCache(); - PersistenceOptions.PersistenceOptionsBuilder persistenceOptions = PersistenceOptions.builder() - .dataPath(dbPath); StaticValueGenerator valueGenerator = new StaticValueGenerator(dataSize); - ICorfuTable table = corfuRuntime.getObjectsView().build() - .setTypeToken(PersistedCorfuTable.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) @@ -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(); } } @@ -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; @@ -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(); } } diff --git a/benchmarks/src/main/java/org/corfudb/benchmarks/runtime/collections/experiment/rocksdb/RocksDbMap.java b/benchmarks/src/main/java/org/corfudb/benchmarks/runtime/collections/experiment/rocksdb/RocksDbMap.java index 5df36155..16366f79 100644 --- a/benchmarks/src/main/java/org/corfudb/benchmarks/runtime/collections/experiment/rocksdb/RocksDbMap.java +++ b/benchmarks/src/main/java/org/corfudb/benchmarks/runtime/collections/experiment/rocksdb/RocksDbMap.java @@ -239,7 +239,7 @@ public Set> entrySet() { } /** - * https://github.com/facebook/rocksdb/blob/master/include/rocksdb/db.h + * Db stats * * @return database statistics * @throws RocksDBException db exception