From 91e3a3ea1f06ab1da489e364c312afdeb7bf9596 Mon Sep 17 00:00:00 2001 From: "will@2012" Date: Mon, 20 May 2024 22:38:05 +0800 Subject: [PATCH] perf: add more log --- core/rawdb/accessors_trie.go | 17 ++++++++++++++++- ethdb/leveldb/leveldb.go | 14 +++++++++++--- ethdb/pebble/pebble.go | 7 +++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/rawdb/accessors_trie.go b/core/rawdb/accessors_trie.go index cde9e1bcd..f92a4bf2e 100644 --- a/core/rawdb/accessors_trie.go +++ b/core/rawdb/accessors_trie.go @@ -228,7 +228,22 @@ func HasTrieNode(db ethdb.KeyValueReader, owner common.Hash, path []byte, hash c func ReadTrieNode(db ethdb.KeyValueReader, owner common.Hash, path []byte, hash common.Hash, scheme string) []byte { switch scheme { case HashScheme: - return ReadLegacyTrieNode(db, hash) + var ( + blob []byte + start time.Time + ) + start = time.Now() + blob = ReadLegacyTrieNode(db, hash) + if owner == (common.Hash{}) { + if metrics.EnabledExpensive { + rawdbGetAccountTrieNodeTimer.UpdateSince(start) + } + } else { + if metrics.EnabledExpensive { + rawdbGetStorageTrieNodeTimer.UpdateSince(start) + } + } + return blob case PathScheme: var ( blob []byte diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index ddda5daef..29054fdad 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -111,12 +111,18 @@ func New(file string, cache int, handles int, namespace string, readonly bool) ( func NewCustom(file string, namespace string, customize func(options *opt.Options)) (*Database, error) { options := configureOptions(customize) logger := log.New("database", file) - usedCache := options.GetBlockCacheCapacity() + options.GetWriteBuffer()*2 - logCtx := []interface{}{"cache", common.StorageSize(usedCache), "handles", options.GetOpenFilesCacheCapacity()} + // usedCache := options.GetBlockCacheCapacity() + options.GetWriteBuffer()*2 + logCtx := []interface{}{"handles", options.GetOpenFilesCacheCapacity()} if options.ReadOnly { logCtx = append(logCtx, "readonly", "true") } - logger.Info("Allocated cache and file handles", logCtx...) + if options.BlockCacheCapacity != 0 { + logCtx = append(logCtx, "block_cache_size", common.StorageSize(options.BlockCacheCapacity)) + } + if options.WriteBuffer != 0 { + logCtx = append(logCtx, "memory_table_size", common.StorageSize(options.WriteBuffer)) + } + logger.Info("Level db Allocated cache and file handles", logCtx...) // Open the db and recover any potential corruptions db, err := leveldb.OpenFile(file, options) @@ -313,6 +319,8 @@ func (db *Database) meter(refresh time.Duration, namespace string) { merr = err continue } + fmt.Printf("loop print level db stats db_metrics=\n%v\n", stats) + db.log.Info("loop print level db stats", "stats", stats) // Iterate over all the leveldbTable rows, and accumulate the entries for j := 0; j < len(compactions[i%2]); j++ { compactions[i%2][j] = 0 diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index 0bf1bfeac..8c6495a7c 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -183,8 +183,8 @@ func New(file string, cache int, handles int, namespace string, readonly bool, e memTableSize = maxMemTableSize - 1 } - logger.Info("Allocated cache and file handles", "cache", common.StorageSize(cache*1024*1024), - "handles", handles, "memory table", common.StorageSize(memTableSize)) + logger.Info("Pebble db Allocated cache and file handles", "handles", handles, "block_cache_size", common.StorageSize(cache*1024*1024), + "memory_table_size", common.StorageSize(memTableSize)) db := &Database{ fn: file, @@ -544,6 +544,9 @@ func (d *Database) meter(refresh time.Duration, namespace string) { nonLevel0CompCount = int64(d.nonLevel0Comp.Load()) level0CompCount = int64(d.level0Comp.Load()) ) + fmt.Printf("loop print pebble db stats db_metrics=\n%v\n", stats) + d.log.Info("loop print pebble db stats", "comp_time", compTime, "write_delay_count", writeDelayCount, "write_delay_time", + writeDelayTime, "non_level0_comp_count", nonLevel0CompCount, "level0_comp_count", level0CompCount) writeDelayTimes[i%2] = writeDelayTime writeDelayCounts[i%2] = writeDelayCount compTimes[i%2] = compTime