mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
src: dynamic span, to calculate span limit dynamically
Co-authored-by: nahuhh
This commit is contained in:
parent
b089f9ee69
commit
90d2133132
@ -124,6 +124,11 @@ namespace cryptonote
|
||||
, "Set maximum size of block download queue in bytes (0 for default)"
|
||||
, 0
|
||||
};
|
||||
const command_line::arg_descriptor<size_t> arg_span_limit = {
|
||||
"span-limit"
|
||||
, "Set span limit when syncing, can time (m postfix for minutes), default is 2 minutes"
|
||||
, 2
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_sync_pruned_blocks = {
|
||||
"sync-pruned-blocks"
|
||||
, "Allow syncing from nodes with only pruned blocks"
|
||||
@ -346,6 +351,7 @@ namespace cryptonote
|
||||
command_line::add_arg(desc, arg_offline);
|
||||
command_line::add_arg(desc, arg_disable_dns_checkpoints);
|
||||
command_line::add_arg(desc, arg_block_download_max_size);
|
||||
command_line::add_arg(desc, arg_span_limit);
|
||||
command_line::add_arg(desc, arg_sync_pruned_blocks);
|
||||
command_line::add_arg(desc, arg_max_txpool_weight);
|
||||
command_line::add_arg(desc, arg_block_notify);
|
||||
|
@ -70,6 +70,7 @@ namespace cryptonote
|
||||
extern const command_line::arg_descriptor<difficulty_type> arg_fixed_difficulty;
|
||||
extern const command_line::arg_descriptor<bool> arg_offline;
|
||||
extern const command_line::arg_descriptor<size_t> arg_block_download_max_size;
|
||||
extern const command_line::arg_descriptor<size_t> arg_span_limit;
|
||||
extern const command_line::arg_descriptor<bool> arg_sync_pruned_blocks;
|
||||
|
||||
/************************************************************************/
|
||||
|
@ -166,6 +166,7 @@ namespace cryptonote
|
||||
size_t skip_unneeded_hashes(cryptonote_connection_context& context, bool check_block_queue) const;
|
||||
bool request_txpool_complement(cryptonote_connection_context &context);
|
||||
void hit_score(cryptonote_connection_context &context, int32_t score);
|
||||
void calculate_dynamic_span(double blocks_per_seconds);
|
||||
|
||||
t_core& m_core;
|
||||
|
||||
@ -190,6 +191,9 @@ namespace cryptonote
|
||||
uint64_t m_sync_download_chain_size, m_sync_download_objects_size;
|
||||
size_t m_block_download_max_size;
|
||||
bool m_sync_pruned_blocks;
|
||||
size_t m_span_time;
|
||||
size_t m_span_limit;
|
||||
size_t m_bss;
|
||||
|
||||
// Values for sync time estimates
|
||||
boost::posix_time::ptime m_sync_start_time;
|
||||
|
@ -62,7 +62,8 @@
|
||||
#define MLOG_PEER_STATE(x) \
|
||||
MCINFO(MONERO_DEFAULT_LOG_CATEGORY, context << "[" << epee::string_tools::to_string_hex(context.m_pruning_seed) << "] state: " << x << " in state " << cryptonote::get_protocol_state_string(context.m_state))
|
||||
|
||||
#define BLOCK_QUEUE_NSPANS_THRESHOLD 10 // chunks of N blocks
|
||||
#define BLOCK_QUEUE_NSPANS_THRESHOLD 200 // chunks of N blocks
|
||||
#define BLOCK_QUEUE_NSPANS_MINIMUM 10 // minimum number of spans
|
||||
#define BLOCK_QUEUE_SIZE_THRESHOLD (100*1024*1024) // MB
|
||||
#define BLOCK_QUEUE_FORCE_DOWNLOAD_NEAR_BLOCKS 1000
|
||||
#define REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY (5 * 1000000) // microseconds
|
||||
@ -87,7 +88,10 @@ namespace cryptonote
|
||||
m_synchronized(offline),
|
||||
m_ask_for_txpool_complement(true),
|
||||
m_stopping(false),
|
||||
m_no_sync(false)
|
||||
m_no_sync(false),
|
||||
m_span_limit(BLOCK_QUEUE_NSPANS_MINIMUM),
|
||||
m_span_time(0),
|
||||
m_bss(0)
|
||||
|
||||
{
|
||||
if(!m_p2p)
|
||||
@ -110,11 +114,22 @@ namespace cryptonote
|
||||
|
||||
m_block_download_max_size = command_line::get_arg(vm, cryptonote::arg_block_download_max_size);
|
||||
m_sync_pruned_blocks = command_line::get_arg(vm, cryptonote::arg_sync_pruned_blocks);
|
||||
m_span_time = command_line::get_arg(vm, cryptonote::arg_span_limit);
|
||||
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
void t_cryptonote_protocol_handler<t_core>::calculate_dynamic_span(double blocks_per_seconds)
|
||||
{
|
||||
MINFO("m_bss : " << m_bss << ", blocks_per_seconds : " << blocks_per_seconds << ", m_span_limit : " << m_span_limit);
|
||||
m_span_limit = (m_bss && blocks_per_seconds) ? (( blocks_per_seconds * 60 * m_span_time ) / m_bss) : BLOCK_QUEUE_NSPANS_THRESHOLD;
|
||||
if (m_span_limit < BLOCK_QUEUE_NSPANS_MINIMUM)
|
||||
m_span_limit = BLOCK_QUEUE_NSPANS_MINIMUM;
|
||||
MINFO("calculated dynamic span limit is span_limit : " << m_span_limit);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
bool t_cryptonote_protocol_handler<t_core>::deinit()
|
||||
{
|
||||
return true;
|
||||
@ -1660,10 +1675,12 @@ namespace cryptonote
|
||||
m_block_queue.remove_spans(span_connection_id, start_height);
|
||||
|
||||
const uint64_t current_blockchain_height = m_core.get_current_blockchain_height();
|
||||
const boost::posix_time::time_duration dt = boost::posix_time::microsec_clock::universal_time() - start;
|
||||
double blocks_per_seconds = (((current_blockchain_height - previous_height) * 1e6) / dt.total_microseconds());
|
||||
calculate_dynamic_span(blocks_per_seconds);
|
||||
if (current_blockchain_height > previous_height)
|
||||
{
|
||||
const uint64_t target_blockchain_height = m_core.get_target_blockchain_height();
|
||||
const boost::posix_time::time_duration dt = boost::posix_time::microsec_clock::universal_time() - start;
|
||||
std::string progress_message = "";
|
||||
if (current_blockchain_height < target_blockchain_height)
|
||||
{
|
||||
@ -1687,7 +1704,7 @@ namespace cryptonote
|
||||
std::string timing_message = "";
|
||||
if (ELPP->vRegistry()->allowed(el::Level::Info, "sync-info"))
|
||||
timing_message = std::string(" (") + std::to_string(dt.total_microseconds()/1e6) + " sec, "
|
||||
+ std::to_string((current_blockchain_height - previous_height) * 1e6 / dt.total_microseconds())
|
||||
+ std::to_string(blocks_per_seconds)
|
||||
+ " blocks/sec), " + std::to_string(m_block_queue.get_data_size() / 1048576.f) + " MB queued in "
|
||||
+ std::to_string(m_block_queue.get_num_filled_spans()) + " spans, stripe "
|
||||
+ std::to_string(previous_stripe) + " -> " + std::to_string(current_stripe);
|
||||
@ -2106,7 +2123,17 @@ skip:
|
||||
const uint32_t peer_stripe = tools::get_pruning_stripe(context.m_pruning_seed);
|
||||
const uint32_t local_stripe = tools::get_pruning_stripe(m_core.get_blockchain_pruning_seed());
|
||||
const size_t block_queue_size_threshold = m_block_download_max_size ? m_block_download_max_size : BLOCK_QUEUE_SIZE_THRESHOLD;
|
||||
bool queue_proceed = nspans < BLOCK_QUEUE_NSPANS_THRESHOLD || size < block_queue_size_threshold;
|
||||
m_span_limit = m_span_limit ? m_span_limit : BLOCK_QUEUE_NSPANS_THRESHOLD;
|
||||
bool queue_proceed = (nspans < m_span_limit) && (size < block_queue_size_threshold);
|
||||
MINFO( "block_queue_size_threshold : " << block_queue_size_threshold
|
||||
<< ", queue_proceed : " << queue_proceed
|
||||
<< ", size : " << size
|
||||
<< ", nspans : " << nspans
|
||||
<< ", m_span_limit : " << m_span_limit
|
||||
<< ", bc_height : " << bc_height
|
||||
<< ", add_stripe : " << add_stripe
|
||||
<< ", peer_stripe : " << peer_stripe
|
||||
<< ", local_stripe : " << local_stripe);
|
||||
// get rid of blocks we already requested, or already have
|
||||
if (skip_unneeded_hashes(context, true) && context.m_needed_objects.empty() && context.m_num_requested == 0)
|
||||
{
|
||||
@ -2224,7 +2251,7 @@ skip:
|
||||
NOTIFY_REQUEST_GET_OBJECTS::request req;
|
||||
bool is_next = false;
|
||||
size_t count = 0;
|
||||
const size_t count_limit = m_core.get_block_sync_size(m_core.get_current_blockchain_height());
|
||||
m_bss = m_core.get_block_sync_size(m_core.get_current_blockchain_height());
|
||||
std::pair<uint64_t, uint64_t> span = std::make_pair(0, 0);
|
||||
if (force_next_span)
|
||||
{
|
||||
@ -2274,7 +2301,7 @@ skip:
|
||||
const uint64_t first_block_height = context.m_last_response_height - context.m_needed_objects.size() + 1;
|
||||
static const uint64_t bp_fork_height = m_core.get_earliest_ideal_height_for_version(8);
|
||||
bool sync_pruned_blocks = m_sync_pruned_blocks && first_block_height >= bp_fork_height && m_core.get_blockchain_pruning_seed();
|
||||
span = m_block_queue.reserve_span(first_block_height, context.m_last_response_height, count_limit, context.m_connection_id, context.m_remote_address, sync_pruned_blocks, m_core.get_blockchain_pruning_seed(), context.m_pruning_seed, context.m_remote_blockchain_height, context.m_needed_objects);
|
||||
span = m_block_queue.reserve_span(first_block_height, context.m_last_response_height, m_bss, context.m_connection_id, context.m_remote_address, sync_pruned_blocks, m_core.get_blockchain_pruning_seed(), context.m_pruning_seed, context.m_remote_blockchain_height, context.m_needed_objects);
|
||||
MDEBUG(context << " span from " << first_block_height << ": " << span.first << "/" << span.second);
|
||||
if (span.second > 0)
|
||||
{
|
||||
@ -2360,7 +2387,7 @@ skip:
|
||||
context.m_expect_height = span.first;
|
||||
context.m_expect_response = NOTIFY_RESPONSE_GET_OBJECTS::ID;
|
||||
MLOG_P2P_MESSAGE("-->>NOTIFY_REQUEST_GET_OBJECTS: blocks.size()=" << req.blocks.size()
|
||||
<< "requested blocks count=" << count << " / " << count_limit << " from " << span.first << ", first hash " << req.blocks.front());
|
||||
<< "requested blocks count=" << count << " / " << m_bss << " from " << span.first << ", first hash " << req.blocks.front());
|
||||
//epee::net_utils::network_throttle_manager::get_global_throttle_inreq().logger_handle_net("log/dr-monero/net/req-all.data", sec, get_avg_block_size());
|
||||
|
||||
MDEBUG("Asking for " << (req.prune ? "pruned" : "full") << " data, start/end "
|
||||
|
Loading…
Reference in New Issue
Block a user