Use dedicated thread pool

This commit is contained in:
Piotr Wójcik 2025-01-04 13:42:07 +01:00
commit 1b989270b1
5 changed files with 34 additions and 3 deletions

View file

@ -190,6 +190,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::monitor:
thread_role_name_string = "Monitor";
break;
case nano::thread_role::name::http_callbacks:
thread_role_name_string = "HTTP callbacks";
break;
default:
debug_assert (false && "nano::thread_role::get_string unhandled thread role");
}

View file

@ -68,6 +68,7 @@ enum class name
vote_router,
online_reps,
monitor,
http_callbacks,
};
std::string_view to_string (name);

View file

@ -558,6 +558,7 @@ void nano::node::start ()
vote_router.start ();
online_reps.start ();
monitor.start ();
http_callbacks.start ();
add_initial_peers ();
}
@ -605,6 +606,7 @@ void nano::node::stop ()
message_processor.stop ();
network.stop ();
monitor.stop ();
http_callbacks.stop ();
bootstrap_workers.stop ();
wallet_workers.stop ();
@ -1075,6 +1077,7 @@ nano::container_info nano::node::container_info () const
info.add ("bandwidth", outbound_limiter.container_info ());
info.add ("backlog_scan", backlog_scan.container_info ());
info.add ("bounded_backlog", backlog.container_info ());
info.add ("http_callbacks", http_callbacks.container_info ());
return info;
}

View file

@ -9,7 +9,8 @@ nano::http_callbacks::http_callbacks (nano::node & node_a) :
observers{ node_a.observers },
ledger{ node_a.ledger },
logger{ node_a.logger },
stats{ node_a.stats }
stats{ node_a.stats },
workers{ 1, nano::thread_role::name::http_callbacks }
{
// Only set up callbacks if a callback address is configured
if (!config.callback_address.empty ())
@ -19,6 +20,21 @@ nano::http_callbacks::http_callbacks (nano::node & node_a) :
}
}
void nano::http_callbacks::start ()
{
workers.start ();
}
void nano::http_callbacks::stop ()
{
workers.stop ();
}
nano::container_info nano::http_callbacks::container_info () const
{
return workers.container_info ();
}
void nano::http_callbacks::setup_callbacks ()
{
// Add observer for block confirmations
@ -36,8 +52,8 @@ void nano::http_callbacks::setup_callbacks ()
stats.inc (nano::stat::type::http_callbacks_notified, nano::stat::detail::block_confirmed);
// Post callback processing to worker thread
// Safe to capture 'this' by reference as workers are stopped before node destruction
node.workers.post ([this, block_a, account_a, amount_a, is_state_send_a, is_state_epoch_a] () {
// Safe to capture 'this' by reference as workers are stopped before this component destruction
workers.post ([this, block_a, account_a, amount_a, is_state_send_a, is_state_epoch_a] () {
// Construct the callback payload as a property tree
boost::property_tree::ptree event;
event.add ("account", account_a.to_account ());

View file

@ -1,5 +1,6 @@
#pragma once
#include <nano/lib/thread_pool.hpp>
#include <nano/node/fwd.hpp>
namespace nano
@ -9,6 +10,11 @@ class http_callbacks
public:
explicit http_callbacks (nano::node &);
void start ();
void stop ();
nano::container_info container_info () const;
private: // Dependencies
nano::node_config const & config;
nano::node & node;
@ -20,5 +26,7 @@ private: // Dependencies
private:
void setup_callbacks ();
void do_rpc_callback (boost::asio::ip::tcp::resolver::iterator i_a, std::string const &, uint16_t, std::shared_ptr<std::string> const &, std::shared_ptr<std::string> const &, std::shared_ptr<boost::asio::ip::tcp::resolver> const &);
nano::thread_pool workers;
};
}