mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
sep proc
This commit is contained in:
parent
2ac62c5627
commit
aae51bd4c3
3 changed files with 13 additions and 8 deletions
|
|
@ -105,14 +105,18 @@ func (b *Balancer) Push(work Task) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Balancer) balance(work chan Task) {
|
func (b *Balancer) balance(work chan Task) {
|
||||||
for {
|
go func() {
|
||||||
select {
|
// worker is done
|
||||||
case w := <-b.done: // worker is done
|
for w := range b.done {
|
||||||
b.completed(w) // handle worker
|
b.completed(w) // handle worker
|
||||||
case task := <-work: // get task
|
}
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
// get task
|
||||||
|
for task := range work {
|
||||||
b.dispatch(task) // dispatch the tasks
|
b.dispatch(task) // dispatch the tasks
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// dispatch dispatches the tasks to the least loaded worker.
|
// dispatch dispatches the tasks to the least loaded worker.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/balancer"
|
"github.com/ethereum/go-ethereum/balancer"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -18,7 +19,7 @@ func balanceTxWork(b *balancer.Balancer, txs types.Transactions) {
|
||||||
return
|
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)
|
errch := make(chan error, int(math.Ceil(float64(len(txs))/float64(workSize)))) // error channel (buffered)
|
||||||
for i := 0; i < len(txs); i += workSize {
|
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 {
|
func balanceBlockWork(b *balancer.Balancer, blocks []*types.Block, checker pow.PoW) chan nonceResult {
|
||||||
workSize := len(blocks) / 4
|
workSize := len(blocks) / runtime.GOMAXPROCS(0)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nonceResults = make(chan nonceResult, len(blocks)) // the nonce result channel (buffered)
|
nonceResults = make(chan nonceResult, len(blocks)) // the nonce result channel (buffered)
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ func NewBlockChain(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*Bl
|
||||||
blockCache: blockCache,
|
blockCache: blockCache,
|
||||||
futureBlocks: futureBlocks,
|
futureBlocks: futureBlocks,
|
||||||
pow: pow,
|
pow: pow,
|
||||||
balancer: balancer.New(runtime.NumCPU()),
|
balancer: balancer.New(runtime.GOMAXPROCS(0)),
|
||||||
}
|
}
|
||||||
// Seed a fast but crypto originating random generator
|
// Seed a fast but crypto originating random generator
|
||||||
seed, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
|
seed, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue