Skip to content
Snippets Groups Projects
Commit d19e76bf authored by vincentrou's avatar vincentrou
Browse files

Merge branch 'reduce_cpu_improvements' into 'reduce_cpu'

[enh] Ecomode improvements

See merge request !1216
parents 97d0de73 93c5b747
No related branches found
No related tags found
2 merge requests!1216[enh] Ecomode improvements,!1214Reduce cpu
...@@ -201,12 +201,12 @@ export class BlockProver { ...@@ -201,12 +201,12 @@ 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 === true && this.conf.nbCores*testsPerSecond > 300) { if(this.conf.ecoMode === true && this.conf.nbCores*testsPerSecond > ProverConstants.ECO_MODE_MINIMAL_TESTS_PER_SECONDS) {
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
} }
else if(this.conf.cpu > 0.19){ else if(this.conf.cpu > ProverConstants.ECO_MODE_MINIMAL_CPU){
let cpu:number = this.conf.cpu - 0.1 let cpu:number = this.conf.cpu - 0.1
this.logger.info("Slowing down the CPU to "+cpu) this.logger.info("Slowing down the CPU to "+cpu)
this.changeCPU(cpu) this.changeCPU(cpu)
......
...@@ -5,12 +5,15 @@ export const ProverConstants = { ...@@ -5,12 +5,15 @@ 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_ECO_MODE: false,
DEFAULT_CPU: 0.6, DEFAULT_CPU: 0.6,
DEFAULT_PEER_ID: 1, DEFAULT_PEER_ID: 1,
MIN_PEER_ID: 1, MIN_PEER_ID: 1,
MAX_PEER_ID: 899, // Due to MAX_SAFE_INTEGER = 9007199254740991 (16 digits, and we use 11 digits for the nonce + 2 digits for core number => 3 digits for the peer, must be below 900) MAX_PEER_ID: 899, // Due to MAX_SAFE_INTEGER = 9007199254740991 (16 digits, and we use 11 digits for the nonce + 2 digits for core number => 3 digits for the peer, must be below 900)
ECO_MODE_MINIMAL_TESTS_PER_SECONDS: 300,
ECO_MODE_MINIMAL_CPU: 0.19,
NONCE_RANGE: 1000 * 1000 * 1000 * 100, NONCE_RANGE: 1000 * 1000 * 1000 * 100,
POW_MAXIMUM_ACCEPTABLE_HANDICAP: 64, POW_MAXIMUM_ACCEPTABLE_HANDICAP: 64,
......
...@@ -185,27 +185,24 @@ export class Master { ...@@ -185,27 +185,24 @@ export class Master {
// Start the salves' job // Start the salves' job
this.slaves.forEach((s:any, index) => { this.slaves.forEach((s:any, index) => {
if(index < stuff.newPoW.conf.nbCores) { s.worker.send({
s.worker.send({ uuid,
uuid, command: 'newPoW',
command: 'newPoW', value: {
value: { block: stuff.newPoW.block,
block: stuff.newPoW.block, nonceBeginning: s.nonceBeginning,
nonceBeginning: s.nonceBeginning, zeros: stuff.newPoW.zeros,
zeros: stuff.newPoW.zeros, highMark: stuff.newPoW.highMark,
highMark: stuff.newPoW.highMark, pair: _.clone(stuff.newPoW.pair),
pair: _.clone(stuff.newPoW.pair), forcedTime: stuff.newPoW.forcedTime,
forcedTime: stuff.newPoW.forcedTime, turnDuration: stuff.newPoW.turnDuration,conf: {
turnDuration: stuff.newPoW.turnDuration, medianTimeBlocks: stuff.newPoW.conf.medianTimeBlocks,
conf: { avgGenTime: stuff.newPoW.conf.avgGenTime,
medianTimeBlocks: stuff.newPoW.conf.medianTimeBlocks, cpu: stuff.newPoW.conf.cpu,
avgGenTime: stuff.newPoW.conf.avgGenTime, prefix: stuff.newPoW.conf.prefix
cpu: stuff.newPoW.conf.cpu,
prefix: stuff.newPoW.conf.prefix
}
} }
}) }
} })
}) })
return await this.currentPromise return await this.currentPromise
......
...@@ -36,11 +36,10 @@ const prover = new BlockProver({ ...@@ -36,11 +36,10 @@ const prover = new BlockProver({
const now = 1474382274 * 1000; const now = 1474382274 * 1000;
const MUST_START_WITH_A_ZERO = 16; const MUST_START_WITH_A_ZERO = 16;
const MUST_START_WITH_TWO_ZEROS = 32; const MUST_START_WITH_TWO_ZEROS = 32;
const MUST_START_WITH_THREE_ZEROS = 58; const MUST_START_WITH_A_ZERO_AND_A_NUMBER = 22
describe("Proof-of-work", function() { describe("Proof-of-work", function() {
this.timeout(6*60000)
it('should be able to find an easy PoW', () => co(function*() { it('should be able to find an easy PoW', () => co(function*() {
let block = yield prover.prove({ let block = yield prover.prove({
issuer: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', issuer: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
...@@ -53,12 +52,19 @@ describe("Proof-of-work", function() { ...@@ -53,12 +52,19 @@ describe("Proof-of-work", function() {
})); }));
it('should be reducing cpu when the PoW is too easy for the cpu', () => co(function*() { it('should be reducing cpu when the PoW is too easy for the cpu', () => co(function*() {
prover.conf.nbCores = 2
prover.conf.cpu = 0.9
prover.conf.nbCores.should.equal(2)
prover.conf.cpu.should.equal(0.9)
for(let i=0; i<8; ++i) { for(let i=0; i<8; ++i) {
let block = yield prover.prove({ yield prover.prove({
issuer: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', issuer: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
number: i+2 number: i+2,
}, MUST_START_WITH_THREE_ZEROS, now); now
}, MUST_START_WITH_A_ZERO_AND_A_NUMBER, now);
} }
prover.conf.nbCores.should.equal(1)
prover.conf.cpu.should.be.below(0.9)
})); }));
// Too randomly successing test // Too randomly successing test
// it('should be able to cancel a proof-of-work on other PoW receival', () => co(function*() { // it('should be able to cancel a proof-of-work on other PoW receival', () => co(function*() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment