X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Futils.ts;h=724c4ab960c691e8f4a5d8661f9c442ff14d5b3d;hb=b358c8aca5934f7d5dc4bd234d1909ba13850ea9;hp=7c1b7866e6d958687ba6dc2e2c29827706caab4f;hpb=10c74f8a996cd15f294bdb31ad31d59ab0177db1;p=poolifier.git diff --git a/src/pools/utils.ts b/src/pools/utils.ts index 7c1b7866..724c4ab9 100644 --- a/src/pools/utils.ts +++ b/src/pools/utils.ts @@ -110,24 +110,29 @@ const estimatedCpuSpeed = (): number => { return Math.trunc(runs / duration / 1000) // in MHz } -const estCpuSpeed = estimatedCpuSpeed() - -const getDefaultWorkerWeight = (estimatedCpuSpeed = estCpuSpeed): number => { +const getDefaultWorkerWeight = (): number => { + const currentCpus = cpus() + let estCpuSpeed: number | undefined + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if (currentCpus.every(cpu => cpu.speed == null || cpu.speed === 0)) { + estCpuSpeed = estimatedCpuSpeed() + } let cpusCycleTimeWeight = 0 - for (const cpu of cpus()) { + for (const cpu of currentCpus) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (cpu.speed == null || cpu.speed === 0) { cpu.speed = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - cpus().find(cpu => cpu.speed != null && cpu.speed !== 0)?.speed ?? - estimatedCpuSpeed + currentCpus.find(cpu => cpu.speed != null && cpu.speed !== 0)?.speed ?? + estCpuSpeed ?? + 2000 } // CPU estimated cycle time const numberOfDigits = cpu.speed.toString().length - 1 const cpuCycleTime = 1 / (cpu.speed / Math.pow(10, numberOfDigits)) cpusCycleTimeWeight += cpuCycleTime * Math.pow(10, numberOfDigits) } - return Math.round(cpusCycleTimeWeight / cpus().length) + return Math.round(cpusCycleTimeWeight / currentCpus.length) } export const checkFilePath = (filePath: string | undefined): void => {