diff --git a/balancer/balancer.go b/balancer/balancer.go index 3a05726032..709fa91d0a 100644 --- a/balancer/balancer.go +++ b/balancer/balancer.go @@ -105,14 +105,18 @@ func (b *Balancer) Push(work Task) { } func (b *Balancer) balance(work chan Task) { - for { - select { - case w := <-b.done: // worker is done + go func() { + // worker is done + for w := range b.done { b.completed(w) // handle worker - case task := <-work: // get task + } + }() + go func() { + // get task + for task := range work { b.dispatch(task) // dispatch the tasks } - } + }() } // dispatch dispatches the tasks to the least loaded worker. diff --git a/core/block_work.go b/core/block_work.go index d45559e2a5..5eb5e51e6b 100644 --- a/core/block_work.go +++ b/core/block_work.go @@ -2,6 +2,7 @@ package core import ( "math" + "runtime" "github.com/ethereum/go-ethereum/balancer" "github.com/ethereum/go-ethereum/core/types" @@ -18,7 +19,7 @@ func balanceTxWork(b *balancer.Balancer, txs types.Transactions) { return } - workSize := len(txs) / 4 + workSize := len(txs) / runtime.GOMAXPROCS(0) errch := make(chan error, int(math.Ceil(float64(len(txs))/float64(workSize)))) // error channel (buffered) for i := 0; i < len(txs); i += workSize { @@ -48,7 +49,7 @@ func balanceTxWork(b *balancer.Balancer, txs types.Transactions) { } func balanceBlockWork(b *balancer.Balancer, blocks []*types.Block, checker pow.PoW) chan nonceResult { - workSize := len(blocks) / 4 + workSize := len(blocks) / runtime.GOMAXPROCS(0) var ( nonceResults = make(chan nonceResult, len(blocks)) // the nonce result channel (buffered) diff --git a/core/blockchain.go b/core/blockchain.go index 5fca8a1584..c21f58b47c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -139,7 +139,7 @@ func NewBlockChain(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*Bl blockCache: blockCache, futureBlocks: futureBlocks, pow: pow, - balancer: balancer.New(runtime.NumCPU()), + balancer: balancer.New(runtime.GOMAXPROCS(0)), } // Seed a fast but crypto originating random generator seed, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))