diff --git a/nano/benchmarks/CMakeLists.txt b/nano/benchmarks/CMakeLists.txt index dc3829303d..94a3e64f21 100644 --- a/nano/benchmarks/CMakeLists.txt +++ b/nano/benchmarks/CMakeLists.txt @@ -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) diff --git a/nano/benchmarks/ledger.cpp b/nano/benchmarks/ledger.cpp new file mode 100644 index 0000000000..dfe608f56d --- /dev/null +++ b/nano/benchmarks/ledger.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +// 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 (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); \ No newline at end of file diff --git a/nano/secure/generate_cache_flags.hpp b/nano/secure/generate_cache_flags.hpp index 29445e53d8..f3d832d70d 100644 --- a/nano/secure/generate_cache_flags.hpp +++ b/nano/secure/generate_cache_flags.hpp @@ -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; + } }; } diff --git a/nano/store/lmdb/lmdb.hpp b/nano/store/lmdb/lmdb.hpp index 8cf9d94bc3..3a87154695 100644 --- a/nano/store/lmdb/lmdb.hpp +++ b/nano/store/lmdb/lmdb.hpp @@ -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 const & tables_requiring_lock = {}, std::vector const & tables_no_lock = {}) override; store::read_transaction tx_begin_read () const override;