mirror of
https://github.com/Swizec/thaw-carrots.git
synced 2024-09-29 10:45:37 +00:00
Average last 3 measurements before scaling workload
This commit is contained in:
parent
dc1c106671
commit
9c70e39260
14
index.js
14
index.js
|
@ -3,28 +3,37 @@ const mri = require("mri");
|
||||||
const sll = require("single-line-log").stdout;
|
const sll = require("single-line-log").stdout;
|
||||||
const kleur = require("kleur");
|
const kleur = require("kleur");
|
||||||
const fork = require("child_process").fork;
|
const fork = require("child_process").fork;
|
||||||
|
const sleep = require("sleep");
|
||||||
|
|
||||||
async function readTemp() {
|
async function readTemp() {
|
||||||
const temp = await si.cpuTemperature();
|
const temp = await si.cpuTemperature();
|
||||||
return { main: temp.main, cores: temp.cores };
|
return { main: temp.main, cores: temp.cores };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function avg(arr) {
|
||||||
|
return arr.reduce((sum, t) => t.main + sum, 0) / arr.length;
|
||||||
|
}
|
||||||
|
|
||||||
async function thawMyCarrots(targetTemp) {
|
async function thawMyCarrots(targetTemp) {
|
||||||
let temp = await readTemp(),
|
let temp = await readTemp(),
|
||||||
|
temps = [temp, temp, temp],
|
||||||
children = [];
|
children = [];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (temp.main < targetTemp) {
|
if (avg(temps) < targetTemp) {
|
||||||
if (children.length < 10) {
|
if (children.length < 10) {
|
||||||
children.push(fork("./eat-cpu"));
|
children.push(fork("./eat-cpu"));
|
||||||
}
|
}
|
||||||
} else if (temp.main > targetTemp) {
|
} else if (avg(temps) > targetTemp) {
|
||||||
if (children.length > 0) {
|
if (children.length > 0) {
|
||||||
children.pop().kill();
|
children.pop().kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
temp = await readTemp();
|
temp = await readTemp();
|
||||||
|
temps.shift();
|
||||||
|
temps.push(temp);
|
||||||
|
|
||||||
sll(
|
sll(
|
||||||
"Current temp",
|
"Current temp",
|
||||||
kleur.bold.red(temp.main.toFixed(2)),
|
kleur.bold.red(temp.main.toFixed(2)),
|
||||||
|
@ -32,6 +41,7 @@ async function thawMyCarrots(targetTemp) {
|
||||||
kleur.bold.gray(temp.cores),
|
kleur.bold.gray(temp.cores),
|
||||||
`\nChildren: ${children.length}`
|
`\nChildren: ${children.length}`
|
||||||
);
|
);
|
||||||
|
sleep.msleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -32,6 +32,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.1.tgz",
|
||||||
"integrity": "sha1-haom09ru7t+A3FmEr5XMXKXK2fE="
|
"integrity": "sha1-haom09ru7t+A3FmEr5XMXKXK2fE="
|
||||||
},
|
},
|
||||||
|
"nan": {
|
||||||
|
"version": "2.11.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/nan/-/nan-2.11.1.tgz",
|
||||||
|
"integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA=="
|
||||||
|
},
|
||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
|
||||||
|
@ -55,6 +60,14 @@
|
||||||
"string-width": "^1.0.1"
|
"string-width": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"sleep": {
|
||||||
|
"version": "5.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/sleep/-/sleep-5.2.3.tgz",
|
||||||
|
"integrity": "sha512-vC05N1XqgIiPIj6tEq7wt0R32aTycJv4Ymo/jwSEp2PkeU1GCJ1tkl+RdYZEo7Gjebq8QQuhFuEe7vsyVGlFRA==",
|
||||||
|
"requires": {
|
||||||
|
"nan": ">=2.5.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
"osx-temperature-sensor": "^1.0.3",
|
"osx-temperature-sensor": "^1.0.3",
|
||||||
"prime-number": "^0.2.2",
|
"prime-number": "^0.2.2",
|
||||||
"single-line-log": "^1.1.2",
|
"single-line-log": "^1.1.2",
|
||||||
|
"sleep": "^5.2.3",
|
||||||
"systeminformation": "^3.45.7"
|
"systeminformation": "^3.45.7"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"thaw-carrots": "index.js"
|
"thaw-carrots": "index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue