Skip to content

Commit

Permalink
Store & ledger benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Aug 3, 2024
1 parent 134eca1 commit aec1d84
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nano/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(benchmarks entry.cpp stats.cpp)
add_executable(benchmarks entry.cpp ledger.cpp stats.cpp)

target_link_libraries(benchmarks test_common benchmark::benchmark)

Expand Down
103 changes: 103 additions & 0 deletions nano/benchmarks/ledger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <nano/lib/logging.hpp>
#include <nano/node/make_store.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_any.hpp>
#include <nano/secure/utility.hpp>
#include <nano/store/account.hpp>

#include <benchmark/benchmark.h>

// Expects live ledger in default location
// PLEASE NOTE: Make sure to purge disk cache between runs (`purge` command on macOS)
static void BM_ledger_iterate_accounts (benchmark::State & state)
{
nano::logger::initialize_dummy ();
nano::logger logger;
nano::stats stats{ logger };

// Use live ledger
nano::networks network = nano::networks::nano_live_network;
nano::network_params network_params{ network };
nano::node_config config{ network_params };
config.rocksdb_config.enable = state.range (0);
auto application_path = nano::working_path (network);

auto store_impl{ nano::make_store (logger, application_path, network_params.ledger, false, true, config.rocksdb_config, config.diagnostics_config.txn_tracking, config.block_processor_batch_max_time, config.lmdb_config, config.backup_before_upgrade) };
auto & store{ *store_impl };

if (store.init_error ())
{
state.SkipWithError ("Store initialization failed. Make sure ledger files are present in the default location.");
}

auto ledger_impl{ std::make_unique<nano::ledger> (store, stats, network_params.ledger, nano::generate_cache_flags::all_disabled (), config.representative_vote_weight_minimum.number ()) };
auto & ledger{ *ledger_impl };

auto transaction = ledger.tx_begin_read ();
nano::account current{ 0 };
nano::account_info current_info;
for (auto _ : state)
{
auto item = ledger.any.account_upper_bound (transaction, current.number ());
if (item != ledger.any.account_end ())
{
current = item->first;
current_info = item->second;
benchmark::DoNotOptimize (current);
benchmark::DoNotOptimize (current_info);
}
else
{
break;
}
}
}
BENCHMARK (BM_ledger_iterate_accounts)->ArgName ("use_rocksdb")->Arg (0)->Arg (1);

// Expects live ledger in default location
// PLEASE NOTE: Make sure to purge disk cache between runs (`purge` command on macOS)
static void BM_store_iterate_accounts (benchmark::State & state)
{
nano::logger::initialize_dummy ();
nano::logger logger;
nano::stats stats{ logger };

// Use live ledger
nano::networks network = nano::networks::nano_live_network;
nano::network_params network_params{ network };
nano::node_config config{ network_params };
config.rocksdb_config.enable = state.range (0);
nano::node_flags flags;
auto application_path = nano::working_path (network);

auto store_impl{ nano::make_store (logger, application_path, network_params.ledger, false, true, config.rocksdb_config, config.diagnostics_config.txn_tracking, config.block_processor_batch_max_time, config.lmdb_config, config.backup_before_upgrade, flags.force_use_write_queue) };
auto & store{ *store_impl };

if (store.init_error ())
{
state.SkipWithError ("Store initialization failed. Make sure ledger files are present in the default location.");
}

auto transaction = store.tx_begin_read ();
nano::account current{ 0 };
nano::account_info current_info;
auto i = store.account.begin (transaction);
for (auto _ : state)
{
if (i != store.account.end ())
{
current = i->first;
current_info = i->second;
benchmark::DoNotOptimize (current);
benchmark::DoNotOptimize (current_info);

++i;
}
else
{
break;
}
}
}
BENCHMARK (BM_store_iterate_accounts)->ArgName ("use_rocksdb")->Arg (0)->Arg (1);
12 changes: 12 additions & 0 deletions nano/secure/generate_cache_flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@ class generate_cache_flags
bool block_count = true;

void enable_all ();

public:
static generate_cache_flags all_disabled ()
{
generate_cache_flags flags;
flags.reps = false;
flags.cemented_count = false;
flags.unchecked_count = false;
flags.account_count = false;
flags.block_count = false;
return flags;
}
};
}
1 change: 1 addition & 0 deletions nano/store/lmdb/lmdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class component : public nano::store::component

public:
component (nano::logger &, std::filesystem::path const &, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), nano::lmdb_config const & lmdb_config_a = nano::lmdb_config{}, bool backup_before_upgrade = false);

store::write_transaction tx_begin_write (std::vector<nano::tables> const & tables_requiring_lock = {}, std::vector<nano::tables> const & tables_no_lock = {}) override;
store::read_transaction tx_begin_read () const override;

Expand Down

0 comments on commit aec1d84

Please sign in to comment.