This commit is contained in:
Jeffrey Wilcke 2016-02-20 19:05:39 +01:00
parent 2ac62c5627
commit aae51bd4c3
3 changed files with 13 additions and 8 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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))