-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process.cpuUsage accuracy #8728
Comments
/ping @pmuellr |
Hi Nick, did you have any luck finding a good recipe? I tried your
Correct, it does not account for cores, as far as I know. The underlying API measures the amount of CPU used across all cores, so if your program uses 100% CPU in the main JavaScript thread, but also does work in other threads, you should expect the resultant % value to be > 100%. I think CPU usage values like this are typically based on a single CPU; that's what I seem to see in Mac's Activity Monitor, for instance. Same sort of thing, where a process using most of two cores will show CPU % values like 200%. If you want to have a value of % of total machine CPUs used, you could of course divide by the number of CPUs.
I believe you are right, and we should fix this. Seems like the following bits:
should be changed to:
|
Thanks for taking a look. After trying some more, I created a new example similar to test2 that is having results much more similar to what you would see in activity monitor. I think that resolves any questions I had around process.cpuUsage, but we should still update the test to use the correct multiplier. |
Great! Agree that we should fix the test; would you like the "honors"? Otherwise I'll try to get around to it this week or next ... |
Yeah, here it is: #14706 |
PR-URL: #14706 Fixes: #8728 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
PR-URL: #14706 Fixes: #8728 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
I'm trying to find cpu utilization of the process as a percentage of the system as a whole - similar to how top, activity monitor, and similar tools work, but from within the program itself. It appears that process.cpuUsage is a relatively new feature, and I haven't been able to find a way to get the cpu percentage and have it accurately match values found in system monitors. I created a repository of some of the different methods I have tried: https://github.com/nickstanish/node-test-process-cpuusage
It appears that there is discussion on an approach to get the percentage, but uses the wrong precision and seems to not account for number of cpu cores.
Is there a recommended approach in order to find this value?
I'd also like to point out that the tests for this feature have the wrong precision as well which makes the possible value range huge. The process usage values are in microseconds and it multiplies by 1e6
https://github.com/nodejs/node/blob/master/test/pummel/test-process-cpuUsage.js#L27
Original Issue:
nodejs/help#283
The text was updated successfully, but these errors were encountered: