Node: CPU time passes 10x faster than real time on a single core

Created on 25 Apr 2020  路  4Comments  路  Source: nodejs/node

  • Version: v13.11.0
  • Platform: Linux 4.15.0-91-generic #92-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: os

What steps will reproduce the bug?

const { cpus } = require('os');
const measure = () => cpus().map(c => c.times.idle);
const diff = (first, second) => second.map((v, i) => v - first[i]);
setTimeout(((first) => () => console.log(diff(first, measure())))(measure()), 1000);

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

Within 1000ms, each core cannot spend more than (approximately) 1000ms idle.

What do you see instead?

[
  10200, 10200,
  10100, 10200,
  10000, 10000,
   9900, 10000
]

Additional information

I cannot reproduce the problem on Windows, so I assumed it's a problem in libuv, but the code in libuv seems correct to me.

libuv linux os

Most helpful comment

Probably sometime in May. The last libuv release was just last week.

All 4 comments

That was actually fixed just three days ago, see libuv/libuv@37a8aff. :-)

@bnoordhuis Oh, nice! That explains it :D Any idea when that patch might make it into a Node.js release?

Probably sometime in May. The last libuv release was just last week.

I believe this has been resolved in master

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonathanong picture jonathanong  路  91Comments

yury-s picture yury-s  路  89Comments

AkashaThorne picture AkashaThorne  路  207Comments

substack picture substack  路  878Comments

feross picture feross  路  208Comments