From eaff0d30fb494cd9746c73ac59c84a568ee58783 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sat, 6 Nov 2021 18:33:43 -0700 Subject: [PATCH] Make the sweep_interval individually configurable: The "sweep interval" is the amount of time between successive sweeps of of various in-memory data structures to remove stale items. Prior to this commit, the interval was automatically adjusted, based on the value of the `[node_size]` option in a server's configuration file. If merged, this commit introduces a new configuration option that makes it possible for a server operator to adjust the sweep interval and make a CPU/memory tradeoff: [sweep_interval] The specified value represents the number of seconds between successive sweeps. The range of valid values is between 10 and 600. Important operator notes: This is an advanced configuration option that should not be used unless there is empirical data which suggests that the default sweep frequency is either resulting in performance problems or is causing undue load to the server. Note that adjusting the sweep interval may not have the intended effect on the server. Lower values will not always translate to a reduction of memory usage and higher values will not always translate to a reduction of CPU usage and/or load. --- src/ripple/app/main/Application.cpp | 3 ++- src/ripple/core/Config.h | 4 ++++ src/ripple/core/ConfigSections.h | 1 + src/ripple/core/impl/Config.cpp | 9 +++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index b9b60767b..f8f1690f2 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -1065,7 +1065,8 @@ public: { using namespace std::chrono; sweepTimer_.expires_from_now( - seconds{config_->getValueFor(SizedItem::sweepInterval)}); + seconds{config_->SWEEP_INTERVAL.value_or( + config_->getValueFor(SizedItem::sweepInterval))}); sweepTimer_.async_wait(std::move(*optionalCountedHandler)); } } diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 30117ad13..ea5044c2d 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -204,6 +204,10 @@ public: // Thread pool configuration std::size_t WORKERS = 0; + // Normally the sweep timer is automatically deduced based on the node + // size, but we allow admins to explicitly set it in the config. + std::optional SWEEP_INTERVAL; + // Reduce-relay - these parameters are experimental. // Enable reduce-relay features // Validation/proposal reduce-relay feature diff --git a/src/ripple/core/ConfigSections.h b/src/ripple/core/ConfigSections.h index 1c06e75d9..fbe425b43 100644 --- a/src/ripple/core/ConfigSections.h +++ b/src/ripple/core/ConfigSections.h @@ -98,6 +98,7 @@ struct ConfigSection #define SECTION_WORKERS "workers" #define SECTION_LEDGER_REPLAY "ledger_replay" #define SECTION_BETA_RPC_API "beta_rpc_api" +#define SECTION_SWEEP_INTERVAL "sweep_interval" } // namespace ripple diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 08c30f0da..b5a9677e2 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -627,6 +627,15 @@ Config::loadFromString(std::string const& fileContents) if (getSingleSection(secConfig, SECTION_DEBUG_LOGFILE, strTemp, j_)) DEBUG_LOGFILE = strTemp; + if (getSingleSection(secConfig, SECTION_SWEEP_INTERVAL, strTemp, j_)) + { + SWEEP_INTERVAL = beast::lexicalCastThrow(strTemp); + + if (SWEEP_INTERVAL < 10 || SWEEP_INTERVAL > 600) + Throw("Invalid " SECTION_SWEEP_INTERVAL + ": must be between 10 and 600 inclusive"); + } + if (getSingleSection(secConfig, SECTION_WORKERS, strTemp, j_)) WORKERS = beast::lexicalCastThrow(strTemp);