Skip to content

Commit

Permalink
add metrics for parallel processor (#254)
Browse files Browse the repository at this point in the history
Co-authored-by: andyzhang2023 <[email protected]>
  • Loading branch information
andyzhang2023 and andyzhang2023 authored Jan 15, 2025
1 parent dfab164 commit 9bb6f30
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ var (
txDAGGenerateTimer = metrics.NewRegisteredTimer("chain/block/txdag/gen", nil)
txDAGReaderChanGauge = metrics.NewRegisteredGauge("chain/block/txdag/reader/chan", nil)

// expensive metrics
// metrics of reasons why a block is processed in a parallel EVM or serial EVM
parallelConditionTooDeep = metrics.NewRegisteredMeter("chain/parallel/condition/toodeep", nil)
parallelConditionTxDAGMiss = metrics.NewRegisteredMeter("chain/parallel/condition/txdagmiss", nil)
parallelConditionByzantium = metrics.NewRegisteredMeter("chain/parallel/condition/byzantium", nil)

// metrics to identify whether a block is processed in parallel EVM or serial EVM
parallelInSequencial = metrics.NewRegisteredMeter("chain/parallel/sequencial", nil)
parallelTxDepth = metrics.NewRegisteredMeter("chain/parallel/txdepth", nil)
// TxDepthRatio = TxDepth / TxNum * 100
parallelTxDepthRatio = metrics.NewRegisteredGauge("chain/parallel/txdepth/ratio", nil)

parallelTxNumMeter = metrics.NewRegisteredMeter("chain/parallel/txs", nil)
parallelEnableMeter = metrics.NewRegisteredMeter("chain/parallel/enable", nil)
parallelFallbackMeter = metrics.NewRegisteredMeter("chain/parallel/fallback", nil)
Expand Down Expand Up @@ -1765,11 +1777,36 @@ func (bc *BlockChain) useSerialProcessor(block *types.Block) (bool, bool) {
// if the dependencies are too deep, we will fallback to serial processing
txCount := len(block.Transactions())
_, depth := BuildTxLevels(txCount, bc.vmConfig.TxDAG)
tooDeep := float64(depth)/float64(txCount) > bc.vmConfig.TxDAGMaxDepthRatio
var depthRatio float64

if txCount > 0 {
depthRatio = float64(depth) / float64(txCount)
} else {
depthRatio = 0
}
tooDeep := depthRatio > bc.vmConfig.TxDAGMaxDepthRatio
isByzantium := bc.chainConfig.IsByzantium(block.Number())

txDAGMissButNecessary := bc.vmConfig.TxDAG == nil && (bc.vmConfig.EnableParallelUnorderedMerge || bc.vmConfig.EnableTxParallelMerge)
useSerialProcessor := !bc.vmConfig.EnableParallelExec || txDAGMissButNecessary || tooDeep || !isByzantium

// mark the metrics
defer func() {
parallelTxDepth.Mark(int64(depth))
parallelTxDepthRatio.Update(int64(depthRatio * 100))
// put reasons in expensive metrics
if metrics.EnabledExpensive {
if tooDeep {
parallelConditionTooDeep.Mark(1)
}
if bc.vmConfig.TxDAG == nil {
parallelConditionTxDAGMiss.Mark(1)
}
if isByzantium {
parallelConditionByzantium.Mark(1)
}
}
}()
return useSerialProcessor, tooDeep
}

Expand Down Expand Up @@ -2036,6 +2073,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
// Process block using the parent state as reference point
pstart = time.Now()
if useSerialProcessor {
parallelInSequencial.Mark(1)
receipts, logs, usedGas, err = bc.serialProcessor.Process(block, statedb, bc.vmConfig)
blockProcessedInParallel = false
} else {
Expand Down

0 comments on commit 9bb6f30

Please sign in to comment.