Skip to content
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

Backlog population is done by a linear scan separated by a 5 minute w… #3648

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nano/node/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ void nano::election_scheduler::manual (std::shared_ptr<nano::block> const & bloc
notify ();
}

void nano::election_scheduler::activate (nano::account const & account_a, nano::transaction const & transaction)
bool nano::election_scheduler::activate (nano::account const & account_a, nano::transaction const & transaction)
{
bool result = false;
debug_assert (!account_a.is_zero ());
nano::account_info account_info;
if (!node.store.account.get (transaction, account_a, account_info))
Expand All @@ -38,11 +39,12 @@ void nano::election_scheduler::activate (nano::account const & account_a, nano::
if (node.ledger.dependents_confirmed (transaction, *block))
{
nano::lock_guard<nano::mutex> lock{ mutex };
priority.push (account_info.modified, block);
result = priority.push (account_info.modified, block);
notify ();
}
}
}
return result;
}

void nano::election_scheduler::stop ()
Expand Down
2 changes: 1 addition & 1 deletion nano/node/election_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class election_scheduler final
// Call action with confirmed block, may be different than what we started with
void manual (std::shared_ptr<nano::block> const &, boost::optional<nano::uint128_t> const & = boost::none, nano::election_behavior = nano::election_behavior::normal, std::function<void (std::shared_ptr<nano::block> const &)> const & = nullptr);
// Activates the first unconfirmed block of \p account_a
void activate (nano::account const &, nano::transaction const &);
bool activate (nano::account const &, nano::transaction const &);
void stop ();
// Blocks until no more elections can be activated or there are no more elections to activate
void flush ();
Expand Down
15 changes: 12 additions & 3 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,12 @@ void nano::node::ongoing_unchecked_cleanup ()

void nano::node::ongoing_backlog_population ()
{
populate_backlog ();
auto overflow = populate_backlog ();
auto delay = config.network_params.network.is_dev_network () ? std::chrono::seconds{ 1 } : std::chrono::duration_cast<std::chrono::seconds> (std::chrono::minutes{ 5 });
if (overflow)
{
delay = std::chrono::seconds{ 0 };
}
workers.add_timed_task (std::chrono::steady_clock::now () + delay, [this_l = shared ()] () {
this_l->ongoing_backlog_population ();
});
Expand Down Expand Up @@ -1745,24 +1749,29 @@ std::pair<uint64_t, decltype (nano::ledger::bootstrap_weights)> nano::node::get_
return { max_blocks, weights };
}

void nano::node::populate_backlog ()
bool nano::node::populate_backlog ()
{
std::cerr << "<---------------Populating...\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a direct print to console needed here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some testing on this PR and it looks really good
This is the baseline test (v23 RC3 branch)
BaselineV23
Cycling is obvious

This V23 RC3 bu with included cherry pick of this PR:
V23+3648
No cycling and average CPS is approx three times higher

auto done = false;
uint64_t const chunk_size = 65536;
nano::account next = 0;
uint64_t total = 0;
bool overflow = false;
while (!stopped && !done)
{
auto transaction = store.tx_begin_read ();
auto count = 0;
for (auto i = store.account.begin (transaction, next), n = store.account.end (); !stopped && i != n && count < chunk_size; ++i, ++count, ++total)
{
auto const & account = i->first;
scheduler.activate (account, transaction);
overflow |= scheduler.activate (account, transaction);
next = account.number () + 1;
}
done = store.account.begin (transaction, next) == store.account.end ();

}
std::cerr << "<---------------Done populating...\n";
return overflow;
}

nano::node_wrapper::node_wrapper (boost::filesystem::path const & path_a, boost::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) :
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class node final : public std::enable_shared_from_this<nano::node>
bool epoch_upgrader (nano::raw_key const &, nano::epoch, uint64_t, uint64_t);
void set_bandwidth_params (std::size_t limit, double ratio);
std::pair<uint64_t, decltype (nano::ledger::bootstrap_weights)> get_bootstrap_weights () const;
void populate_backlog ();
bool populate_backlog ();
nano::write_database_queue write_database_queue;
boost::asio::io_context & io_ctx;
boost::latch node_initialized_latch;
Expand Down
5 changes: 4 additions & 1 deletion nano/node/prioritization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ nano::prioritization::prioritization (uint64_t maximum, std::function<void (std:
current = schedule.begin ();
}

void nano::prioritization::push (uint64_t time, std::shared_ptr<nano::block> block)
bool nano::prioritization::push (uint64_t time, std::shared_ptr<nano::block> block)
{
bool result = false;
auto was_empty = empty ();
auto block_has_balance = block->type () == nano::block_type::state || block->type () == nano::block_type::send;
debug_assert (block_has_balance || block->has_sideband ());
Expand All @@ -68,12 +69,14 @@ void nano::prioritization::push (uint64_t time, std::shared_ptr<nano::block> blo
bucket.emplace (value_type{ time, block });
if (bucket.size () > std::max (decltype (maximum){ 1 }, maximum / buckets.size ()))
{
result = true;
bucket.erase (--bucket.end ());
}
if (was_empty)
{
seek ();
}
return result;
}

std::shared_ptr<nano::block> nano::prioritization::top () const
Expand Down
2 changes: 1 addition & 1 deletion nano/node/prioritization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class prioritization final

public:
prioritization (uint64_t maximum = 250000u, std::function<void (std::shared_ptr<nano::block>)> const & drop_a = nullptr);
void push (uint64_t time, std::shared_ptr<nano::block> block);
bool push (uint64_t time, std::shared_ptr<nano::block> block);
std::shared_ptr<nano::block> top () const;
void pop ();
std::size_t size () const;
Expand Down