|
99 | 99 | txDAGGenerateTimer = metrics.NewRegisteredTimer("chain/block/txdag/gen", nil) |
100 | 100 | txDAGReaderChanGauge = metrics.NewRegisteredGauge("chain/block/txdag/reader/chan", nil) |
101 | 101 |
|
| 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 | + |
102 | 114 | parallelTxNumMeter = metrics.NewRegisteredMeter("chain/parallel/txs", nil) |
103 | 115 | parallelEnableMeter = metrics.NewRegisteredMeter("chain/parallel/enable", nil) |
104 | 116 | parallelFallbackMeter = metrics.NewRegisteredMeter("chain/parallel/fallback", nil) |
@@ -1766,11 +1778,36 @@ func (bc *BlockChain) useSerialProcessor(block *types.Block) (bool, bool) { |
1766 | 1778 | // if the dependencies are too deep, we will fallback to serial processing |
1767 | 1779 | txCount := len(block.Transactions()) |
1768 | 1780 | _, 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 |
1770 | 1789 | isByzantium := bc.chainConfig.IsByzantium(block.Number()) |
1771 | 1790 |
|
1772 | 1791 | txDAGMissButNecessary := bc.vmConfig.TxDAG == nil && (bc.vmConfig.EnableParallelUnorderedMerge || bc.vmConfig.EnableTxParallelMerge) |
1773 | 1792 | 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 | + }() |
1774 | 1811 | return useSerialProcessor, tooDeep |
1775 | 1812 | } |
1776 | 1813 |
|
@@ -2037,6 +2074,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) |
2037 | 2074 | // Process block using the parent state as reference point |
2038 | 2075 | pstart = time.Now() |
2039 | 2076 | if useSerialProcessor { |
| 2077 | + parallelInSequencial.Mark(1) |
2040 | 2078 | receipts, logs, usedGas, err = bc.serialProcessor.Process(block, statedb, bc.vmConfig) |
2041 | 2079 | blockProcessedInParallel = false |
2042 | 2080 | } else { |
|
0 commit comments