Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

RocksDB Metrics #531

Merged
merged 4 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 ethereum/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
jmhImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
jmhImplementation project(':ethereum:rlp')
jmhImplementation project(':ethereum:trie')
jmhImplementation project(':metrics')
jmhImplementation project(':services:kvstore')
jmhImplementation project(':util')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tech.pegasys.pantheon.ethereum.core.ExecutionContextTestFixture;
import tech.pegasys.pantheon.ethereum.core.MessageFrameTestFixture;
import tech.pegasys.pantheon.ethereum.vm.MessageFrame;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import tech.pegasys.pantheon.util.uint.UInt256;
Expand Down Expand Up @@ -49,7 +50,8 @@ private OperationBenchmarkHelper(

public static OperationBenchmarkHelper create() throws IOException {
final Path storageDirectory = Files.createTempDirectory("benchmark");
final KeyValueStorage keyValueStorage = RocksDbKeyValueStorage.create(storageDirectory);
final KeyValueStorage keyValueStorage =
RocksDbKeyValueStorage.create(storageDirectory, new NoOpMetricsSystem());

final ExecutionContextTestFixture executionContext =
ExecutionContextTestFixture.builder().keyValueStorage(keyValueStorage).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.ethereum.storage.keyvalue;

import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;

Expand All @@ -22,8 +23,10 @@

public class RocksDbStorageProvider {

public static StorageProvider create(final Path databaseDir) throws IOException {
final KeyValueStorage kv = RocksDbKeyValueStorage.create(Files.createDirectories(databaseDir));
public static StorageProvider create(final Path databaseDir, final MetricsSystem metricsSystem)
throws IOException {
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(databaseDir), metricsSystem);
return new KeyValueStorageProvider(kv);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public enum MetricCategory {
PROCESS("process", false),
BLOCKCHAIN("blockchain"),
SYNCHRONIZER("synchronizer"),
NETWORK("network");
NETWORK("network"),
ROCKSDB("rocksdb");

private final String name;
private final boolean pantheonSpecific;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public PantheonController<?> build() throws IOException {
final KeyPair nodeKeys = loadKeyPair(nodePrivateKeyFile);

final StorageProvider storageProvider =
RocksDbStorageProvider.create(homePath.resolve(DATABASE_PATH));
RocksDbStorageProvider.create(homePath.resolve(DATABASE_PATH), metricsSystem);
if (devMode) {
final GenesisConfigFile genesisConfig = GenesisConfigFile.development();
return MainnetPantheonController.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception {
}

private StorageProvider createKeyValueStorageProvider(final Path dbAhead) throws IOException {
return RocksDbStorageProvider.create(dbAhead);
return RocksDbStorageProvider.create(dbAhead, new NoOpMetricsSystem());
}

private JsonRpcConfiguration jsonRpcConfiguration() {
Expand Down
1 change: 1 addition & 0 deletions services/kvstore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jar {

dependencies {
api project(':util')
implementation project(':metrics')

implementation 'org.apache.logging.log4j:log4j-api'
implementation 'com.google.guava:guava'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
package tech.pegasys.pantheon.services.kvstore;

import tech.pegasys.pantheon.metrics.Counter;
import tech.pegasys.pantheon.metrics.MetricCategory;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.OperationTimer;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.io.Closeable;
Expand Down Expand Up @@ -44,19 +48,45 @@ public class RocksDbKeyValueStorage implements KeyValueStorage, Closeable {
private final TransactionDB db;
private final AtomicBoolean closed = new AtomicBoolean(false);

private final OperationTimer readLatency;
private final OperationTimer removeLatency;
private final OperationTimer writeLatency;
private final OperationTimer commitLatency;
private final Counter rollbackCount;

static {
RocksDB.loadLibrary();
}

public static KeyValueStorage create(final Path storageDirectory) throws StorageException {
return new RocksDbKeyValueStorage(storageDirectory);
public static KeyValueStorage create(
final Path storageDirectory, final MetricsSystem metricsSystem) throws StorageException {
return new RocksDbKeyValueStorage(storageDirectory, metricsSystem);
}

private RocksDbKeyValueStorage(final Path storageDirectory) {
private RocksDbKeyValueStorage(final Path storageDirectory, final MetricsSystem metricsSystem) {
try {
options = new Options().setCreateIfMissing(true);
txOptions = new TransactionDBOptions();
db = TransactionDB.open(options, txOptions, storageDirectory.toString());

readLatency =
metricsSystem.createTimer(
MetricCategory.ROCKSDB, "read_latency_seconds", "Latency for read from RocksDB.");
removeLatency =
metricsSystem.createTimer(
MetricCategory.ROCKSDB,
"remove_latency_seconds",
"Latency of remove requests from RocksDB.");
writeLatency =
metricsSystem.createTimer(
MetricCategory.ROCKSDB, "write_latency_seconds", "Latency for write to RocksDB.");
commitLatency =
metricsSystem.createTimer(
MetricCategory.ROCKSDB, "commit_latency_seconds", "Latency for write to RocksDB.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description is incorrect, should be "for commit" not "for write"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


rollbackCount =
metricsSystem.createCounter(
MetricCategory.ROCKSDB, "rollback_count", "Number of transactions rolled back.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the description "Number of RocksDB transactions rolled back."? I know it will have rocksdb in the key as well but it would be easy to confuse this with number of EVM transactions rolled back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} catch (final RocksDBException e) {
throw new StorageException(e);
}
Expand All @@ -65,7 +95,8 @@ private RocksDbKeyValueStorage(final Path storageDirectory) {
@Override
public Optional<BytesValue> get(final BytesValue key) throws StorageException {
throwIfClosed();
try {

try (final OperationTimer.TimingContext ignored = readLatency.startTimer()) {
return Optional.ofNullable(db.get(key.extractArray())).map(BytesValue::wrap);
} catch (final RocksDBException e) {
throw new StorageException(e);
Expand Down Expand Up @@ -143,7 +174,7 @@ public Entry next() {
return entry;
}

public Stream<Entry> toStream() {
Stream<Entry> toStream() {
final Spliterator<Entry> split =
Spliterators.spliteratorUnknownSize(
this, Spliterator.IMMUTABLE | Spliterator.DISTINCT | Spliterator.NONNULL);
Expand All @@ -158,7 +189,7 @@ public void close() {
}
}

private static class RocksDbTransaction extends AbstractTransaction {
private class RocksDbTransaction extends AbstractTransaction {
private final org.rocksdb.Transaction innerTx;
private final WriteOptions options;

Expand All @@ -169,7 +200,7 @@ private static class RocksDbTransaction extends AbstractTransaction {

@Override
protected void doPut(final BytesValue key, final BytesValue value) {
try {
try (final OperationTimer.TimingContext ignored = writeLatency.startTimer()) {
innerTx.put(key.extractArray(), value.extractArray());
} catch (final RocksDBException e) {
throw new StorageException(e);
Expand All @@ -178,7 +209,7 @@ protected void doPut(final BytesValue key, final BytesValue value) {

@Override
protected void doRemove(final BytesValue key) {
try {
try (final OperationTimer.TimingContext ignored = removeLatency.startTimer()) {
innerTx.delete(key.extractArray());
} catch (final RocksDBException e) {
throw new StorageException(e);
Expand All @@ -187,7 +218,7 @@ protected void doRemove(final BytesValue key) {

@Override
protected void doCommit() throws StorageException {
try {
try (final OperationTimer.TimingContext ignored = commitLatency.startTimer()) {
innerTx.commit();
} catch (final RocksDBException e) {
throw new StorageException(e);
Expand All @@ -200,6 +231,7 @@ protected void doCommit() throws StorageException {
protected void doRollback() {
try {
innerTx.rollback();
rollbackCount.inc();
} catch (final RocksDBException e) {
throw new StorageException(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package tech.pegasys.pantheon.services.kvstore;

import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;

import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

Expand All @@ -21,6 +23,6 @@ public class RocksDbKeyValueStorageTest extends AbstractKeyValueStorageTest {

@Override
protected KeyValueStorage createStore() throws Exception {
return RocksDbKeyValueStorage.create(folder.newFolder().toPath());
return RocksDbKeyValueStorage.create(folder.newFolder().toPath(), new NoOpMetricsSystem());
}
}