Skip to content
Snippets Groups Projects
Unverified Commit 97d0de73 authored by Éloïs's avatar Éloïs
Browse files

[fix] cli option ecoMode : treat cleanly default and undefined value

parent c4965546
Branches
No related tags found
1 merge request!1214Reduce cpu
...@@ -41,6 +41,7 @@ export const ExecuteCommand = () => { ...@@ -41,6 +41,7 @@ export const ExecuteCommand = () => {
.option('--addep <endpoint>', 'With `config` command, add given endpoint to the list of endpoints of this node') .option('--addep <endpoint>', 'With `config` command, add given endpoint to the list of endpoints of this node')
.option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node') .option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node')
.option('--eco-mode', 'reduce CPU usage for proof-of-work computation')
.option('--no-eco-mode', 'Do not reduce CPU usage for proof-of-work computation') .option('--no-eco-mode', 'Do not reduce CPU usage for proof-of-work computation')
.option('--cpu <percent>', 'Percent of CPU usage for proof-of-work computation', parsePercent) .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('--nb-cores <number>', 'Number of cores uses for proof-of-work computation', parseInt)
......
...@@ -91,7 +91,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, ...@@ -91,7 +91,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
public rmEndpoints: string[], public rmEndpoints: string[],
public rootoffset: number, public rootoffset: number,
public upInterval: number, public upInterval: number,
public ecoMode: boolean|true, public ecoMode: boolean|undefined,
public cpu: number, public cpu: number,
public nbCores: number, public nbCores: number,
public prefix: number, public prefix: number,
......
...@@ -18,6 +18,9 @@ export const ProverDependency = { ...@@ -18,6 +18,9 @@ export const ProverDependency = {
/*********** Permanent prover **************/ /*********** Permanent prover **************/
config: { config: {
onLoading: async (conf:ConfDTO) => { onLoading: async (conf:ConfDTO) => {
if (conf.ecoMode === null || conf.ecoMode === undefined) {
conf.ecoMode = ProverConstants.DEFAULT_ECO_MODE;
}
if (conf.cpu === null || conf.cpu === undefined) { if (conf.cpu === null || conf.cpu === undefined) {
conf.cpu = ProverConstants.DEFAULT_CPU; conf.cpu = ProverConstants.DEFAULT_CPU;
} }
......
...@@ -201,7 +201,7 @@ export class BlockProver { ...@@ -201,7 +201,7 @@ export class BlockProver {
this.logger.info('Done: #%s, %s in %ss instead of %ss (%s tests, ~%s tests/s)', block.number, proof.hash, (duration / 1000).toFixed(2), this.logger.info('Done: #%s, %s in %ss instead of %ss (%s tests, ~%s tests/s)', block.number, proof.hash, (duration / 1000).toFixed(2),
this.conf.avgGenTime, testsCount, testsPerSecond.toFixed(2)); this.conf.avgGenTime, testsCount, testsPerSecond.toFixed(2));
this.logger.info('FOUND proof-of-work with %s leading zeros followed by [0-' + highMark + ']!', nbZeros); this.logger.info('FOUND proof-of-work with %s leading zeros followed by [0-' + highMark + ']!', nbZeros);
if(this.conf.ecoMode && this.conf.nbCores*testsPerSecond > 300) { if(this.conf.ecoMode === true && this.conf.nbCores*testsPerSecond > 300) {
if(this.conf.nbCores > 1) { if(this.conf.nbCores > 1) {
this.logger.info("Reducing number of CPU cores "+this.conf.nbCores) this.logger.info("Reducing number of CPU cores "+this.conf.nbCores)
this.conf.nbCores = this.conf.nbCores -1 this.conf.nbCores = this.conf.nbCores -1
......
...@@ -5,6 +5,7 @@ export const ProverConstants = { ...@@ -5,6 +5,7 @@ export const ProverConstants = {
MINIMAL_ZEROS_TO_SHOW_IN_LOGS: 3, MINIMAL_ZEROS_TO_SHOW_IN_LOGS: 3,
POW_MINIMAL_TO_SHOW: 2, POW_MINIMAL_TO_SHOW: 2,
DEFAULT_ECO_MODE: true,
DEFAULT_CPU: 0.6, DEFAULT_CPU: 0.6,
DEFAULT_PEER_ID: 1, DEFAULT_PEER_ID: 1,
MIN_PEER_ID: 1, MIN_PEER_ID: 1,
......
...@@ -444,6 +444,7 @@ function commandLineConf(program:any, conf:any = {}) { ...@@ -444,6 +444,7 @@ function commandLineConf(program:any, conf:any = {}) {
const cli = { const cli = {
currency: program.currency, currency: program.currency,
ecoMode: program.ecoMode, ecoMode: program.ecoMode,
noEcoMode: program.noEcoMode,
cpu: program.cpu, cpu: program.cpu,
nbCores: program.nbCores, nbCores: program.nbCores,
prefix: program.prefix, prefix: program.prefix,
...@@ -486,7 +487,8 @@ function commandLineConf(program:any, conf:any = {}) { ...@@ -486,7 +487,8 @@ function commandLineConf(program:any, conf:any = {}) {
// Update the rest of the conf // Update the rest of the conf
if (cli.currency) conf.currency = cli.currency; if (cli.currency) conf.currency = cli.currency;
if (cli.server.port) conf.port = cli.server.port; if (cli.server.port) conf.port = cli.server.port;
if (cli.ecoMode) conf.ecoMode = cli.ecoMode if (cli.ecoMode) conf.ecoMode = true
if (cli.noEcoMode) conf.ecoMode = false
if (cli.cpu) conf.cpu = Math.max(0.01, Math.min(1.0, cli.cpu)); if (cli.cpu) conf.cpu = Math.max(0.01, Math.min(1.0, cli.cpu));
if (cli.prefix) conf.prefix = Math.max(ProverConstants.MIN_PEER_ID, Math.min(ProverConstants.MAX_PEER_ID, cli.prefix)); if (cli.prefix) conf.prefix = Math.max(ProverConstants.MIN_PEER_ID, Math.min(ProverConstants.MAX_PEER_ID, cli.prefix));
if (cli.logs.http) conf.httplogs = true; if (cli.logs.http) conf.httplogs = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment