Skip to content

Commit

Permalink
fix: use ParallelTxNum config and uber automaxprocs (bnb-chain#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkin22 authored Oct 23, 2024
1 parent c5f1c9e commit 3973f55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.ParallelTxUnorderedMerge = ctx.Bool(ParallelTxUnorderedMergeFlag.Name)
}

if ctx.IsSet(ParallelTxNumFlag.Name) {
cfg.ParallelTxNum = ctx.Int(ParallelTxNumFlag.Name)
}

if ctx.IsSet(ParallelTxDAGFlag.Name) {
cfg.EnableParallelTxDAG = ctx.Bool(ParallelTxDAGFlag.Name)
}
Expand Down
14 changes: 9 additions & 5 deletions core/parallel_state_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (

var runner chan func()

func init() {
cpuNum := runtime.NumCPU()
runner = make(chan func(), cpuNum)
for i := 0; i < cpuNum; i++ {
func initParallelRunner(targetNum int) {
if targetNum == 0 {
targetNum = runtime.GOMAXPROCS(0)
}
runner = make(chan func(), targetNum)
for i := 0; i < targetNum; i++ {
go func() {
for f := range runner {
f()
Expand Down Expand Up @@ -187,6 +189,8 @@ func (cq *confirmQueue) rerun(i int, execute func(*PEVMTxRequest) *PEVMTxResult,
return nil
}

var goMaxProcs = runtime.GOMAXPROCS(0)

// run runs the transactions in parallel
// execute must return a non-nil result, otherwise it panics.
func (tls TxLevels) Run(execute func(*PEVMTxRequest) *PEVMTxResult, confirm func(*PEVMTxResult) error, unorderedMerge bool) (error, int) {
Expand All @@ -207,7 +211,7 @@ func (tls TxLevels) Run(execute func(*PEVMTxRequest) *PEVMTxResult, confirm func
maxLevelTxCount = len(txLevel)
}
wait := sync.WaitGroup{}
trunks := txLevel.Split(runtime.NumCPU())
trunks := txLevel.Split(goMaxProcs)
wait.Add(len(trunks))
// split tx into chunks, to save the cost of channel communication
for _, txs := range trunks {
Expand Down
3 changes: 2 additions & 1 deletion core/pevm_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func newPEVMProcessor(config *params.ChainConfig, bc *BlockChain, engine consens
StateProcessor: *NewStateProcessor(config, bc, engine),
unorderedMerge: bc.vmConfig.EnableParallelUnorderedMerge,
}
initParallelRunner(bc.vmConfig.ParallelTxNum)
log.Info("Parallel execution mode is enabled", "Parallel Num", ParallelNum(),
"CPUNum", runtime.NumCPU(), "unorderedMerge", processor.unorderedMerge)
"CPUNum", runtime.GOMAXPROCS(0), "unorderedMerge", processor.unorderedMerge)
return processor
}

Expand Down

0 comments on commit 3973f55

Please sign in to comment.