mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
refactor: Clamp worker threads in ChainstateManager constructor
This ensures the options are applied consistently from contexts where
they might not pass through the args manager, such as in some tests, or
when used through the kernel library.
This is similar to the patch applied in 09ef322acc
.
This commit is contained in:
parent
e546b4e1a0
commit
8f85d36d68
5 changed files with 7 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
#ifndef BITCOIN_CHECKQUEUE_H
|
#ifndef BITCOIN_CHECKQUEUE_H
|
||||||
#define BITCOIN_CHECKQUEUE_H
|
#define BITCOIN_CHECKQUEUE_H
|
||||||
|
|
||||||
|
#include <logging.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/threadnames.h>
|
#include <util/threadnames.h>
|
||||||
|
@ -130,6 +131,7 @@ public:
|
||||||
explicit CCheckQueue(unsigned int batch_size, int worker_threads_num)
|
explicit CCheckQueue(unsigned int batch_size, int worker_threads_num)
|
||||||
: nBatchSize(batch_size)
|
: nBatchSize(batch_size)
|
||||||
{
|
{
|
||||||
|
LogInfo("Script verification uses %d additional threads", worker_threads_num);
|
||||||
m_worker_threads.reserve(worker_threads_num);
|
m_worker_threads.reserve(worker_threads_num);
|
||||||
for (int n = 0; n < worker_threads_num; ++n) {
|
for (int n = 0; n < worker_threads_num; ++n) {
|
||||||
m_worker_threads.emplace_back([this, n]() {
|
m_worker_threads.emplace_back([this, n]() {
|
||||||
|
|
|
@ -60,8 +60,7 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
|
||||||
script_threads += GetNumCores();
|
script_threads += GetNumCores();
|
||||||
}
|
}
|
||||||
// Subtract 1 because the main thread counts towards the par threads.
|
// Subtract 1 because the main thread counts towards the par threads.
|
||||||
opts.worker_threads_num = std::clamp(script_threads - 1, 0, MAX_SCRIPTCHECK_THREADS);
|
opts.worker_threads_num = script_threads - 1;
|
||||||
LogPrintf("Script verification uses %d additional threads\n", opts.worker_threads_num);
|
|
||||||
|
|
||||||
if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
|
if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
|
||||||
// 1. When supplied with a max_size of 0, both the signature cache and
|
// 1. When supplied with a max_size of 0, both the signature cache and
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
|
|
||||||
/** Maximum number of dedicated script-checking threads allowed */
|
|
||||||
static constexpr int MAX_SCRIPTCHECK_THREADS{15};
|
|
||||||
/** -par default (number of script-checking threads, 0 = auto) */
|
/** -par default (number of script-checking threads, 0 = auto) */
|
||||||
static constexpr int DEFAULT_SCRIPTCHECK_THREADS{0};
|
static constexpr int DEFAULT_SCRIPTCHECK_THREADS{0};
|
||||||
|
|
||||||
|
|
|
@ -6260,7 +6260,7 @@ static ChainstateManager::Options&& Flatten(ChainstateManager::Options&& opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options)
|
ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options)
|
||||||
: m_script_check_queue{/*batch_size=*/128, options.worker_threads_num},
|
: m_script_check_queue{/*batch_size=*/128, std::clamp(options.worker_threads_num, 0, MAX_SCRIPTCHECK_THREADS)},
|
||||||
m_interrupt{interrupt},
|
m_interrupt{interrupt},
|
||||||
m_options{Flatten(std::move(options))},
|
m_options{Flatten(std::move(options))},
|
||||||
m_blockman{interrupt, std::move(blockman_options)},
|
m_blockman{interrupt, std::move(blockman_options)},
|
||||||
|
|
|
@ -78,6 +78,9 @@ static constexpr int DEFAULT_CHECKLEVEL{3};
|
||||||
// Setting the target to >= 550 MiB will make it likely we can respect the target.
|
// Setting the target to >= 550 MiB will make it likely we can respect the target.
|
||||||
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
|
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
|
||||||
|
|
||||||
|
/** Maximum number of dedicated script-checking threads allowed */
|
||||||
|
static constexpr int MAX_SCRIPTCHECK_THREADS{15};
|
||||||
|
|
||||||
/** Current sync state passed to tip changed callbacks. */
|
/** Current sync state passed to tip changed callbacks. */
|
||||||
enum class SynchronizationState {
|
enum class SynchronizationState {
|
||||||
INIT_REINDEX,
|
INIT_REINDEX,
|
||||||
|
|
Loading…
Reference in a new issue