Skip to content

Commit c423cdd

Browse files
authored
fix: cpus().length is broken under docker. (#100)
cgroups don't mask off unavailable CPUs and this is considered a feature not a bug, and so Node got os.availableParallelism() to attempt to fix this. This version still has issues (nodejs/node#59200) but at least it's more likely to be correct.
1 parent 133c156 commit c423cdd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/reporter/chart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { platform, arch, cpus, totalmem } = require("node:os");
1+
const { platform, arch, availableParallelism, totalmem } = require("node:os");
22
const { styleText } = require("../utils/styleText");
33
const { analyze } = require("../utils/baseline.js");
44

@@ -85,7 +85,7 @@ const timer = Intl.NumberFormat(undefined, {
8585
const environment = {
8686
nodeVersion: `Node.js version: ${process.version}`,
8787
platform: `${platform()} ${arch()}`,
88-
hardware: `${cpus().length} vCPUs | ${(totalmem() / 1024 ** 3).toFixed(1)}GB Mem`,
88+
hardware: `${availableParallelism()} vCPUs | ${(totalmem() / 1024 ** 3).toFixed(1)}GB Mem`,
8989
};
9090

9191
/**

lib/reporter/html.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { platform, arch, cpus, totalmem } = require("node:os");
1+
const { platform, arch, availableParallelism, totalmem } = require("node:os");
22
const fs = require("node:fs");
33
const path = require("node:path");
44

@@ -77,7 +77,7 @@ const generateHTML = (template, durations) => {
7777

7878
const environmentDiv = `<p>Node.js version: <span class="number">${process.version}</span></p>
7979
<p>Platform: <span class="number">${platform()} ${arch()}</span></p>
80-
<p>CPU Cores: <span class="number">${cpus().length}</span> vCPUs | <span class="number">${(totalmem() / 1024 ** 3).toFixed(1)}GB Mem</span></p>`;
80+
<p>CPU Cores: <span class="number">${availableParallelism()}</span> vCPUs | <span class="number">${(totalmem() / 1024 ** 3).toFixed(1)}GB Mem</span></p>`;
8181

8282
return template
8383
.replaceAll("{{CONTAINER_HEIGHT}}", `${durations.length * 100}px;`)

0 commit comments

Comments
 (0)