Skip to content

Commit

Permalink
Merge pull request bnb-chain#4 from flywukong/IO-metrics
Browse files Browse the repository at this point in the history
add preload metrics
  • Loading branch information
forcodedancing authored Feb 24, 2022
2 parents aded4df + a620d34 commit 2530f64
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 6 additions & 3 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (

var (
emptyCodeHash = crypto.Keccak256(nil)
syncPreloadCost = metrics.NewRegisteredTimer("state/preload/sync/delay", nil)
minerPreloadCost = metrics.NewRegisteredTimer("state/preload/miner/delay", nil)
syncPreloadCounter = metrics.NewRegisteredCounter("state/preload/sync/counter", nil)
minerPreloadCounter = metrics.NewRegisteredCounter("state/preload/miner/counter", nil)
syncOverheadCost = metrics.NewRegisteredTimer("state/overhead/sync/delay", nil)
minerOverheadCost = metrics.NewRegisteredTimer("state/overhead/miner/delay", nil)
syncOverheadCounter = metrics.NewRegisteredCounter("state/overhead/sync/counter", nil)
Expand Down Expand Up @@ -361,15 +365,14 @@ func (s *StateObject) finalise(prefetch bool) {
minerOverheadCounter.Inc(overheadCost.Nanoseconds())
}
}()

start := time.Now()
for key, value := range s.dirtyStorage {
s.pendingStorage[key] = value
if value != s.originStorage[key] {
start := time.Now()
slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(key[:])) // Copy needed for closure
overheadCost += time.Since(start)
}
}
overheadCost = time.Since(start)
if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != emptyRoot {
s.db.prefetcher.prefetch(s.data.Root, slotsToPrefetch, s.addrHash)
}
Expand Down
22 changes: 21 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ var (
totalMinerIOCost = metrics.NewRegisteredTimer("state/cache/miner/delay", nil)
totalSyncIOCounter = metrics.NewRegisteredCounter("state/cache/sync/counter", nil)
totalMinerIOCounter = metrics.NewRegisteredCounter("state/cache/miner/counter", nil)
//TotalAccountIOCost
)

type proofList [][]byte
Expand Down Expand Up @@ -645,9 +644,30 @@ func (s *StateDB) TryPreload(block *types.Block, signer types.Signer) {
accounts[*tx.To()] = true
}
}

var overheadCost time.Duration
defer func() {
goid := cachemetrics.Goid()
isSyncMainProcess := cachemetrics.IsSyncMainRoutineID(goid)
isMinerMainProcess := cachemetrics.IsMinerMainRoutineID(goid)
// record metrics of syncing main process
if isSyncMainProcess {
syncPreloadCost.Update(overheadCost)
syncPreloadCounter.Inc(overheadCost.Nanoseconds())
}
// record metrics of mining main process
if isMinerMainProcess {
minerPreloadCost.Update(overheadCost)
minerPreloadCounter.Inc(overheadCost.Nanoseconds())
}
}()

start := time.Now()
for account := range accounts {
accountsSlice = append(accountsSlice, account)
}
overheadCost = time.Since(start)

if len(accountsSlice) >= preLoadLimit && len(accountsSlice) > runtime.NumCPU() {
objsChan := make(chan []*StateObject, runtime.NumCPU())
for i := 0; i < runtime.NumCPU(); i++ {
Expand Down

0 comments on commit 2530f64

Please sign in to comment.