Search in sources :

Example 1 with RocksDBKeyValueStorage

use of org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage in project besu by hyperledger.

the class OperationBenchmarkHelper method create.

public static OperationBenchmarkHelper create() throws IOException {
    final Path storageDirectory = Files.createTempDirectory("benchmark");
    final KeyValueStorage keyValueStorage = new RocksDBKeyValueStorage(new RocksDBConfigurationBuilder().databaseDir(storageDirectory).build(), new NoOpMetricsSystem(), RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
    final ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.builder().keyValueStorage(keyValueStorage).build();
    final MutableBlockchain blockchain = executionContext.getBlockchain();
    for (int i = 1; i < 256; i++) {
        blockchain.appendBlock(new Block(new BlockHeaderTestFixture().parentHash(blockchain.getChainHeadHash()).number(i).difficulty(Difficulty.ONE).buildHeader(), new BlockBody(emptyList(), emptyList())), emptyList());
    }
    final MessageFrame messageFrame = new MessageFrameTestFixture().executionContextTestFixture(executionContext).blockHeader(new BlockHeaderTestFixture().parentHash(blockchain.getChainHeadHash()).number(blockchain.getChainHeadBlockNumber() + 1).difficulty(Difficulty.ONE).buildHeader()).build();
    return new OperationBenchmarkHelper(storageDirectory, keyValueStorage, messageFrame, blockchain);
}
Also used : Path(java.nio.file.Path) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) RocksDBKeyValueStorage(org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage) KeyValueStorage(org.hyperledger.besu.plugin.services.storage.KeyValueStorage) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) RocksDBKeyValueStorage(org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage) RocksDBConfigurationBuilder(org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfigurationBuilder) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain)

Example 2 with RocksDBKeyValueStorage

use of org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage in project besu by hyperledger.

the class RocksDBKeyValueStorageTest method createStoreMustCreateMetrics.

@Test
public void createStoreMustCreateMetrics() throws Exception {
    // Prepare mocks
    when(labelledMetricOperationTimerMock.labels(any())).thenReturn(operationTimerMock);
    when(metricsSystemMock.createLabelledTimer(eq(BesuMetricCategory.KVSTORE_ROCKSDB), anyString(), anyString(), any())).thenReturn(labelledMetricOperationTimerMock);
    when(metricsSystemMock.createLabelledCounter(eq(BesuMetricCategory.KVSTORE_ROCKSDB), anyString(), anyString(), any())).thenReturn(labelledMetricCounterMock);
    // Prepare argument captors
    final ArgumentCaptor<String> labelledTimersMetricsNameArgs = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> labelledTimersHelpArgs = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> labelledCountersMetricsNameArgs = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> labelledCountersHelpArgs = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> longGaugesMetricsNameArgs = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> longGaugesHelpArgs = ArgumentCaptor.forClass(String.class);
    // Actual call
    final KeyValueStorage keyValueStorage = new RocksDBKeyValueStorage(config(), metricsSystemMock, RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
    // Assertions
    assertThat(keyValueStorage).isNotNull();
    verify(metricsSystemMock, times(4)).createLabelledTimer(eq(BesuMetricCategory.KVSTORE_ROCKSDB), labelledTimersMetricsNameArgs.capture(), labelledTimersHelpArgs.capture(), any());
    assertThat(labelledTimersMetricsNameArgs.getAllValues()).containsExactly("read_latency_seconds", "remove_latency_seconds", "write_latency_seconds", "commit_latency_seconds");
    assertThat(labelledTimersHelpArgs.getAllValues()).containsExactly("Latency for read from RocksDB.", "Latency of remove requests from RocksDB.", "Latency for write to RocksDB.", "Latency for commits to RocksDB.");
    verify(metricsSystemMock, times(2)).createLongGauge(eq(BesuMetricCategory.KVSTORE_ROCKSDB), longGaugesMetricsNameArgs.capture(), longGaugesHelpArgs.capture(), any(LongSupplier.class));
    assertThat(longGaugesMetricsNameArgs.getAllValues()).containsExactly("rocks_db_table_readers_memory_bytes", "rocks_db_files_size_bytes");
    assertThat(longGaugesHelpArgs.getAllValues()).containsExactly("Estimated memory used for RocksDB index and filter blocks in bytes", "Estimated database size in bytes");
    verify(metricsSystemMock).createLabelledCounter(eq(BesuMetricCategory.KVSTORE_ROCKSDB), labelledCountersMetricsNameArgs.capture(), labelledCountersHelpArgs.capture(), any());
    assertThat(labelledCountersMetricsNameArgs.getValue()).isEqualTo("rollback_count");
    assertThat(labelledCountersHelpArgs.getValue()).isEqualTo("Number of RocksDB transactions rolled back.");
}
Also used : RocksDBKeyValueStorage(org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage) KeyValueStorage(org.hyperledger.besu.plugin.services.storage.KeyValueStorage) RocksDBKeyValueStorage(org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LongSupplier(java.util.function.LongSupplier) AbstractKeyValueStorageTest(org.hyperledger.besu.kvstore.AbstractKeyValueStorageTest) Test(org.junit.Test)

Aggregations

KeyValueStorage (org.hyperledger.besu.plugin.services.storage.KeyValueStorage)2 RocksDBKeyValueStorage (org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage)2 Path (java.nio.file.Path)1 LongSupplier (java.util.function.LongSupplier)1 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)1 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)1 ExecutionContextTestFixture (org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture)1 MessageFrameTestFixture (org.hyperledger.besu.ethereum.core.MessageFrameTestFixture)1 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)1 AbstractKeyValueStorageTest (org.hyperledger.besu.kvstore.AbstractKeyValueStorageTest)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 RocksDBConfigurationBuilder (org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfigurationBuilder)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1