From 8a3d62e756a9dae37b8cf442d05db9de06d34489 Mon Sep 17 00:00:00 2001 From: "will@2012" Date: Sat, 14 Sep 2024 10:06:38 +0800 Subject: [PATCH] perf: add db metrics --- core/state/snapshot/disklayer.go | 10 ++++++++++ core/state/snapshot/metrics.go | 3 +++ triedb/pathdb/disklayer.go | 5 +++++ triedb/pathdb/metrics.go | 3 +++ 4 files changed, 21 insertions(+) diff --git a/core/state/snapshot/disklayer.go b/core/state/snapshot/disklayer.go index 58ce3e365..6b25dc3de 100644 --- a/core/state/snapshot/disklayer.go +++ b/core/state/snapshot/disklayer.go @@ -19,6 +19,7 @@ package snapshot import ( "bytes" "sync" + "time" "github.com/VictoriaMetrics/fastcache" "github.com/ethereum/go-ethereum/common" @@ -136,7 +137,12 @@ func (dl *diskLayer) AccountRLP(hash common.Hash) ([]byte, error) { return blob, nil } // Cache doesn't contain account, pull from disk and cache for later + // TODO: + snapNodeQPS.Mark(1) + startLoadSnapNode := time.Now() blob := rawdb.ReadAccountSnapshot(dl.diskdb, hash) + snapNodeTime.Mark(time.Since(startLoadSnapNode).Nanoseconds()) + dl.cache.Set(hash[:], blob) snapshotCleanAccountMissMeter.Mark(1) @@ -176,7 +182,11 @@ func (dl *diskLayer) Storage(accountHash, storageHash common.Hash) ([]byte, erro return blob, nil } // Cache doesn't contain storage slot, pull from disk and cache for later + // TODO: + snapNodeQPS.Mark(1) + startLoadSnapNode := time.Now() blob := rawdb.ReadStorageSnapshot(dl.diskdb, accountHash, storageHash) + snapNodeTime.Mark(time.Since(startLoadSnapNode).Nanoseconds()) dl.cache.Set(key, blob) snapshotCleanStorageMissMeter.Mark(1) diff --git a/core/state/snapshot/metrics.go b/core/state/snapshot/metrics.go index b2e884588..fbbaf3585 100644 --- a/core/state/snapshot/metrics.go +++ b/core/state/snapshot/metrics.go @@ -50,4 +50,7 @@ var ( snapStorageWriteCounter = metrics.NewRegisteredCounter("state/snapshot/generation/duration/storage/write", nil) // snapStorageCleanCounter measures time spent on deleting storages snapStorageCleanCounter = metrics.NewRegisteredCounter("state/snapshot/generation/duration/storage/clean", nil) + + snapNodeQPS = metrics.NewRegisteredMeter("pbss/snap/node/qps", nil) + snapNodeTime = metrics.NewRegisteredMeter("pbss/snap/node/time", nil) ) diff --git a/triedb/pathdb/disklayer.go b/triedb/pathdb/disklayer.go index d14b29e18..246764455 100644 --- a/triedb/pathdb/disklayer.go +++ b/triedb/pathdb/disklayer.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "sync" + "time" "github.com/VictoriaMetrics/fastcache" "github.com/ethereum/go-ethereum/common" @@ -197,11 +198,15 @@ func (dl *diskLayer) Node(owner common.Hash, path []byte, hash common.Hash) ([]b nBlob []byte nHash common.Hash ) + // TODO: + trieNodeQPS.Mark(1) + startLoadTrieNode := time.Now() if owner == (common.Hash{}) { nBlob, nHash = rawdb.ReadAccountTrieNode(dl.db.diskdb, path) } else { nBlob, nHash = rawdb.ReadStorageTrieNode(dl.db.diskdb, owner, path) } + trieNodeTime.Mark(time.Since(startLoadTrieNode).Nanoseconds()) if nHash != hash { diskFalseMeter.Mark(1) log.Error("Unexpected trie node in disk", "owner", owner, "path", path, "expect", hash, "got", nHash) diff --git a/triedb/pathdb/metrics.go b/triedb/pathdb/metrics.go index ad98cb362..10b47286c 100644 --- a/triedb/pathdb/metrics.go +++ b/triedb/pathdb/metrics.go @@ -56,4 +56,7 @@ var ( PbssUpdateDiffQPS = metrics.NewRegisteredMeter("pbss/difflayer/update/qps", nil) PbssUpdateDiffTime = metrics.NewRegisteredTimer("pbss/difflayer/update/time", nil) + + trieNodeQPS = metrics.NewRegisteredMeter("pbss/trie/node/qps", nil) + trieNodeTime = metrics.NewRegisteredMeter("pbss/trie/node/time", nil) )