From d3b10d22b32d7cce4b22e7bb004d184b1d8a6589 Mon Sep 17 00:00:00 2001 From: aaronbuchwald Date: Thu, 20 Oct 2022 09:53:32 -0700 Subject: [PATCH] Add cache config options for trie db and snapshot (#310) --- eth/backend.go | 17 +++-------------- eth/ethconfig/config.go | 4 ++-- plugin/evm/config.go | 14 ++++++++++++++ plugin/evm/vm.go | 4 ++++ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index 3985ff10c1..b96b1b938f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -125,18 +125,6 @@ func New( if chainDb == nil { return nil, errors.New("chainDb cannot be nil") } - if !config.Pruning && config.TrieDirtyCache > 0 { - // If snapshots are enabled, allocate 2/5 of the TrieDirtyCache memory cap to the snapshot cache - if config.SnapshotCache > 0 { - config.TrieCleanCache += config.TrieDirtyCache * 3 / 5 - config.SnapshotCache += config.TrieDirtyCache * 2 / 5 - } else { - // If snapshots are disabled, the TrieDirtyCache will be written through to the clean cache - // so move the cache allocation from the dirty cache to the clean cache - config.TrieCleanCache += config.TrieDirtyCache - config.TrieDirtyCache = 0 - } - } // round TrieCleanCache and SnapshotCache up to nearest 64MB, since fastcache will mmap // memory in 64MBs chunks. @@ -145,8 +133,9 @@ func New( log.Info( "Allocated trie memory caches", - "clean", common.StorageSize(config.TrieCleanCache)*1024*1024, - "dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024, + "trie clean", common.StorageSize(config.TrieCleanCache)*1024*1024, + "trie dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024, + "snapshot clean", common.StorageSize(config.SnapshotCache)*1024*1024, ) chainConfig, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis, lastAcceptedHash) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 84c582364e..3c3b28a9b2 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -55,10 +55,10 @@ func NewDefaultConfig() Config { LightPeers: 100, UltraLightFraction: 75, DatabaseCache: 512, - TrieCleanCache: 256, + TrieCleanCache: 512, TrieDirtyCache: 256, TrieDirtyCommitTarget: 20, - SnapshotCache: 128, + SnapshotCache: 256, Miner: miner.Config{}, TxPool: core.DefaultTxPoolConfig, RPCGasCap: 25000000, diff --git a/plugin/evm/config.go b/plugin/evm/config.go index 71bbab6c87..3042a06f0b 100644 --- a/plugin/evm/config.go +++ b/plugin/evm/config.go @@ -17,6 +17,10 @@ const ( defaultAcceptorQueueLimit = 64 // Provides 2 minutes of buffer (2s block target) for a commit delay defaultPruningEnabled = true defaultCommitInterval = 4096 + defaultTrieCleanCache = 512 + defaultTrieDirtyCache = 256 + defaultTrieDirtyCommitTarget = 20 + defaultSnapshotCache = 256 defaultSyncableCommitInterval = defaultCommitInterval * 4 defaultSnapshotAsync = true defaultRpcGasCap = 50_000_000 // Default to 50M Gas Limit @@ -85,6 +89,12 @@ type Config struct { RPCGasCap uint64 `json:"rpc-gas-cap"` RPCTxFeeCap float64 `json:"rpc-tx-fee-cap"` + // Cache settings + TrieCleanCache int `json:"trie-clean-cache"` // Size of the trie clean cache (MB) + TrieDirtyCache int `json:"trie-dirty-cache"` // Size of the trie dirty cache (MB) + TrieDirtyCommitTarget int `json:"trie-dirty-commit-target"` // Memory limit to target in the dirty cache before performing a commit (MB) + SnapshotCache int `json:"snapshot-cache"` // Size of the snapshot disk layer clean cache (MB) + // Eth Settings Preimages bool `json:"preimages-enabled"` SnapshotAsync bool `json:"snapshot-async"` @@ -170,6 +180,10 @@ func (c *Config) SetDefaults() { c.ContinuousProfilerFrequency.Duration = defaultContinuousProfilerFrequency c.ContinuousProfilerMaxFiles = defaultContinuousProfilerMaxFiles c.Pruning = defaultPruningEnabled + c.TrieCleanCache = defaultTrieCleanCache + c.TrieDirtyCache = defaultTrieDirtyCache + c.TrieDirtyCommitTarget = defaultTrieDirtyCommitTarget + c.SnapshotCache = defaultSnapshotCache c.AcceptorQueueLimit = defaultAcceptorQueueLimit c.CommitInterval = defaultCommitInterval c.SnapshotAsync = defaultSnapshotAsync diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 48e6d89431..ef34701c0b 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -304,6 +304,10 @@ func (vm *VM) Initialize( vm.ethConfig.AllowUnprotectedTxs = vm.config.AllowUnprotectedTxs vm.ethConfig.Preimages = vm.config.Preimages vm.ethConfig.Pruning = vm.config.Pruning + vm.ethConfig.TrieCleanCache = vm.config.TrieCleanCache + vm.ethConfig.TrieDirtyCache = vm.config.TrieDirtyCache + vm.ethConfig.TrieDirtyCommitTarget = vm.config.TrieDirtyCommitTarget + vm.ethConfig.SnapshotCache = vm.config.SnapshotCache vm.ethConfig.AcceptorQueueLimit = vm.config.AcceptorQueueLimit vm.ethConfig.PopulateMissingTries = vm.config.PopulateMissingTries vm.ethConfig.PopulateMissingTriesParallelism = vm.config.PopulateMissingTriesParallelism