Skip to content

Commit

Permalink
Improve automatic tuning of thread pool:
Browse files Browse the repository at this point in the history
The job queue can automatically tune the number of threads that
it creates based on the number of processors or processor cores
that are available.

The existing tuning was very conservative, limiting the maximum
number of threads to only 6.

Adjust the new algorithm to allow a larger number of threads and
allow server administrators to override the value in the config
file.
  • Loading branch information
mtrippled authored and nbougalis committed Jun 9, 2017
1 parent cb91d56 commit 68b8ffd
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
8 changes: 8 additions & 0 deletions doc/rippled-example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,14 @@
#
#
#
# [workers]
#
# Configures the number of threads for processing work submitted by peers
# and clients. If not specified, then the value is automatically determined
# by factors including the number of system processors and whether this
# node is a validator.
#
#
#-------------------------------------------------------------------------------
#
# 4. HTTPS Client
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,9 @@ class ApplicationImp
bool ApplicationImp::setup()
{
// VFALCO NOTE: 0 means use heuristics to determine the thread count.
m_jobQueue->setThreadCount (0, config_->standalone());
m_jobQueue->setThreadCount (config_->WORKERS, config_->standalone(),
config_->exists (SECTION_VALIDATOR_TOKEN) ||
config_->exists (SECTION_VALIDATION_SEED));

// We want to intercept and wait for CTRL-C to terminate the process
m_signals.add (SIGINT);
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class Config : public BasicConfig
std::string SSL_VERIFY_FILE;
std::string SSL_VERIFY_DIR;

// Thread pool configuration
std::size_t WORKERS = 0;

// These override the command line client settings
boost::optional<boost::asio::ip::address_v4> rpc_ip;
boost::optional<std::uint16_t> rpc_port;
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 @@ -69,6 +69,7 @@ struct ConfigSection
#define SECTION_VALIDATORS "validators"
#define SECTION_VALIDATOR_TOKEN "validator_token"
#define SECTION_VETO_AMENDMENTS "veto_amendments"
#define SECTION_WORKERS "workers"

} // ripple

Expand Down
3 changes: 2 additions & 1 deletion src/ripple/core/JobQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ class JobQueue

/** Set the number of thread serving the job queue to precisely this number.
*/
void setThreadCount (int c, bool const standaloneMode);
void setThreadCount (int c, bool const standaloneMode,
bool const validator=true);

/** Return a scoped LoadEvent.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/core/impl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ void Config::loadFromString (std::string const& fileContents)
if (getSingleSection (secConfig, SECTION_DEBUG_LOGFILE, strTemp, j_))
DEBUG_LOGFILE = strTemp;

if (getSingleSection (secConfig, SECTION_WORKERS, strTemp, j_))
WORKERS = beast::lexicalCastThrow <std::size_t> (strTemp);

// Do not load trusted validator configuration for standalone mode
if (! RUN_STANDALONE)
{
Expand Down
19 changes: 14 additions & 5 deletions src/ripple/core/impl/JobQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ JobQueue::getJobCountGE (JobType t) const
}

void
JobQueue::setThreadCount (int c, bool const standaloneMode)
JobQueue::setThreadCount (int c, bool const standaloneMode,
bool const validator)
{
if (standaloneMode)
{
Expand All @@ -161,10 +162,18 @@ JobQueue::setThreadCount (int c, bool const standaloneMode)
else if (c == 0)
{
c = static_cast<int>(std::thread::hardware_concurrency());
c = 2 + std::min (c, 4); // I/O will bottleneck

JLOG(m_journal.info()) << "Auto-tuning to " << c <<
" validation/transaction/proposal threads";
if (validator)
c = 2 + std::min(c, 4); // I/O will bottleneck
else
c *= 2; // Tested to improve stability under high RPC load.
JLOG (m_journal.info()) << "Auto-tuning to " << c <<
" validation/transaction/proposal threads for " <<
(validator ? "" : "non-") << "validator.";
}
else
{
JLOG (m_journal.info()) << "Configured " << c <<
" validation/transaction/proposal threads.";
}

m_workers.setNumberOfThreads (c);
Expand Down

0 comments on commit 68b8ffd

Please sign in to comment.