Skip to content

Commit 921afc5

Browse files
andyzhang2023andyzhang2023
authored andcommitted
add metrics for parallel processor (bnb-chain#254)
Co-authored-by: andyzhang2023 <andyzhang2023@gmail.com>
1 parent ffe9dc0 commit 921afc5

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

core/blockchain.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ var (
9999
txDAGGenerateTimer = metrics.NewRegisteredTimer("chain/block/txdag/gen", nil)
100100
txDAGReaderChanGauge = metrics.NewRegisteredGauge("chain/block/txdag/reader/chan", nil)
101101

102+
// expensive metrics
103+
// metrics of reasons why a block is processed in a parallel EVM or serial EVM
104+
parallelConditionTooDeep = metrics.NewRegisteredMeter("chain/parallel/condition/toodeep", nil)
105+
parallelConditionTxDAGMiss = metrics.NewRegisteredMeter("chain/parallel/condition/txdagmiss", nil)
106+
parallelConditionByzantium = metrics.NewRegisteredMeter("chain/parallel/condition/byzantium", nil)
107+
108+
// metrics to identify whether a block is processed in parallel EVM or serial EVM
109+
parallelInSequencial = metrics.NewRegisteredMeter("chain/parallel/sequencial", nil)
110+
parallelTxDepth = metrics.NewRegisteredMeter("chain/parallel/txdepth", nil)
111+
// TxDepthRatio = TxDepth / TxNum * 100
112+
parallelTxDepthRatio = metrics.NewRegisteredGauge("chain/parallel/txdepth/ratio", nil)
113+
102114
parallelTxNumMeter = metrics.NewRegisteredMeter("chain/parallel/txs", nil)
103115
parallelEnableMeter = metrics.NewRegisteredMeter("chain/parallel/enable", nil)
104116
parallelFallbackMeter = metrics.NewRegisteredMeter("chain/parallel/fallback", nil)
@@ -1766,11 +1778,36 @@ func (bc *BlockChain) useSerialProcessor(block *types.Block) (bool, bool) {
17661778
// if the dependencies are too deep, we will fallback to serial processing
17671779
txCount := len(block.Transactions())
17681780
_, depth := BuildTxLevels(txCount, bc.vmConfig.TxDAG)
1769-
tooDeep := float64(depth)/float64(txCount) > bc.vmConfig.TxDAGMaxDepthRatio
1781+
var depthRatio float64
1782+
1783+
if txCount > 0 {
1784+
depthRatio = float64(depth) / float64(txCount)
1785+
} else {
1786+
depthRatio = 0
1787+
}
1788+
tooDeep := depthRatio > bc.vmConfig.TxDAGMaxDepthRatio
17701789
isByzantium := bc.chainConfig.IsByzantium(block.Number())
17711790

17721791
txDAGMissButNecessary := bc.vmConfig.TxDAG == nil && (bc.vmConfig.EnableParallelUnorderedMerge || bc.vmConfig.EnableTxParallelMerge)
17731792
useSerialProcessor := !bc.vmConfig.EnableParallelExec || txDAGMissButNecessary || tooDeep || !isByzantium
1793+
1794+
// mark the metrics
1795+
defer func() {
1796+
parallelTxDepth.Mark(int64(depth))
1797+
parallelTxDepthRatio.Update(int64(depthRatio * 100))
1798+
// put reasons in expensive metrics
1799+
if metrics.EnabledExpensive {
1800+
if tooDeep {
1801+
parallelConditionTooDeep.Mark(1)
1802+
}
1803+
if bc.vmConfig.TxDAG == nil {
1804+
parallelConditionTxDAGMiss.Mark(1)
1805+
}
1806+
if isByzantium {
1807+
parallelConditionByzantium.Mark(1)
1808+
}
1809+
}
1810+
}()
17741811
return useSerialProcessor, tooDeep
17751812
}
17761813

@@ -2037,6 +2074,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
20372074
// Process block using the parent state as reference point
20382075
pstart = time.Now()
20392076
if useSerialProcessor {
2077+
parallelInSequencial.Mark(1)
20402078
receipts, logs, usedGas, err = bc.serialProcessor.Process(block, statedb, bc.vmConfig)
20412079
blockProcessedInParallel = false
20422080
} else {

0 commit comments

Comments
 (0)