Skip to content

Commit

Permalink
Disable block_in performance ratcheting.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 20, 2024
1 parent 293a8fb commit 79878dc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 77 deletions.
28 changes: 14 additions & 14 deletions include/bitcoin/node/protocols/protocol_block_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class BCN_API protocol_block_in
const channel_ptr& channel, bool report_performance) NOEXCEPT
: node::protocol(session, channel),
network::tracker<protocol_block_in>(session.log),
report_performance_(report_performance &&
to_bool(session.config().node.sample_period_seconds)),
////report_performance_(report_performance &&
//// to_bool(session.config().node.sample_period_seconds)),
block_type_(session.config().network.witness_node() ?
type_id::witness_block : type_id::block),
performance_timer_(std::make_shared<network::deadline>(session.log,
channel->strand(), session.config().node.sample_period()))
type_id::witness_block : type_id::block)
////performance_timer_(std::make_shared<network::deadline>(session.log,
//// channel->strand(), session.config().node.sample_period()))
{
}
BC_POP_WARNING()
Expand Down Expand Up @@ -73,11 +73,11 @@ class BCN_API protocol_block_in
const network::messages::block::cptr& message,
const track_ptr& tracker) NOEXCEPT;

/// Handle performance timer event.
virtual void handle_performance_timer(const code& ec) NOEXCEPT;
/////// Handle performance timer event.
////virtual void handle_performance_timer(const code& ec) NOEXCEPT;

/// Handle result of performance reporting.
virtual void handle_performance(const code& ec) NOEXCEPT;
/////// Handle result of performance reporting.
////virtual void handle_performance(const code& ec) NOEXCEPT;

/// Invoked when initial blocks sync is complete.
virtual void complete() NOEXCEPT;
Expand All @@ -96,17 +96,17 @@ class BCN_API protocol_block_in
const network::messages::inventory& message) const NOEXCEPT;


void do_handle_performance(const code& ec) NOEXCEPT;
////void do_handle_performance(const code& ec) NOEXCEPT;

// Thread safe.
const bool report_performance_;
////const bool report_performance_;
const network::messages::inventory::type_id block_type_;

// Protected by strand.
uint64_t bytes_{ zero };
////uint64_t bytes_{ zero };
system::chain::checkpoint top_{};
network::steady_clock::time_point start_{};
network::deadline::ptr performance_timer_;
////network::steady_clock::time_point start_{};
////network::deadline::ptr performance_timer_;
};

} // namespace node
Expand Down
131 changes: 68 additions & 63 deletions src/protocols/protocol_block_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,61 +49,66 @@ BC_PUSH_WARNING(NO_NEW_OR_DELETE)
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)

// Performance polling.
// ----------------------------------------------------------------------------

void protocol_block_in::handle_performance_timer(const code& ec) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "expected channel strand");

if (stopped() || ec == network::error::operation_canceled)
return;

if (ec)
{
LOGF("Performance timer error, " << ec.message());
stop(ec);
return;
}

// Compute rate in bytes per second.
const auto now = steady_clock::now();
const auto gap = std::chrono::duration_cast<seconds>(now - start_).count();
const auto rate = floored_divide(bytes_, to_unsigned(gap));

// Reset counters and log rate.
bytes_ = zero;
start_ = now;
log.fire(event_block, rate);

// Bounces to network strand, performs work, then calls handler.
// Channel will continue to process blocks while this call excecutes on the
// network strand. Timer will not be restarted until this call completes.
performance(identifier(), rate, BIND1(handle_performance, ec));
}

void protocol_block_in::handle_performance(const code& ec) NOEXCEPT
{
POST1(do_handle_performance, ec);
}

void protocol_block_in::do_handle_performance(const code& ec) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "expected network strand");

if (stopped())
return;

// stalled_channel or slow_channel
if (ec)
{
LOGF("Performance action, " << ec.message());
stop(ec);
return;
};

performance_timer_->start(BIND1(handle_performance_timer, _1));
}
////// Performance polling.
////// ----------------------------------------------------------------------------
////
////void protocol_block_in::handle_performance_timer(const code& ec) NOEXCEPT
////{
//// BC_ASSERT_MSG(stranded(), "expected channel strand");
////
//// if (stopped() || ec == network::error::operation_canceled)
//// return;
////
//// if (ec)
//// {
//// LOGF("Performance timer error, " << ec.message());
//// stop(ec);
//// return;
//// }
////
//// // Compute rate in bytes per second.
//// const auto now = steady_clock::now();
//// const auto gap = std::chrono::duration_cast<seconds>(now - start_).count();
//// const auto rate = floored_divide(bytes_, gap);
//// LOGN("Rate ["
//// << identifier() << "] ("
//// << bytes_ << "/"
//// << gap << " = "
//// << rate << ").");
////
//// // Reset counters and log rate.
//// bytes_ = zero;
//// start_ = now;
//// ////log.fire(event_block, rate);
////
//// // Bounces to network strand, performs work, then calls handler.
//// // Channel will continue to process blocks while this call excecutes on the
//// // network strand. Timer will not be restarted until this call completes.
//// performance(identifier(), rate, BIND1(handle_performance, ec));
////}
////
////void protocol_block_in::handle_performance(const code& ec) NOEXCEPT
////{
//// POST1(do_handle_performance, ec);
////}
////
////void protocol_block_in::do_handle_performance(const code& ec) NOEXCEPT
////{
//// BC_ASSERT_MSG(stranded(), "expected network strand");
////
//// if (stopped())
//// return;
////
//// // stalled_channel or slow_channel
//// if (ec)
//// {
//// LOGF("Performance action, " << ec.message());
//// stop(ec);
//// return;
//// };
////
//// performance_timer_->start(BIND1(handle_performance_timer, _1));
////}

// Start/stop.
// ----------------------------------------------------------------------------
Expand All @@ -119,11 +124,11 @@ void protocol_block_in::start() NOEXCEPT
const auto top = query.get_top_candidate();
top_ = { query.get_header_key(query.to_candidate(top)), top };

if (report_performance_)
{
start_ = steady_clock::now();
performance_timer_->start(BIND1(handle_performance_timer, _1));
}
////if (report_performance_)
////{
//// start_ = steady_clock::now();
//// performance_timer_->start(BIND1(handle_performance_timer, _1));
////}

// There is one persistent common inventory subscription.
SUBSCRIBE_CHANNEL2(inventory, handle_receive_inventory, _1, _2);
Expand All @@ -134,7 +139,7 @@ void protocol_block_in::start() NOEXCEPT
void protocol_block_in::stopping(const code& ec) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "protocol_block_in");
performance_timer_->stop();
////performance_timer_->stop();
protocol::stopping(ec);
}

Expand Down Expand Up @@ -221,8 +226,8 @@ bool protocol_block_in::handle_receive_block(const code& ec,
LOGP("Block [" << encode_hash(top_.hash()) << "] at ("
<< top_.height() << ") from [" << authority() << "].");

// Accumulate byte count.
bytes_ += message->cached_size;
////// Accumulate byte count.
////bytes_ += message->cached_size;

// Order is reversed, so next is at back.
tracker->hashes.pop_back();
Expand Down

0 comments on commit 79878dc

Please sign in to comment.