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

Add resource settings as config variables #339

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ target_sources (rippled PRIVATE
src/ripple/resource/impl/Consumer.cpp
src/ripple/resource/impl/Fees.cpp
src/ripple/resource/impl/ResourceManager.cpp
src/ripple/resource/impl/Tuning.cpp
#[===============================[
main sources:
subdir: rpc
Expand Down
40 changes: 38 additions & 2 deletions cfg/rippled-example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#
# 9. Misc Settings
#
# 10. Example Settings
# 10. Resource Settings
#
# 11. Example Settings
#
#-------------------------------------------------------------------------------
#
Expand Down Expand Up @@ -1565,7 +1567,41 @@
#
#-------------------------------------------------------------------------------
#
# 10. Example Settings
# 10. Resource Settings
#
#--------------------
# [resource]
#
# A set of key/value pair parameters to tune the performance of the
# transaction queue.
#
# warning_threshold = <number>
#
# Lorem Epsium....
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

#
# drop_threshold = <number>
#
# Lorem Epsium....
#
# decay_window_seconds = <number>
#
# Lorem Epsium....
#
# minimum_gossip_balance = <number>
#
# Lorem Epsium....
#
# seconds_until_expiration = <number>
#
# Lorem Epsium....
#
# gossip_expiration_seconds = <number>
#
# Lorem Epsium....
#
#
#
# 11. Example Settings
#
#--------------------
#
Expand Down
1 change: 1 addition & 0 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class ApplicationImp : public Application, public BasicApp
, validatorKeys_(*config_, m_journal)

, m_resourceManager(Resource::make_Manager(
config_->section("resource"),
m_collectorManager->collector(),
logs_->journal("Resource")))

Expand Down
1 change: 1 addition & 0 deletions src/ripple/core/ConfigSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct ConfigSection
#define SECTION_SWEEP_INTERVAL "sweep_interval"
#define SECTION_NETWORK_ID "network_id"
#define SECTION_IMPORT_VL_KEYS "import_vl_keys"
#define SECTION_RESOURCE "resource"

} // namespace ripple

Expand Down
1 change: 1 addition & 0 deletions src/ripple/resource/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Manager : public beast::PropertyStream::Source

std::unique_ptr<Manager>
make_Manager(
Section const& section,
beast::insight::Collector::ptr const& collector,
beast::Journal journal);

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/resource/impl/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct Entry : public beast::List<Entry>::Node
int refcount;

// Exponentially decaying balance of resource consumption
DecayingSample<decayWindowSeconds, clock_type> local_balance;
DecayingSample<Tuning::getDecayWindowSeconds(), clock_type> local_balance;

// Normalized balance contribution from imports
int remote_balance;
Expand Down
37 changes: 27 additions & 10 deletions src/ripple/resource/impl/Logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ripple/resource/Fees.h>
#include <ripple/resource/Gossip.h>
#include <ripple/resource/impl/Import.h>
#include <ripple/resource/impl/Tuning.h>
#include <cassert>
#include <mutex>

Expand Down Expand Up @@ -88,11 +89,27 @@ class Logic
//--------------------------------------------------------------------------
public:
Logic(
Section const& section,
beast::insight::Collector::ptr const& collector,
clock_type& clock,
beast::Journal journal)
: m_stats(collector), m_clock(clock), m_journal(journal)
{
std::uint32_t warningThreshold;
if (get_if_exists(section, "warning_threshold", warningThreshold))
Tuning::warningThreshold = warningThreshold;

std::uint32_t dropThreshold;
if (get_if_exists(section, "drop_threshold", dropThreshold))
Tuning::dropThreshold = dropThreshold;

// std::uint32_t decayWindowSeconds;
// if (get_if_exists(section, "decay_window_seconds", decayWindowSeconds))
// Tuning::decayWindowSeconds = decayWindowSeconds;

std::uint32_t minimumGossipBalance;
if (get_if_exists(section, "minimum_gossip_balance", minimumGossipBalance))
Tuning::minimumGossipBalance = minimumGossipBalance;
}

~Logic()
Expand Down Expand Up @@ -200,7 +217,7 @@ class Logic
Json::Value
getJson()
{
return getJson(warningThreshold);
return getJson(Tuning::warningThreshold);
}

