diff --git a/app/cli.ts b/app/cli.ts index 26accf24f158facb605808a72bfaec2dfc9f2abd..3c2e495153853106e8b04d3253c36be1703752c1 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -42,6 +42,7 @@ export const ExecuteCommand = () => { .option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node') .option('--cpu <percent>', 'Percent of CPU usage for proof-of-work computation', parsePercent) + .option('--nb-cores <number>', 'Number of cores uses for proof-of-work computation', parseInt) .option('--prefix <nodeId>', 'Prefix node id for the first character of nonce', parseInt) .option('-c, --currency <name>', 'Name of the currency managed by this node.') diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 7bdd83464fbadb89784356ce724eb13ff643e0eb..01b4bc719e8e94bec686f4b902c86d540b5dc71b 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -21,6 +21,9 @@ export const ProverDependency = { if (conf.cpu === null || conf.cpu === undefined) { conf.cpu = Constants.DEFAULT_CPU; } + if (conf.nbCores === null || conf.nbCores === undefined) { + conf.nbCores = Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + } if (conf.prefix === null || conf.prefix === undefined) { conf.prefix = Constants.DEFAULT_PEER_ID; } diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index 12d2751d6c45f522027ce96c88de942cd9f0c62a..116963e475f0b2f76143711d80d348f349ed0474 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -20,7 +20,7 @@ export class PowEngine { constructor(private conf:ConfDTO, logger:any) { // We use as much cores as available, but not more than CORES_MAXIMUM_USE_IN_PARALLEL - this.nbWorkers = (conf && conf.nbCores) || Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + this.nbWorkers = conf.nbCores this.cluster = new PowCluster(this.nbWorkers, logger) this.id = this.cluster.clusterId } diff --git a/index.ts b/index.ts index f9e3cf445157876a33b1c8d5be9335d121b6a070..1086b3aa0bf52983a3c3e05514da232dd6a974c4 100644 --- a/index.ts +++ b/index.ts @@ -444,6 +444,7 @@ function commandLineConf(program:any, conf:any = {}) { const cli = { currency: program.currency, cpu: program.cpu, + nbCores: program.nbCores, prefix: program.prefix, server: { port: program.port,