Skip to content

Commit 3973f55

Browse files
authored
fix: use ParallelTxNum config and uber automaxprocs (bnb-chain#204)
1 parent c5f1c9e commit 3973f55

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

cmd/utils/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
20302030
cfg.ParallelTxUnorderedMerge = ctx.Bool(ParallelTxUnorderedMergeFlag.Name)
20312031
}
20322032

2033+
if ctx.IsSet(ParallelTxNumFlag.Name) {
2034+
cfg.ParallelTxNum = ctx.Int(ParallelTxNumFlag.Name)
2035+
}
2036+
20332037
if ctx.IsSet(ParallelTxDAGFlag.Name) {
20342038
cfg.EnableParallelTxDAG = ctx.Bool(ParallelTxDAGFlag.Name)
20352039
}

core/parallel_state_scheduler.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313

1414
var runner chan func()
1515

16-
func init() {
17-
cpuNum := runtime.NumCPU()
18-
runner = make(chan func(), cpuNum)
19-
for i := 0; i < cpuNum; i++ {
16+
func initParallelRunner(targetNum int) {
17+
if targetNum == 0 {
18+
targetNum = runtime.GOMAXPROCS(0)
19+
}
20+
runner = make(chan func(), targetNum)
21+
for i := 0; i < targetNum; i++ {
2022
go func() {
2123
for f := range runner {
2224
f()
@@ -187,6 +189,8 @@ func (cq *confirmQueue) rerun(i int, execute func(*PEVMTxRequest) *PEVMTxResult,
187189
return nil
188190
}
189191

192+
var goMaxProcs = runtime.GOMAXPROCS(0)
193+
190194
// run runs the transactions in parallel
191195
// execute must return a non-nil result, otherwise it panics.
192196
func (tls TxLevels) Run(execute func(*PEVMTxRequest) *PEVMTxResult, confirm func(*PEVMTxResult) error, unorderedMerge bool) (error, int) {
@@ -207,7 +211,7 @@ func (tls TxLevels) Run(execute func(*PEVMTxRequest) *PEVMTxResult, confirm func
207211
maxLevelTxCount = len(txLevel)
208212
}
209213
wait := sync.WaitGroup{}
210-
trunks := txLevel.Split(runtime.NumCPU())
214+
trunks := txLevel.Split(goMaxProcs)
211215
wait.Add(len(trunks))
212216
// split tx into chunks, to save the cost of channel communication
213217
for _, txs := range trunks {

core/pevm_processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ func newPEVMProcessor(config *params.ChainConfig, bc *BlockChain, engine consens
3434
StateProcessor: *NewStateProcessor(config, bc, engine),
3535
unorderedMerge: bc.vmConfig.EnableParallelUnorderedMerge,
3636
}
37+
initParallelRunner(bc.vmConfig.ParallelTxNum)
3738
log.Info("Parallel execution mode is enabled", "Parallel Num", ParallelNum(),
38-
"CPUNum", runtime.NumCPU(), "unorderedMerge", processor.unorderedMerge)
39+
"CPUNum", runtime.GOMAXPROCS(0), "unorderedMerge", processor.unorderedMerge)
3940
return processor
4041
}
4142

0 commit comments

Comments
 (0)