/** Returns a Json::objectValue. */
Expand Down Expand Up @@ -266,7 +283,7 @@ class Logic
{
Gossip::Item item;
item.balance = inboundEntry.local_balance.value(now);
if (item.balance >= minimumGossipBalance)
if (item.balance >= Tuning::minimumGossipBalance)
{
item.address = inboundEntry.key->address;
gossip.items.push_back(item);
Expand Down Expand Up @@ -294,7 +311,7 @@ class Logic
{
// This is a new import
Import& next(resultIt->second);
next.whenExpires = elapsed + gossipExpirationSeconds;
next.whenExpires = elapsed + Tuning::gossipExpirationSeconds;
next.items.reserve(gossip.items.size());

for (auto const& gossipItem : gossip.items)
Expand All @@ -312,7 +329,7 @@ class Logic
// balances and then deduct the old remote balances.

Import next;
next.whenExpires = elapsed + gossipExpirationSeconds;
next.whenExpires = elapsed + Tuning::gossipExpirationSeconds;
next.items.reserve(gossip.items.size());
for (auto const& gossipItem : gossip.items)
{
Expand Down Expand Up @@ -387,10 +404,10 @@ class Logic
static Disposition
disposition(int balance)
{
if (balance >= dropThreshold)
if (balance >= Tuning::dropThreshold)
return Disposition::drop;

if (balance >= warningThreshold)
if (balance >= Tuning::warningThreshold)
return Disposition::warn;

return Disposition::ok;
Expand Down Expand Up @@ -437,7 +454,7 @@ class Logic
break;
}
inactive_.push_back(entry);
entry.whenExpires = m_clock.now() + secondsUntilExpiration;
entry.whenExpires = m_clock.now() + Tuning::secondsUntilExpiration;
}
}

Expand All @@ -460,7 +477,7 @@ class Logic
std::lock_guard _(lock_);
bool notify(false);
auto const elapsed = m_clock.now();
if (entry.balance(m_clock.now()) >= warningThreshold &&
if (entry.balance(m_clock.now()) >= Tuning::warningThreshold &&
elapsed != entry.lastWarningTime)
{
charge(entry, feeWarning);
Expand All @@ -485,11 +502,11 @@ class Logic
bool drop(false);
clock_type::time_point const now(m_clock.now());
int const balance(entry.balance(now));
if (balance >= dropThreshold)
if (balance >= Tuning::dropThreshold)
{
JLOG(m_journal.warn())
<< "Consumer entry " << entry << " dropped with balance "
<< balance << " at or above drop threshold " << dropThreshold;
<< balance << " at or above drop threshold " << Tuning::dropThreshold;

// Adding feeDrop at this point keeps the dropped connection
// from re-connecting for at least a little while after it is
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/resource/impl/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class ManagerImp : public Manager

public:
ManagerImp(
Section const& section,
beast::insight::Collector::ptr const& collector,
beast::Journal journal)
: journal_(journal), logic_(collector, stopwatch(), journal)
: journal_(journal), logic_(section, collector, stopwatch(), journal)
{
thread_ = std::thread{&ManagerImp::run, this};
}
Expand Down Expand Up @@ -173,10 +174,11 @@ Manager::~Manager() = default;

std::unique_ptr<Manager>
make_Manager(
Section const& section,
beast::insight::Collector::ptr const& collector,
beast::Journal journal)
{
return std::make_unique<ManagerImp>(collector, journal);
return std::make_unique<ManagerImp>(section, collector, journal);
}

} // namespace Resource
Expand Down
34 changes: 34 additions & 0 deletions src/ripple/resource/impl/Tuning.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include "Tuning.h"

namespace ripple {
namespace Resource {

uint32_t Tuning::warningThreshold = 5000;
uint32_t Tuning::dropThreshold = 15000;
// uint32_t Tuning::decayWindowSeconds = 32;
uint32_t Tuning::minimumGossipBalance = 1000;

std::chrono::seconds constexpr Tuning::secondsUntilExpiration{300};
std::chrono::seconds constexpr Tuning::gossipExpirationSeconds{30};

} // namespace Resource
} // namespace ripple
39 changes: 16 additions & 23 deletions src/ripple/resource/impl/Tuning.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
//==============================================================================

// Tuning.h
#ifndef RIPPLE_RESOURCE_TUNING_H_INCLUDED
#define RIPPLE_RESOURCE_TUNING_H_INCLUDED

Expand All @@ -25,31 +26,23 @@
namespace ripple {
namespace Resource {

/** Tunable constants. */
enum {
// Balance at which a warning is issued
warningThreshold = 5000

// Balance at which the consumer is disconnected
,
dropThreshold = 15000

// The number of seconds in the exponential decay window
// (This should be a power of two)
,
decayWindowSeconds = 32

// The minimum balance required in order to include a load source in gossip
,
minimumGossipBalance = 1000
class Tuning
{
public:
static std::uint32_t warningThreshold;
static std::uint32_t dropThreshold;
// static std::uint32_t decayWindowSeconds;
static std::uint32_t minimumGossipBalance;

static std::chrono::seconds const secondsUntilExpiration;
static std::chrono::seconds const gossipExpirationSeconds;

static constexpr std::uint32_t getDecayWindowSeconds()
{
return 32;
}
};

// The number of seconds until an inactive table item is removed
std::chrono::seconds constexpr secondsUntilExpiration{300};

// Number of seconds until imported gossip expires
std::chrono::seconds constexpr gossipExpirationSeconds{30};

} // namespace Resource
} // namespace ripple

Expand Down
Loading
Loading