-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.0] P2P: Throttle over sync window #1811
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -892,6 +892,8 @@ namespace eosio { | |
std::atomic<size_t> bytes_sent{0}; | ||
std::atomic<size_t> block_sync_bytes_received{0}; | ||
std::atomic<size_t> block_sync_bytes_sent{0}; | ||
std::chrono::nanoseconds block_sync_send_start{0ns}; // start of enqueue blocks | ||
size_t block_sync_send_bytes_sent{0}; // bytes sent in this set of enqueue blocks | ||
std::atomic<bool> block_sync_throttling{false}; | ||
std::atomic<std::chrono::nanoseconds> last_bytes_sent{0ns}; | ||
std::atomic<boost::asio::ip::port_type> remote_endpoint_port{0}; | ||
|
@@ -1460,6 +1462,9 @@ namespace eosio { | |
latest_msg_time = std::chrono::system_clock::time_point::min(); | ||
latest_blk_time = std::chrono::system_clock::time_point::min(); | ||
set_state(connection_state::closed); | ||
block_sync_send_start = 0ns; | ||
block_sync_send_bytes_sent = 0; | ||
block_sync_throttling = false; | ||
|
||
if( reconnect && !shutdown ) { | ||
my_impl->connections.start_conn_timer( std::chrono::milliseconds( 100 ), | ||
|
@@ -1740,25 +1745,38 @@ namespace eosio { | |
} FC_LOG_AND_DROP(); | ||
if( sb ) { | ||
// Skip transmitting block this loop if threshold exceeded | ||
if( block_sync_rate_limit > 0 && peer_syncing_from_us ) { | ||
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(get_time() - connection_start_time); | ||
auto current_rate = double(block_sync_bytes_sent) / elapsed.count(); | ||
if (block_sync_send_start == 0ns) { // start of enqueue blocks | ||
block_sync_send_start = get_time(); | ||
block_sync_send_bytes_sent = 0; | ||
} | ||
if( block_sync_rate_limit > 0 && block_sync_send_bytes_sent > 0 && peer_syncing_from_us ) { | ||
auto now = get_time(); | ||
auto elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(now - block_sync_send_start); | ||
double current_rate = (double(block_sync_bytes_sent) / elapsed_us.count()) * 100000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are changing variables names from my comment above, please make this line a bit more readable by renaming |
||
peer_dlog(this, "start enqueue block time ${st}, now ${t}, elapsed ${e}, rate ${r}, limit ${l}", | ||
("st", block_sync_send_start.count())("t", now.count())("e", elapsed_us.count())("r", current_rate)("l", block_sync_rate_limit)); | ||
if( current_rate >= block_sync_rate_limit ) { | ||
block_sync_throttling = true; | ||
peer_dlog( this, "throttling block sync to peer ${host}:${port}", ("host", log_remote_endpoint_ip)("port", log_remote_endpoint_port)); | ||
return false; | ||
} | ||
} | ||
block_sync_throttling = false; | ||
block_sync_bytes_sent += enqueue_block( sb, true ); | ||
auto sent = enqueue_block( sb, true ); | ||
block_sync_bytes_sent += sent; | ||
block_sync_send_bytes_sent += sent; | ||
++peer_requested->last; | ||
if(num == peer_requested->end_block) { | ||
peer_requested.reset(); | ||
block_sync_send_start = 0ns; | ||
block_sync_send_bytes_sent = 0; | ||
peer_dlog( this, "completing enqueue_sync_block ${num}", ("num", num) ); | ||
} | ||
} else { | ||
peer_ilog( this, "enqueue sync, unable to fetch block ${num}, sending benign_other go away", ("num", num) ); | ||
peer_requested.reset(); // unable to provide requested blocks | ||
block_sync_send_start = 0ns; | ||
block_sync_send_bytes_sent = 0; | ||
no_retry = benign_other; | ||
enqueue( go_away_message( benign_other ) ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to quibble over naming but
block_sync_bytes_sent
andblock_sync_send_bytes_sent
just blow my mind.Can we rename this to something like:
block_sync_total_bytes_sent
block_sync_frame_bytes_sent
?