Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
63a7f4b7
Commit
63a7f4b7
authored
7 years ago
by
Vincent Rousseau
Browse files
Options
Downloads
Patches
Plain Diff
Add and remove workers during eco mode
parent
53fdad34
No related branches found
No related tags found
1 merge request
!1214
Reduce cpu
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/modules/prover/lib/blockProver.ts
+30
-11
30 additions, 11 deletions
app/modules/prover/lib/blockProver.ts
app/modules/prover/lib/engine.ts
+9
-4
9 additions, 4 deletions
app/modules/prover/lib/engine.ts
app/modules/prover/lib/powCluster.ts
+52
-30
52 additions, 30 deletions
app/modules/prover/lib/powCluster.ts
with
91 additions
and
45 deletions
app/modules/prover/lib/blockProver.ts
+
30
−
11
View file @
63a7f4b7
...
...
@@ -48,6 +48,14 @@ export class WorkerFarm {
return
this
.
theEngine
.
getNbWorkers
()
}
reduceNbCores
()
{
return
this
.
theEngine
.
reduceNbCores
()
}
boostCPU
(){
return
this
.
theEngine
.
boostCPU
()
}
changeCPU
(
cpu
:
any
)
{
return
this
.
theEngine
.
setConf
({
cpu
})
}
...
...
@@ -194,13 +202,12 @@ export class BlockProver {
});
if
(
!
result
)
{
this
.
logger
.
info
(
'
GIVEN proof-of-work for block#%s with %s leading zeros followed by [0-
'
+
highMark
+
'
]! stop PoW for %s
'
,
block
.
number
,
nbZeros
,
this
.
pair
&&
this
.
pair
.
pub
.
slice
(
0
,
6
));
let
selfNbBlockInFrame
=
await
this
.
server
.
getBcContext
().
getIssuerNbBlockInFrame
(
this
.
server
.
PeeringService
.
selfPubkey
)
if
(
this
.
conf
.
ecoMode
===
true
)
{
let
selfNbBlockInFrame
=
await
this
.
server
.
getBcContext
().
getIssuerNbBlockInFrame
(
this
.
server
.
PeeringService
.
selfPubkey
)
if
(
selfNbBlockInFrame
<
2
)
{
this
.
change
CPU
(
1
)
this
.
conf
.
nbCores
=
this
.
server
.
conf
.
nb
C
or
e
s
this
.
logger
.
info
(
"
Boost number of CPU cores
"
+
this
.
conf
.
nb
C
or
e
s
+
"
with only
"
+
selfNbBlockInFrame
+
"
block member in frame
"
)
this
.
boost
CPU
()
this
.
conf
.
nbCores
=
powFarm
.
nb
W
or
ker
s
this
.
logger
.
info
(
"
Boost number of CPU cores
"
+
powFarm
.
nb
W
or
ker
s
+
"
with only
"
+
selfNbBlockInFrame
+
"
block member in frame
"
)
}
}
throw
'
Proof-of-work computation canceled because block received
'
;
...
...
@@ -214,14 +221,15 @@ export class BlockProver {
if
(
this
.
conf
.
ecoMode
===
true
)
{
let
selfNbBlockInFrame
=
await
this
.
server
.
getBcContext
().
getIssuerNbBlockInFrame
(
this
.
server
.
PeeringService
.
selfPubkey
)
if
(
selfNbBlockInFrame
<
2
)
{
this
.
change
CPU
(
1
)
this
.
conf
.
nbCores
=
this
.
server
.
conf
.
nb
C
or
e
s
this
.
logger
.
info
(
"
Boost number of CPU cores
"
+
this
.
conf
.
nb
C
or
e
s
+
"
with only
"
+
selfNbBlockInFrame
+
"
block member in frame
"
)
this
.
boost
CPU
()
this
.
conf
.
nbCores
=
powFarm
.
nb
W
or
ker
s
this
.
logger
.
info
(
"
Boost number of CPU cores
"
+
powFarm
.
nb
W
or
ker
s
+
"
with only
"
+
selfNbBlockInFrame
+
"
block member in frame
"
)
}
else
if
(
this
.
conf
.
nbCores
*
testsPerSecond
>
ProverConstants
.
ECO_MODE_MINIMAL_TESTS_PER_SECONDS
)
{
if
(
this
.
conf
.
nbCores
>
1
)
{
this
.
logger
.
info
(
"
Reducing number of CPU cores
"
+
this
.
conf
.
nbCores
)
this
.
conf
.
nbCores
=
this
.
conf
.
nbCores
-
1
else
if
(
testsPerSecond
>
ProverConstants
.
ECO_MODE_MINIMAL_TESTS_PER_SECONDS
)
{
if
(
powFarm
.
nbWorkers
>
1
)
{
this
.
logger
.
info
(
"
Reducing number of CPU cores
"
+
powFarm
.
nbWorkers
)
this
.
reduceNbCores
()
this
.
conf
.
nbCores
=
powFarm
.
nbWorkers
}
else
if
(
this
.
conf
.
cpu
>
ProverConstants
.
ECO_MODE_MINIMAL_CPU
){
let
cpu
:
number
=
this
.
conf
.
cpu
-
0.1
...
...
@@ -235,6 +243,17 @@ export class BlockProver {
})()
};
async
reduceNbCores
()
{
const
farm
=
await
this
.
getWorker
()
return
farm
.
reduceNbCores
()
}
async
boostCPU
()
{
this
.
conf
.
cpu
=
1.0
const
farm
=
await
this
.
getWorker
()
return
farm
.
boostCPU
()
}
async
changeCPU
(
cpu
:
number
)
{
this
.
conf
.
cpu
=
Math
.
max
(
0.01
,
Math
.
min
(
1.0
,
cpu
));
const
farm
=
await
this
.
getWorker
()
...
...
This diff is collapsed.
Click to expand it.
app/modules/prover/lib/engine.ts
+
9
−
4
View file @
63a7f4b7
...
...
@@ -12,15 +12,12 @@ if(debug) {
export
class
PowEngine
{
private
nbWorkers
:
number
private
cluster
:
PowCluster
readonly
id
:
number
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
.
nbCores
this
.
cluster
=
new
PowCluster
(
this
.
nbWorkers
,
logger
)
this
.
cluster
=
new
PowCluster
(
conf
.
nbCores
,
logger
)
this
.
id
=
this
.
cluster
.
clusterId
}
...
...
@@ -41,6 +38,14 @@ export class PowEngine {
return
this
.
cluster
.
cancelWork
()
}
reduceNbCores
()
{
return
this
.
cluster
.
removeSlave
()
}
boostCPU
()
{
return
this
.
cluster
.
boostCPU
()
}
setConf
(
value
:
any
)
{
return
this
.
cluster
.
changeConf
(
value
)
}
...
...
This diff is collapsed.
Click to expand it.
app/modules/prover/lib/powCluster.ts
+
52
−
30
View file @
63a7f4b7
...
...
@@ -35,6 +35,7 @@ export class Master {
logger
:
any
onInfoCallback
:
any
workersOnline
:
Promise
<
any
>
[]
maxNbCores
:
number
=
Math
.
min
(
ProverConstants
.
CORES_MAXIMUM_USE_IN_PARALLEL
,
require
(
'
os
'
).
cpus
().
length
)
constructor
(
private
nbCores
:
number
,
logger
:
any
)
{
this
.
clusterId
=
clusterId
++
...
...
@@ -65,6 +66,56 @@ export class Master {
// this.logger.debug(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index}:`, message)
}
createSlave
(
index
:
number
)
{
const
nodejsWorker
=
cluster
.
fork
()
const
worker
=
new
PowWorker
(
nodejsWorker
,
message
=>
{
this
.
onWorkerMessage
(
index
,
message
)
},
()
=>
{
this
.
logger
.
info
(
`[online] worker c#
${
this
.
clusterId
}
#w#
${
index
}
`
)
worker
.
sendConf
({
command
:
'
conf
'
,
value
:
this
.
conf
})
},
(
code
:
any
,
signal
:
any
)
=>
{
this
.
logger
.
info
(
`worker
${
worker
.
pid
}
died with code
${
code
}
and signal
${
signal
}
`
)
})
this
.
logger
.
info
(
`Creating worker c#
${
this
.
clusterId
}
#w#
${
nodejsWorker
.
id
}
`
)
const
slave
=
{
// The Node.js worker
worker
,
// Inner identifier
index
,
// Worker ready
online
:
worker
.
online
,
// Each worker has his own chunk of possible nonces
nonceBeginning
:
this
.
nbCores
===
1
?
0
:
(
index
+
1
)
*
ProverConstants
.
NONCE_RANGE
}
this
.
slavesMap
[
nodejsWorker
.
id
]
=
slave
return
slave
}
boostCPU
()
{
if
(
this
.
nbWorkers
<
this
.
maxNbCores
)
{
while
(
this
.
nbWorkers
<
this
.
maxNbCores
)
{
this
.
slaves
.
push
(
this
.
createSlave
(
this
.
nbWorkers
))
}
}
let
conf
:
any
=
{
cpu
:
1
}
this
.
changeConf
(
conf
)
}
async
removeSlave
()
{
let
nb_workers
=
this
.
nbWorkers
await
this
.
slaves
[
nb_workers
-
1
].
worker
.
kill
()
this
.
slaves
.
pop
()
this
.
logger
.
info
(
'
Remove slave number
'
+
(
nb_workers
-
1
))
}
/*****************
* CLUSTER METHODS
****************/
...
...
@@ -77,36 +128,7 @@ export class Master {
})
this
.
slaves
=
Array
.
from
({
length
:
this
.
nbCores
}).
map
((
value
,
index
)
=>
{
const
nodejsWorker
=
cluster
.
fork
()
const
worker
=
new
PowWorker
(
nodejsWorker
,
message
=>
{
this
.
onWorkerMessage
(
index
,
message
)
},
()
=>
{
this
.
logger
.
info
(
`[online] worker c#
${
this
.
clusterId
}
#w#
${
index
}
`
)
worker
.
sendConf
({
command
:
'
conf
'
,
value
:
this
.
conf
})
},
(
code
:
any
,
signal
:
any
)
=>
{
this
.
logger
.
info
(
`worker
${
worker
.
pid
}
died with code
${
code
}
and signal
${
signal
}
`
)
})
this
.
logger
.
info
(
`Creating worker c#
${
this
.
clusterId
}
#w#
${
nodejsWorker
.
id
}
`
)
const
slave
=
{
// The Node.js worker
worker
,
// Inner identifier
index
,
// Worker ready
online
:
worker
.
online
,
// Each worker has his own chunk of possible nonces
nonceBeginning
:
this
.
nbCores
===
1
?
0
:
(
index
+
1
)
*
ProverConstants
.
NONCE_RANGE
}
this
.
slavesMap
[
nodejsWorker
.
id
]
=
slave
return
slave
return
this
.
createSlave
(
index
)
})
this
.
workersOnline
=
this
.
slaves
.
map
((
s
)
=>
s
.
online
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment