diff options
author | Maran <maran.hidskes@gmail.com> | 2015-02-19 17:38:36 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2015-02-19 17:38:36 +0800 |
commit | 5aff8bfb5918e53ba2590b25e6c17e1875870f6a (patch) | |
tree | 3961c734a18e1f517d49c0cebc76bbdcae964605 | |
parent | ee9df32dba5091069cbdad8d00dc15738d676d5b (diff) | |
download | dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.tar dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.tar.gz dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.tar.bz2 dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.tar.lz dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.tar.xz dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.tar.zst dexon-5aff8bfb5918e53ba2590b25e6c17e1875870f6a.zip |
Implement command line argument to set the amount of agents created by the miner
Defaults to the amount of cores available on the CPU
-rw-r--r-- | cmd/mist/flags.go | 3 | ||||
-rw-r--r-- | cmd/mist/main.go | 27 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 2 | ||||
-rw-r--r-- | eth/backend.go | 4 | ||||
-rw-r--r-- | miner/miner.go | 4 |
5 files changed, 23 insertions, 17 deletions
diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index eb280f71b..d9487de9e 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -63,6 +63,7 @@ var ( DebugFile string LogLevel int VmType int + MinerThreads int ) // flags specific to gui client @@ -137,6 +138,8 @@ func Init() { flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap") flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") + flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads") + flag.Parse() var err error diff --git a/cmd/mist/main.go b/cmd/mist/main.go index 14f561e99..d41aa34bf 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -52,19 +52,20 @@ func run() error { config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH") ethereum, err := eth.New(ð.Config{ - Name: p2p.MakeName(ClientIdentifier, Version), - KeyStore: KeyStore, - DataDir: Datadir, - LogFile: LogFile, - LogLevel: LogLevel, - MaxPeers: MaxPeer, - Port: OutboundPort, - NAT: NAT, - Shh: true, - BootNodes: BootNodes, - NodeKey: NodeKey, - KeyRing: KeyRing, - Dial: true, + Name: p2p.MakeName(ClientIdentifier, Version), + KeyStore: KeyStore, + DataDir: Datadir, + LogFile: LogFile, + LogLevel: LogLevel, + MaxPeers: MaxPeer, + Port: OutboundPort, + NAT: NAT, + Shh: true, + BootNodes: BootNodes, + NodeKey: NodeKey, + KeyRing: KeyRing, + Dial: true, + MinerThreads: MinerThreads, }) if err != nil { mainlogger.Fatalln(err) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index ecb847fc3..d252f3ab2 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -225,7 +225,7 @@ func StartMining(ethereum *eth.Ethereum) bool { go func() { clilogger.Infoln("Start mining") if gminer == nil { - gminer = miner.New(addr, ethereum) + gminer = miner.New(addr, ethereum, 4) } gminer.Start() }() diff --git a/eth/backend.go b/eth/backend.go index d109ab98e..05d84cae8 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -53,6 +53,8 @@ type Config struct { Shh bool Dial bool + MinerThreads int + KeyManager *crypto.KeyManager } @@ -153,7 +155,7 @@ func New(config *Config) (*Ethereum, error) { eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockProcessor) eth.whisper = whisper.New() - eth.miner = miner.New(keyManager.Address(), eth) + eth.miner = miner.New(keyManager.Address(), eth, config.MinerThreads) hasBlock := eth.chainManager.HasBlock insertChain := eth.chainManager.InsertChain diff --git a/miner/miner.go b/miner/miner.go index 27afcf684..0cc2361c8 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -20,13 +20,13 @@ type Miner struct { mining bool } -func New(coinbase []byte, eth core.Backend) *Miner { +func New(coinbase []byte, eth core.Backend, minerThreads int) *Miner { miner := &Miner{ Coinbase: coinbase, worker: newWorker(coinbase, eth), } - for i := 0; i < 4; i++ { + for i := 0; i < minerThreads; i++ { miner.worker.register(NewCpuMiner(i, ezp.New())) } |