aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-10-19 21:42:54 +0800
committerGitHub <noreply@github.com>2016-10-19 21:42:54 +0800
commit8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec (patch)
tree1c0c56408bcf674881829b5eaff3d019b8dffc47
parentd48e6ae66f09b1061e2e7e54c750b20e14a1e45a (diff)
parent4f46bd19d0b123327596785dc3975d5e4008d761 (diff)
downloadgo-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.tar
go-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.tar.gz
go-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.tar.bz2
go-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.tar.lz
go-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.tar.xz
go-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.tar.zst
go-tangerine-8048f4d4f619e3d34494fb9dcb2bb3b91bca6bec.zip
Merge pull request #3173 from karalabe/parametrized-trie-cache-get
cmd, core/state: allow configurable trie cache generations
-rw-r--r--cmd/geth/chaincmd.go2
-rw-r--r--cmd/geth/main.go3
-rw-r--r--cmd/geth/usage.go6
-rw-r--r--cmd/utils/flags.go20
-rw-r--r--core/state/statedb.go10
5 files changed, 29 insertions, 12 deletions
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index d7cdf1064..c41375c4d 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -99,6 +99,7 @@ func importChain(ctx *cli.Context) error {
utils.Fatalf("Failed to read database stats: %v", err)
}
fmt.Println(stats)
+ fmt.Printf("Trie cache misses: %d\n\n", trie.CacheMisses())
// Compact the entire database to more accurately measure disk io and print the stats
start = time.Now()
@@ -113,7 +114,6 @@ func importChain(ctx *cli.Context) error {
utils.Fatalf("Failed to read database stats: %v", err)
}
fmt.Println(stats)
- fmt.Println("Trie cache misses:", trie.CacheMisses())
}
return nil
}
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 65311ca41..ccc42d3cf 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -134,8 +134,9 @@ participating.
utils.KeyStoreDirFlag,
utils.OlympicFlag,
utils.FastSyncFlag,
- utils.CacheFlag,
utils.LightKDFFlag,
+ utils.CacheFlag,
+ utils.TrieCacheGenFlag,
utils.JSpathFlag,
utils.ListenPortFlag,
utils.MaxPeersFlag,
diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go
index dc1788aad..2cb6e77e8 100644
--- a/cmd/geth/usage.go
+++ b/cmd/geth/usage.go
@@ -73,7 +73,13 @@ var AppHelpFlagGroups = []flagGroup{
utils.IdentityFlag,
utils.FastSyncFlag,
utils.LightKDFFlag,
+ },
+ },
+ {
+ Name: "PERFORMANCE TUNING",
+ Flags: []cli.Flag{
utils.CacheFlag,
+ utils.TrieCacheGenFlag,
},
},
{
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 0c5206a17..1859f735d 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -141,11 +141,6 @@ var (
Usage: "Document Root for HTTPClient file scheme",
Value: DirectoryString{homeDir()},
}
- CacheFlag = cli.IntFlag{
- Name: "cache",
- Usage: "Megabytes of memory allocated to internal caching (min 16MB / database forced)",
- Value: 128,
- }
FastSyncFlag = cli.BoolFlag{
Name: "fast",
Usage: "Enable fast syncing through state downloads",
@@ -154,6 +149,17 @@ var (
Name: "lightkdf",
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
}
+ // Performance tuning settings
+ CacheFlag = cli.IntFlag{
+ Name: "cache",
+ Usage: "Megabytes of memory allocated to internal caching (min 16MB / database forced)",
+ Value: 128,
+ }
+ TrieCacheGenFlag = cli.IntFlag{
+ Name: "trie-cache-gens",
+ Usage: "Number of trie node generations to keep in memory",
+ Value: int(state.MaxTrieCacheGen),
+ }
// Fork settings
SupportDAOFork = cli.BoolFlag{
Name: "support-dao-fork",
@@ -721,6 +727,10 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
}
ethConf.PowTest = true
}
+ // Override any global options pertaining to the Ethereum protocol
+ if gen := ctx.GlobalInt(TrieCacheGenFlag.Name); gen > 0 {
+ state.MaxTrieCacheGen = uint16(gen)
+ }
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return eth.New(ctx, ethConf)
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 0e46e5e2c..6a24d2865 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -38,14 +38,14 @@ import (
// created.
var StartingNonce uint64
+// Trie cache generation limit after which to evic trie nodes from memory.
+var MaxTrieCacheGen = uint16(120)
+
const (
// Number of past tries to keep. This value is chosen such that
// reasonable chain reorg depths will hit an existing trie.
maxPastTries = 12
- // Trie cache generation limit.
- maxTrieCacheGen = 120
-
// Number of codehash->size associations to keep.
codeSizeCacheSize = 100000
)
@@ -89,7 +89,7 @@ type StateDB struct {
// Create a new state from a given trie
func New(root common.Hash, db ethdb.Database) (*StateDB, error) {
- tr, err := trie.NewSecure(root, db, maxTrieCacheGen)
+ tr, err := trie.NewSecure(root, db, MaxTrieCacheGen)
if err != nil {
return nil, err
}
@@ -158,7 +158,7 @@ func (self *StateDB) openTrie(root common.Hash) (*trie.SecureTrie, error) {
return &tr, nil
}
}
- return trie.NewSecure(root, self.db, maxTrieCacheGen)
+ return trie.NewSecure(root, self.db, MaxTrieCacheGen)
}
func (self *StateDB) pushTrie(t *trie.SecureTrie) {