Skip to content

Commit

Permalink
Using limiter in optimistic scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 12, 2023
1 parent ecd0bd2 commit eaddf00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions nano/node/scheduler/optimistic.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <nano/lib/stats.hpp>
#include <nano/lib/tomlconfig.hpp>
#include <nano/node/node.hpp>
#include <nano/node/scheduler/limiter.hpp>
#include <nano/node/scheduler/optimistic.hpp>

nano::scheduler::optimistic::optimistic (optimistic_config const & config_a, nano::node & node_a, nano::ledger & ledger_a, nano::active_transactions & active_a, nano::network_constants const & network_constants_a, nano::stats & stats_a) :
config{ config_a },
node{ node_a },
ledger{ ledger_a },
active{ active_a },
limiter{ std::make_shared<nano::scheduler::limiter> (node.active.insert_fn (), std::max<size_t> (node.config.active_elections_optimistic_limit_percentage * node.config.active_elections_size / 100, 1u), nano::election_behavior::optimistic) },
network_constants{ network_constants_a },
stats{ stats_a }
{
Expand Down Expand Up @@ -100,7 +101,7 @@ bool nano::scheduler::optimistic::predicate () const
{
debug_assert (!mutex.try_lock ());

if (active.vacancy (nano::election_behavior::optimistic) <= 0)
if (!limiter->available ())
{
return false;
}
Expand Down Expand Up @@ -154,7 +155,7 @@ void nano::scheduler::optimistic::run_one (nano::transaction const & transaction
{
// Try to insert it into AEC
// We check for AEC vacancy inside our predicate
auto result = node.active.insert (block, nano::election_behavior::optimistic);
auto result = limiter->activate (block);

stats.inc (nano::stat::type::optimistic_scheduler, result.inserted ? nano::stat::detail::insert : nano::stat::detail::insert_failed);
}
Expand Down
7 changes: 4 additions & 3 deletions nano/node/scheduler/optimistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ namespace mi = boost::multi_index;

namespace nano
{
class node;
class ledger;
class active_transactions;
class ledger;
class node;
}

namespace nano::scheduler
{
class limiter;
class optimistic_config final
{
public:
Expand Down Expand Up @@ -76,7 +77,7 @@ class optimistic final
optimistic_config const & config;
nano::node & node;
nano::ledger & ledger;
nano::active_transactions & active;
std::shared_ptr<nano::scheduler::limiter> limiter;
nano::network_constants const & network_constants;
nano::stats & stats;

Expand Down

0 comments on commit eaddf00

Please sign in to comment.