From d4366d3f18a6766eec9223e1d1c08dff87d3bab8 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 10 Apr 2025 22:42:38 +0400 Subject: [PATCH] added some diagnostic logs for blockchain caching --- contrib/epee/include/cache_helper.h | 15 ++++-- src/common/db_abstract_accessor.h | 5 ++ src/currency_core/blockchain_storage.cpp | 44 +++++++++++------- src/currency_core/blockchain_storage.h | 2 + src/daemon/daemon_commands_handler.h | 9 ++++ utils/test_api_files/@get_blocks_response.bin | Bin 0 -> 69 bytes utils/test_api_files/exec_get_blocks_bin.bat | 9 ++++ utils/test_api_files/get_blocks.bin | Bin 0 -> 943 bytes 8 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 utils/test_api_files/@get_blocks_response.bin create mode 100644 utils/test_api_files/exec_get_blocks_bin.bat create mode 100644 utils/test_api_files/get_blocks.bin diff --git a/contrib/epee/include/cache_helper.h b/contrib/epee/include/cache_helper.h index dd3bb883..416b58bd 100644 --- a/contrib/epee/include/cache_helper.h +++ b/contrib/epee/include/cache_helper.h @@ -60,14 +60,14 @@ namespace epee template class cache_base { - uint64_t mac_allowed_elements; + uint64_t max_allowed_elements; std::list most_recet_acessed; typename container_selector::iterator> >::container data; protected: critical_section m_lock; public: - cache_base() : mac_allowed_elements(max_elements) + cache_base() : max_allowed_elements(max_elements) {} size_t size() const @@ -76,14 +76,19 @@ namespace epee return data.size(); } + size_t most_recent_accessed_container_size() const + { + return most_recet_acessed.size(); + } + uint64_t get_max_elements() const { - return mac_allowed_elements; + return max_allowed_elements; } void set_max_elements(uint64_t e) { - mac_allowed_elements = e; + max_allowed_elements = e; } bool get(const t_key& k, t_value& v) @@ -130,7 +135,7 @@ namespace epee void trim() { CRITICAL_REGION_LOCAL(m_lock); - while (most_recet_acessed.size() > mac_allowed_elements) + while (most_recet_acessed.size() > max_allowed_elements) { auto data_it = data.find(most_recet_acessed.back()); if (data_it != data.end()) diff --git a/src/common/db_abstract_accessor.h b/src/common/db_abstract_accessor.h index b26c4961..b5fefad4 100644 --- a/src/common/db_abstract_accessor.h +++ b/src/common/db_abstract_accessor.h @@ -761,6 +761,11 @@ namespace tools NESTED_CATCH_ENTRY(__func__); } + const cache_container_type& get_cache_obj() const + { + return m_cache; + } + void clear_cache() const { m_cache.clear(); diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 302661df..cb28dcdf 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -220,7 +220,30 @@ void blockchain_storage::set_db_l2_cache_size(uint64_t ceched_elements) const m_db_assets.set_cache_size(ceched_elements); m_db_addr_to_alias.set_cache_size(ceched_elements); } +//------------------------------------------------------------------ +std::string blockchain_storage::get_db_l2_cache_state_str() const +{ + std::stringstream ss; +#define PRINT_CACHE_STATE(db_name) ss << #db_name ":[" << tools::pretty_print_big_nums(db_name.get_cache_obj().size()) << "/" << tools::pretty_print_big_nums(db_name.get_cache_obj().most_recent_accessed_container_size()) << "] " << (db_name.get_cache_obj().size() * 100) / db_name.get_cache_size() << "%" << ENDL; + PRINT_CACHE_STATE(m_db_blocks_index); + PRINT_CACHE_STATE(m_db_blocks); + PRINT_CACHE_STATE(m_db_blocks_index); + PRINT_CACHE_STATE(m_db_transactions); + PRINT_CACHE_STATE(m_db_spent_keys); + PRINT_CACHE_STATE(m_db_multisig_outs); + PRINT_CACHE_STATE(m_db_solo_options); + PRINT_CACHE_STATE(m_db_aliases); + PRINT_CACHE_STATE(m_db_assets); + PRINT_CACHE_STATE(m_db_addr_to_alias); + return ss.str(); +} +//------------------------------------------------------------------ +void blockchain_storage::print_db_l2_cache_state() const +{ + LOG_PRINT_MAGENTA("CACHE STATE (L2):" << ENDL << get_db_l2_cache_state_str(), LOG_LEVEL_0); +} +//------------------------------------------------------------------ void remove_old_db(const std::string old_db_folder_path) { try { @@ -235,8 +258,7 @@ void remove_old_db(const std::string old_db_folder_path) } } - - +//------------------------------------------------------------------ bool blockchain_storage::init(const std::string& config_folder, const boost::program_options::variables_map& vm) { // CRITICAL_REGION_LOCAL(m_read_lock); @@ -5438,23 +5460,11 @@ void blockchain_storage::do_full_db_warm_up() const { ticks_last_print = epee::misc_utils::get_tick_count(); LOG_PRINT_CYAN("Warming up: " << ( ( (i) * 100)/ current_sz) << "%, " << (i) << " of " << current_sz, LOG_LEVEL_0); - -#define PRINT_CONTAINER(cont_name) strm << #cont_name"[" << cont_name.get_cache_size() << "]:" << (cont_name.get_cacheed_items_count() * 100) / cont_name.get_cache_size() << " %, items: " << cont_name.get_cacheed_items_count() << ENDL - - std::stringstream strm; - PRINT_CONTAINER(m_db_blocks_index); - PRINT_CONTAINER(m_db_blocks); - PRINT_CONTAINER(m_db_blocks_index); - PRINT_CONTAINER(m_db_transactions); - PRINT_CONTAINER(m_db_spent_keys); - PRINT_CONTAINER(m_db_multisig_outs); - PRINT_CONTAINER(m_db_solo_options); - PRINT_CONTAINER(m_db_aliases); - PRINT_CONTAINER(m_db_assets); - PRINT_CONTAINER(m_db_addr_to_alias); - LOG_PRINT_CYAN("CACHE STATE: " << ENDL << strm.str(), LOG_LEVEL_2); + + LOG_PRINT_CYAN("CACHE STATE: " << ENDL << get_db_l2_cache_state_str(), LOG_LEVEL_2); } } + LOG_PRINT_CYAN("CACHE STATE: " << ENDL << get_db_l2_cache_state_str(), LOG_LEVEL_0); } //------------------------------------------------------------------ void blockchain_storage::on_hardfork_activated(size_t hardfork_id) diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index b0407fd9..efa31508 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -516,6 +516,8 @@ namespace currency //experimental void do_full_db_warm_up() const; void on_hardfork_activated(size_t hardfork_id); + void print_db_l2_cache_state() const; + std::string get_db_l2_cache_state_str() const; private: diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index cab2be2b..f9e7edc3 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -80,6 +80,7 @@ public: m_cmd_binder.set_handler("print_difficulties_of_last_n_blocks", boost::bind(&daemon_commands_handler::print_difficulties_of_last_n_blocks, this, ph::_1), "Print difficulties of last n blocks"); m_cmd_binder.set_handler("debug_remote_node_mode", boost::bind(&daemon_commands_handler::debug_remote_node_mode, this, ph::_1), " - If node got connected put node into 'debug mode' i.e. no sync process of other communication except ping responses, maintenance secrete key will be requested"); m_cmd_binder.set_handler("full_db_cache_warmup", boost::bind(&daemon_commands_handler::full_db_cache_warmup, this, ph::_1), "(Experimental) Perform full DB loading to RAM cache(make sense only with big numbers passed to --db-cache-l2 option)"); + m_cmd_binder.set_handler("print_cache_state", boost::bind(&daemon_commands_handler::print_cache_state, this, ph::_1), "Print db l2 cache state"); #ifdef _DEBUG m_cmd_binder.set_handler("debug_set_time_adj", boost::bind(&daemon_commands_handler::debug_set_time_adj, this, ph::_1), "DEBUG: set core time adjustment"); #endif @@ -892,6 +893,14 @@ private: return true; } //-------------------------------------------------------------------------------- + bool print_cache_state(const std::vector& args) + { + + m_srv.get_payload_object().get_core().get_blockchain_storage().print_db_l2_cache_state(); + + return true; + } + //-------------------------------------------------------------------------------- bool print_pool(const std::vector& args) { LOG_PRINT_L0("Pool state: " << ENDL << m_srv.get_payload_object().get_core().print_pool(false)); diff --git a/utils/test_api_files/@get_blocks_response.bin b/utils/test_api_files/@get_blocks_response.bin new file mode 100644 index 0000000000000000000000000000000000000000..9b68e85f65adb007dd5e0eea9f89343f46c8ddda GIT binary patch literal 69 zcmZP+WCQ{xMn)dKJG& literal 0 HcmV?d00001 diff --git a/utils/test_api_files/exec_get_blocks_bin.bat b/utils/test_api_files/exec_get_blocks_bin.bat new file mode 100644 index 00000000..fd4d6d9d --- /dev/null +++ b/utils/test_api_files/exec_get_blocks_bin.bat @@ -0,0 +1,9 @@ +@echo on +:loop +echo Iteration. +curl -X POST http://127.0.0.1:11211/getblocks.bin --data-binary @get_blocks.bin --output @get_blocks_response.bin +goto loop + + + + diff --git a/utils/test_api_files/get_blocks.bin b/utils/test_api_files/get_blocks.bin new file mode 100644 index 0000000000000000000000000000000000000000..1ea8fe32be0ef746e47b395ae4873e7ea61817d3 GIT binary patch literal 943 zcmV;g15o?{5di@K0RjO52nk|rZ)0m;X=HN>0S?867H^0i1VVJ6BI;^R)CXKGtpncO z9tPrPU--GiFzYxezWSYGkJX`!En<;idCid`piVS{nXW~7{!6%7G`LYO#{8F#ukVI^ zCi637oG;oIy7bToo}PWtp}W09$Cc6Gv}i9s z*9#$>sEfc7%Qkw+gUT>N1^^A!>U^nF!whvN*jp^ND26O8h2u2jfV@a4*v1Tp97VmW?n!KZGC+^f74`rgsGMGUp>kuC@wv4 zsJx83W38EZUU{+(6E^3kP=V21bub0MP4I-FX^9{Yc*2W${V-D%brGOr-k2qIq+Y*% zpd2R1>ml&fA6!LmQw)3?uH5eE-!;Yq@?0u7jf?bp7fZPn*Ed6woB&Bl^j*mon zP-UQ%6``1({UA6jSvK_2Zz{OsxYa;D&nlHbSbJCB^K);Eg|1@gz+!%+Eoq~_)AXLK zJ3L5|9N2tNxPCrHw$=-=nHKzcKeqg zKNGuwtxGRS4L;0Zk6HK#4llps$jA=1=BZQEeDc<=y);{`qoK;Vm{JaHX>Mt4b!}g0 RWoc(