mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
coins: derive batch_write_bytes
from -dbcache
when unspecified
Extend `ReadCoinsViewArgs` to dynamically set `batch_write_bytes` using `GetDbBatchSize()` when `-dbbatchsize` is not explicitly provided. This enables larger LevelDB batches on systems with high `-dbcache` values, which reduces the number of write operations during UTXO flushes and improves I/O efficiency, particularly during AssumeUTXO loads and IBD.
This commit is contained in:
parent
a32489a175
commit
8fd522b223
3 changed files with 11 additions and 8 deletions
|
@ -48,6 +48,7 @@
|
||||||
#include <node/caches.h>
|
#include <node/caches.h>
|
||||||
#include <node/chainstate.h>
|
#include <node/chainstate.h>
|
||||||
#include <node/chainstatemanager_args.h>
|
#include <node/chainstatemanager_args.h>
|
||||||
|
#include <node/coins_view_args.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
#include <node/kernel_notifications.h>
|
#include <node/kernel_notifications.h>
|
||||||
|
@ -487,7 +488,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
|
||||||
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
|
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: calculated from the `-dbcache` value or %u if not set)", node::GetDbBatchSize(DEFAULT_DB_CACHE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE >> 20, DEFAULT_DB_CACHE >> 20), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE >> 20, DEFAULT_DB_CACHE >> 20), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-allowignoredconf", strprintf("For backwards compatibility, treat an unused %s file in the datadir as a warning, not an error.", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-allowignoredconf", strprintf("For backwards compatibility, treat an unused %s file in the datadir as a warning, not an error.", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <kernel/caches.h>
|
||||||
|
|
||||||
#include <node/coins_view_args.h>
|
#include <node/coins_view_args.h>
|
||||||
|
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
|
@ -10,7 +12,9 @@
|
||||||
namespace node {
|
namespace node {
|
||||||
void ReadCoinsViewArgs(const ArgsManager& args, CoinsViewOptions& options)
|
void ReadCoinsViewArgs(const ArgsManager& args, CoinsViewOptions& options)
|
||||||
{
|
{
|
||||||
if (auto value = args.GetIntArg("-dbbatchsize")) options.batch_write_bytes = *value;
|
if (const auto value = args.GetIntArg("-dbbatchsize")) options.batch_write_bytes = *value;
|
||||||
if (auto value = args.GetIntArg("-dbcrashratio")) options.simulate_crash_ratio = *value;
|
else options.batch_write_bytes = GetDbBatchSize(args.GetIntArg("-dbcache", DEFAULT_KERNEL_CACHE));
|
||||||
|
|
||||||
|
if (const auto value = args.GetIntArg("-dbcrashratio")) options.simulate_crash_ratio = *value;
|
||||||
}
|
}
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <coins.h>
|
#include <coins.h>
|
||||||
#include <dbwrapper.h>
|
#include <dbwrapper.h>
|
||||||
|
#include <kernel/caches.h>
|
||||||
#include <kernel/cs_main.h>
|
#include <kernel/cs_main.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
|
@ -21,16 +22,13 @@
|
||||||
class COutPoint;
|
class COutPoint;
|
||||||
class uint256;
|
class uint256;
|
||||||
|
|
||||||
//! -dbbatchsize default (bytes)
|
|
||||||
static const int64_t nDefaultDbBatchSize = 16 << 20;
|
|
||||||
|
|
||||||
//! User-controlled performance and debug options.
|
//! User-controlled performance and debug options.
|
||||||
struct CoinsViewOptions {
|
struct CoinsViewOptions {
|
||||||
//! Maximum database write batch size in bytes.
|
//! Maximum database write batch size in bytes.
|
||||||
size_t batch_write_bytes = nDefaultDbBatchSize;
|
size_t batch_write_bytes{DEFAULT_DB_CACHE_BATCH};
|
||||||
//! If non-zero, randomly exit when the database is flushed with (1/ratio)
|
//! If non-zero, randomly exit when the database is flushed with (1/ratio)
|
||||||
//! probability.
|
//! probability.
|
||||||
int simulate_crash_ratio = 0;
|
int simulate_crash_ratio{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
/** CCoinsView backed by the coin database (chainstate/) */
|
/** CCoinsView backed by the coin database (chainstate/) */
|
||||||
|
|
Loading…
Add table
Reference in a new issue