I can't comment on how cpu idle time is calculated or if the cpus() array is consistently ordered but I can point out that setTimeout is not expected to be perfectly accurate.
>From the <a href="http://nodejs.org/api/timers.html">documentation</a>: "It is important to note that your callback will probably not be called in exactly delay milliseconds - Node.js makes no guarantees about the exact timing of when the callback will fire, nor of the ordering things will fire in. The callback will be called as close as possible to the time specified." Even clearer might be to say: "The callback will be called as soon as possible after the specified time has passed." Still, 17 seconds seems like a lot. Are you saying that's 17 seconds real time as well? Responding from mobile so forgive any errors, Chris (raptastics) On Dec 7, 2014 10:07 PM, "// ravi" <[email protected]> wrote: > > Hello all, > > I posted this question on node-forward/help on Gitter, so apologies if you > are seeing this again. > > I am stumped by what must clearly be a misreading on my part. Node 0.10 > docs say that each element of os.cpus() contains information about each > CPU/core. This information includes "the number of milliseconds the > CPU/core spent in: user, nice, sys, idle, and irq” (the docs do not say > milliseconds of what, but I assume it means milliseconds since the system > was last started). Note that this used to be, in v0.8 (and I assume > before), reported in CPU ticks, but seems to have switched to milliseconds > for v0.10. > > Now for the puzzle: say I do this: > > console.log(os.cpus()[0].times.idle); > setTimeout(function() { console.log(os.cpus()[0].times.idle); }, 2000); > > The output I see is: > > 39035126800 > 39035144500 > > Assuming that ordering of CPUs/cores is consistent in the array returned > by os.cpus(), it’s not clear how to square the above with the docs. The > difference between the times reported is 17700ms i.e., CPU 0 was idle for > 17 seconds in the 2 seconds between the two calls! > > I guess I am doing something trivially wrong in the above, but what is it? > > Any help appreciated! > > —ravi > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/CAEEC821-242A-4C65-8F07-C6B751A1B07E%40g8o.net > . > For more options, visit https://groups.google.com/d/optout. > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAMT%3Dzo4ZqoQUJ5XdtZSzCyh0y8%2BSH8mLzd%3DcwE2PhaTZh4EQJg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
