Skip to content

Commit

Permalink
Merge pull request #4335 from pwojcikdev/scheduler-container-infos
Browse files Browse the repository at this point in the history
Add missing container info for hinted & optimistic schedulers
  • Loading branch information
pwojcikdev authored Nov 7, 2023
2 parents 358bf03 + b54aef1 commit f3792b5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
6 changes: 2 additions & 4 deletions nano/node/scheduler/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ void nano::scheduler::component::stop ()

std::unique_ptr<nano::container_info_component> nano::scheduler::component::collect_container_info (std::string const & name)
{
nano::unique_lock<nano::mutex> lock{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
//composite->add_component (hinted.collect_container_info ("hinted"));
composite->add_component (hinted.collect_container_info ("hinted"));
composite->add_component (manual.collect_container_info ("manual"));
//composite->add_component (optimistic.collect_container_info ("optimistic"));
composite->add_component (optimistic.collect_container_info ("optimistic"));
composite->add_component (priority.collect_container_info ("priority"));
return composite;
}
1 change: 0 additions & 1 deletion nano/node/scheduler/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class component final
std::unique_ptr<nano::scheduler::manual> manual_impl;
std::unique_ptr<nano::scheduler::optimistic> optimistic_impl;
std::unique_ptr<nano::scheduler::priority> priority_impl;
nano::mutex mutex;

public:
explicit component (nano::node & node);
Expand Down
15 changes: 15 additions & 0 deletions nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ void nano::scheduler::hinted::run ()

if (!stopped)
{
lock.unlock ();

if (predicate ())
{
run_iterative ();
}

lock.lock ();
}
}
}
Expand All @@ -185,6 +189,8 @@ nano::uint128_t nano::scheduler::hinted::final_tally_threshold () const

bool nano::scheduler::hinted::cooldown (const nano::block_hash & hash)
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto const now = std::chrono::steady_clock::now ();

// Check if the hash is still in the cooldown period using the hashed index
Expand All @@ -211,6 +217,15 @@ bool nano::scheduler::hinted::cooldown (const nano::block_hash & hash)
return false; // No need to cooldown
}

std::unique_ptr<nano::container_info_component> nano::scheduler::hinted::collect_container_info (const std::string & name) const
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "cooldowns", cooldowns_m.size (), sizeof (decltype (cooldowns_m)::value_type) }));
return composite;
}

/*
* hinted_config
*/
Expand Down
2 changes: 2 additions & 0 deletions nano/node/scheduler/hinted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class hinted final
*/
void notify ();

std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;

private:
bool predicate () const;
void run ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/scheduler/manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void nano::scheduler::manual::run ()
}
}

std::unique_ptr<nano::container_info_component> nano::scheduler::manual::collect_container_info (std::string const & name)
std::unique_ptr<nano::container_info_component> nano::scheduler::manual::collect_container_info (std::string const & name) const
{
nano::unique_lock<nano::mutex> lock{ mutex };

Expand Down
4 changes: 2 additions & 2 deletions nano/node/scheduler/manual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class manual final
{
std::deque<std::tuple<std::shared_ptr<nano::block>, boost::optional<nano::uint128_t>, nano::election_behavior>> queue;
nano::node & node;
nano::mutex mutex;
mutable nano::mutex mutex;
nano::condition_variable condition;
bool stopped{ false };
std::thread thread;
Expand All @@ -41,6 +41,6 @@ class manual final
// Call action with confirmed block, may be different than what we started with
void push (std::shared_ptr<nano::block> const &, boost::optional<nano::uint128_t> const & = boost::none, nano::election_behavior = nano::election_behavior::normal);

std::unique_ptr<container_info_component> collect_container_info (std::string const & name);
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;
}; // class manual
} // nano::scheduler
10 changes: 10 additions & 0 deletions nano/node/scheduler/optimistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void nano::scheduler::optimistic::run ()
debug_assert (!candidates.empty ());
auto candidate = candidates.front ();
candidates.pop_front ();

lock.unlock ();

run_one (transaction, candidate);
Expand Down Expand Up @@ -161,6 +162,15 @@ void nano::scheduler::optimistic::run_one (store::transaction const & transactio
}
}

std::unique_ptr<nano::container_info_component> nano::scheduler::optimistic::collect_container_info (const std::string & name) const
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "candidates", candidates.size (), sizeof (decltype (candidates)::value_type) }));
return composite;
}

/*
* optimistic_scheduler_config
*/
Expand Down
2 changes: 2 additions & 0 deletions nano/node/scheduler/optimistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class optimistic final
*/
void notify ();

std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;

private:
bool activate_predicate (nano::account_info const &, nano::confirmation_height_info const &) const;

Expand Down

0 comments on commit f3792b5

Please sign in to comment.