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

Prs/scheduler prioritization container info #1

Merged
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
8 changes: 4 additions & 4 deletions nano/node/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ void nano::election_scheduler::run ()
}
}

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

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "manual_queue", election_scheduler.manual_queue.size (), sizeof (decltype (election_scheduler.manual_queue)::value_type) }));
composite->add_component (collect_container_info (election_scheduler.priority, "priority"));
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "manual_queue", manual_queue.size (), sizeof (decltype (manual_queue)::value_type) }));
composite->add_component (priority.collect_container_info ("priority"));
return composite;
}
6 changes: 2 additions & 4 deletions nano/node/election_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class election_scheduler final
std::size_t size () const;
bool empty () const;
std::size_t priority_queue_size () const;
std::unique_ptr<container_info_component> collect_container_info (std::string const &);

private:
void run ();
Expand All @@ -46,8 +47,5 @@ class election_scheduler final
nano::condition_variable condition;
mutable nano::mutex mutex;
std::thread thread;

friend std::unique_ptr<container_info_component> collect_container_info (election_scheduler &, std::string const &);
};
std::unique_ptr<container_info_component> collect_container_info (election_scheduler & election_scheduler, std::string const & name);
}
}
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (no
composite->add_component (collect_container_info (node.confirmation_height_processor, "confirmation_height_processor"));
composite->add_component (collect_container_info (node.distributed_work, "distributed_work"));
composite->add_component (collect_container_info (node.aggregator, "request_aggregator"));
composite->add_component (collect_container_info (node.scheduler, "election_scheduler"));
composite->add_component (node.scheduler.collect_container_info ("election_scheduler"));
return composite;
}

Expand Down
6 changes: 3 additions & 3 deletions nano/node/prioritization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ void nano::prioritization::dump ()
std::cerr << "current: " << std::to_string (*current) << '\n';
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (prioritization & prioritization, std::string const & name)
std::unique_ptr<nano::container_info_component> nano::prioritization::collect_container_info (std::string const & name)
{
auto composite = std::make_unique<container_info_composite> (name);
for (auto i = 0; i < prioritization.buckets.size (); ++i)
for (auto i = 0; i < buckets.size (); ++i)
{
auto const & bucket = prioritization.buckets[i];
auto const & bucket = buckets[i];
composite->add_component (std::make_unique<container_info_leaf> (container_info{ std::to_string (i), bucket.size (), 0 }));
}
return composite;
Expand Down
3 changes: 1 addition & 2 deletions nano/node/prioritization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class prioritization final
void dump ();
uint64_t const maximum;

friend std::unique_ptr<container_info_component> collect_container_info (prioritization &, std::string const &);
std::unique_ptr<nano::container_info_component> collect_container_info (std::string const &);
};
std::unique_ptr<container_info_component> collect_container_info (prioritization & prioritization, std::string const & name);
}
39 changes: 39 additions & 0 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6243,3 +6243,42 @@ TEST (rpc, confirmation_info)
ASSERT_EQ (0, response.get<unsigned> ("total_tally"));
}
}

/** Test election scheduler container object stats
* The test set the AEC size to 0 and then creates a block which gets stuck
* in the election scheduler waiting for a slot in the AEC. Then it confirms that
* the stats RPC call shows the corresponding scheduler bucket incrementing
*/
TEST (node, election_scheduler_container_info)
{
nano::system system;
nano::node_config node_config;
node_config.active_elections_size = 0;
nano::node_flags node_flags;
auto node = add_ipc_enabled_node (system, node_config);
auto const rpc_ctx = add_rpc (system, node);

// create a send block
auto send1 = nano::state_block_builder ()
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 1)
.link (nano::public_key ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*node->work_generate_blocking (nano::dev::genesis->hash ()))
.build_shared ();

// process the block and wait for it to show up in the election scheduler
node->process_active (send1);
ASSERT_TIMELY (10s, node->scheduler.size () == 1);

// now check the RPC call
boost::property_tree::ptree request;
request.put ("action", "stats");
request.put ("type", "objects");
auto response = wait_response (system, rpc_ctx, request);
auto es = response.get_child ("node").get_child ("election_scheduler");
ASSERT_EQ (es.get_child ("manual_queue").get<std::string> ("count"), "0");
ASSERT_EQ (es.get_child ("priority").get_child ("128").get<std::string> ("count"), "1");
}