1
0
Fork 0
forked from lthn/blockchain

added some diagnostic logs for blockchain caching

This commit is contained in:
cryptozoidberg 2025-04-10 22:42:38 +04:00
parent cbb9a39bf1
commit d4366d3f18
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
8 changed files with 62 additions and 22 deletions

View file

@ -60,14 +60,14 @@ namespace epee
template<bool is_ordered_container, typename t_key, typename t_value, uint64_t max_elements>
class cache_base
{
uint64_t mac_allowed_elements;
uint64_t max_allowed_elements;
std::list<t_key> most_recet_acessed;
typename container_selector<is_ordered_container, t_key, std::pair<t_value, typename std::list<t_key>::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())

View file

@ -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();

View file

@ -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)

View file

@ -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:

View file

@ -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), "<ip-address> - 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<std::string>& args)
{
m_srv.get_payload_object().get_core().get_blockchain_storage().print_db_l2_cache_state();
return true;
}
//--------------------------------------------------------------------------------
bool print_pool(const std::vector<std::string>& args)
{
LOG_PRINT_L0("Pool state: " << ENDL << m_srv.get_payload_object().get_core().print_pool(false));

Binary file not shown.

View file

@ -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

Binary file not shown.