From cee88ec556621027da40de1ba45ea58f55da6463 Mon Sep 17 00:00:00 2001 From: joeylichang Date: Thu, 28 Mar 2024 12:23:54 +0800 Subject: [PATCH] chore: add mgasps metrics chore: block tx metrics chore: change execute and validate block time metrics fix: add flush mutex for nodebufferlist --- core/blockchain.go | 41 +++++++++++++++++++++------------------ core/blockchain_insert.go | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 1dd7490ee3..994f05435b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -83,13 +83,12 @@ var ( blockExecutionTimer = metrics.NewRegisteredTimer("chain/execution", nil) blockWriteTimer = metrics.NewRegisteredTimer("chain/write", nil) - blockWriteExternalTimer = metrics.NewRegisteredTimer("chain/block/write/external", nil) - stateCommitExternalTimer = metrics.NewRegisteredTimer("chain/state/commit/external", nil) + blockWriteExternalTimer = metrics.NewRegisteredTimer("chain/block/write/external", nil) + stateCommitExternalTimer = metrics.NewRegisteredTimer("chain/state/commit/external", nil) triedbCommitExternalTimer = metrics.NewRegisteredTimer("chain/triedb/commit/external", nil) - innerExecutionTimer = metrics.NewRegisteredTimer("chain/inner/execution", nil) + innerExecutionTimer = metrics.NewRegisteredTimer("chain/inner/execution", nil) blockGasUsedGauge = metrics.NewRegisteredGauge("chain/block/gas/used", nil) - mgaspsGauge = metrics.NewRegisteredGauge("chain/mgas/ps", nil) blockReorgMeter = metrics.NewRegisteredMeter("chain/reorg/executes", nil) blockReorgAddMeter = metrics.NewRegisteredMeter("chain/reorg/add", nil) @@ -98,6 +97,9 @@ var ( blockPrefetchExecuteTimer = metrics.NewRegisteredTimer("chain/prefetch/executes", nil) blockPrefetchInterruptMeter = metrics.NewRegisteredMeter("chain/prefetch/interrupts", nil) + mgaspsGauge = metrics.NewRegisteredGauge("chain/execution/mgasps", nil) + blockTxGuage = metrics.NewRegisteredGauge("chain/block/tx", nil) + errInsertionInterrupted = errors.New("insertion is interrupted") errChainStopped = errors.New("blockchain is stopped") errInvalidOldChain = errors.New("invalid old chain") @@ -1460,7 +1462,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. } blockWriteExternalTimer.UpdateSince(start) log.Debug("blockWriteExternalTimer", "duration", common.PrettyDuration(time.Since(start)), "hash", block.Hash()) - + // Commit all cached state changes into underlying memory database. start = time.Now() root, err := state.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number())) @@ -1477,10 +1479,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. } // If we're running an archive node, always flush start = time.Now() - defer func () { + defer func() { triedbCommitExternalTimer.UpdateSince(start) log.Debug("triedbCommitExternalTimer", "duration", common.PrettyDuration(time.Since(start)), "hash", block.Hash()) - } () + }() if bc.cacheConfig.TrieDirtyDisabled { return bc.triedb.Commit(root, false) } @@ -1785,7 +1787,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) } }() - defer func () { + defer func() { DebugInnerExecutionDuration = 0 }() for ; block != nil && err == nil || errors.Is(err, ErrKnownBlock); block, err = it.next() { @@ -1908,16 +1910,16 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) proctime := time.Since(start) // processing + validation // Update the metrics touched during block processing and validation - accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing) - storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing) - snapshotAccountReadTimer.Update(statedb.SnapshotAccountReads) // Account reads are complete(in processing) - snapshotStorageReadTimer.Update(statedb.SnapshotStorageReads) // Storage reads are complete(in processing) - accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete(in validation) - storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete(in validation) - accountHashTimer.Update(statedb.AccountHashes) // Account hashes are complete(in validation) - storageHashTimer.Update(statedb.StorageHashes) // Storage hashes are complete(in validation) - blockExecutionTimer.Update(ptime) // The time spent on block execution - blockValidationTimer.Update(vtime) // The time spent on block validation + accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing) + storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing) + snapshotAccountReadTimer.Update(statedb.SnapshotAccountReads) // Account reads are complete(in processing) + snapshotStorageReadTimer.Update(statedb.SnapshotStorageReads) // Storage reads are complete(in processing) + accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete(in validation) + storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete(in validation) + accountHashTimer.Update(statedb.AccountHashes) // Account hashes are complete(in validation) + storageHashTimer.Update(statedb.StorageHashes) // Storage hashes are complete(in validation) + blockExecutionTimer.Update(ptime) // The time spent on block execution + blockValidationTimer.Update(vtime) // The time spent on block validation innerExecutionTimer.Update(DebugInnerExecutionDuration) @@ -1946,6 +1948,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) blockWriteTimer.UpdateSince(wstart) blockInsertTimer.UpdateSince(start) + blockTxGuage.Update(int64(block.Transactions().Len())) log.Debug("New payload db write metrics", "hash", block.Hash(), "insert", common.PrettyDuration(time.Since(start)), "writeDB", common.PrettyDuration(time.Since(wstart)), "writeBlock", common.PrettyDuration(time.Since(wstart)), "accountCommit", common.PrettyDuration(statedb.AccountCommits), "storageCommit", common.PrettyDuration(statedb.StorageCommits), "snapshotCommits", common.PrettyDuration(statedb.SnapshotCommits), "triedbCommit", common.PrettyDuration(statedb.TrieDBCommits)) @@ -1959,7 +1962,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) } trieDiffNodes, trieBufNodes, trieImmutableBufNodes, _ := bc.triedb.Size() stats.report(chain, it.index, snapDiffItems, snapBufItems, trieDiffNodes, trieBufNodes, trieImmutableBufNodes, setHead) - blockGasUsedGauge.Update(int64(block.GasUsed())/1000000) + blockGasUsedGauge.Update(int64(block.GasUsed()) / 1000000) if !setHead { // After merge we expect few side chains. Simply count diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index 82a480d0be..d9000326eb 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -60,7 +60,7 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn "blocks", st.processed, "txs", txs, "mgas", float64(st.usedGas) / 1000000, "elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed), } - mgaspsGauge.Update(int64(st.usedGas)*1000/int64(elapsed)) + mgaspsGauge.Update(int64(float64(st.usedGas) * 1000 / float64(elapsed))) if timestamp := time.Unix(int64(end.Time()), 0); time.Since(timestamp) > time.Minute { context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...) }