Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change buckets construction maximum to mean per-bucket size rather th…
Browse files Browse the repository at this point in the history
…an total size.
clemahieu committed May 14, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 24241f0 commit d7b818b
Showing 5 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/scheduler_buckets.cpp
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ TEST (buckets, trim_reverse)

TEST (buckets, trim_even)
{
nano::scheduler::buckets buckets{ 2 };
nano::scheduler::buckets buckets{ 1 };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1100, block2 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
7 changes: 3 additions & 4 deletions nano/node/scheduler/buckets.cpp
Original file line number Diff line number Diff line change
@@ -29,9 +29,9 @@ void nano::scheduler::buckets::seek ()
* Prioritization constructor, construct a container containing approximately 'maximum' number of blocks.
* @param maximum number of blocks that this container can hold, this is a soft and approximate limit.
*/
nano::scheduler::buckets::buckets (uint64_t maximum) :
maximum{ maximum }
nano::scheduler::buckets::buckets (uint64_t maximum)
{
debug_assert (maximum > 0);
auto build_region = [this] (uint128_t const & begin, uint128_t const & end, size_t count) {
auto width = (end - begin) / count;
for (auto i = 0; i < count; ++i)
@@ -49,10 +49,9 @@ nano::scheduler::buckets::buckets (uint64_t maximum) :
build_region (uint128_t{ 1 } << 112, uint128_t{ 1 } << 116, 4);
build_region (uint128_t{ 1 } << 116, uint128_t{ 1 } << 120, 2);
minimums.push_back (uint128_t{ 1 } << 120);
auto bucket_max = std::max<size_t> (1u, maximum / minimums.size ());
for (size_t i = 0u, n = minimums.size (); i < n; ++i)
{
buckets_m.push_back (std::make_unique<scheduler::bucket> (bucket_max));
buckets_m.push_back (std::make_unique<scheduler::bucket> (maximum));
}
current = buckets_m.begin ();
}
5 changes: 1 addition & 4 deletions nano/node/scheduler/buckets.hpp
Original file line number Diff line number Diff line change
@@ -36,14 +36,11 @@ class buckets final
/** index of bucket to read next */
decltype (buckets_m)::const_iterator current;

/** maximum number of blocks in whole container, each bucket's maximum is maximum / bucket_number */
uint64_t const maximum;

void next ();
void seek ();

public:
buckets (uint64_t maximum = 250000u);
buckets (uint64_t maximum = 4096);
~buckets ();
void push (uint64_t time, std::shared_ptr<nano::block> block, nano::amount const & priority);
std::shared_ptr<nano::block> top () const;
2 changes: 1 addition & 1 deletion nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a)
config{ node_a.config.priority_scheduler },
node{ node_a },
stats{ stats_a },
buckets{ std::make_unique<scheduler::buckets> () }
buckets{ std::make_unique<scheduler::buckets> (config.bucket_maximum) }
{
}

1 change: 1 addition & 0 deletions nano/node/scheduler/priority.hpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ class priority_config

public:
bool enabled{ true };
size_t bucket_maximum{ 4096 };
};

class buckets;

0 comments on commit d7b818b

Please sign in to comment.