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);
}
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.");
}
Aggregations