Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine which core is running Node.js process at runtime

Tags:

node.js

I was looking at the 'os' and 'process' module source and there does not appear to be a way to determine which core a node.js process is running on, before/during/after runtime.

I am looking for something like:

process.env.CORE_ID   //not real

I just want to confirm that different node.js processes are running on different cores. It seems reasonable that, although the operating system ultimately chooses which core a node.js process is executed on, we should be able to read that data once the OS starts the process.

like image 324
Alexander Mills Avatar asked May 28 '15 03:05

Alexander Mills


1 Answers

Processes are not attached to specific core in any operating systems (except, maybe, in some real-time oriented one).

Processors (and cores) are resources that can be assigned to any process whenever it needs. One thread can be executed only in a single core at once, but cores are shared by all processes. The operating system is responsible to schedule processes over available cores. So, when any process is "paused" due to let execute (or continue execution of) another process in the same core, there is no reason to expect that process to be resumed in the same core next time.

This is slightly observable when you have single process with a high cpu cosumtion in a (multi-core) machine with a relative low cpu activity by simply executing htop. Then you could see that there is always a highly occupied core, but which core is it will change regularly.

like image 132
bitifet Avatar answered Sep 22 '22 21:09

bitifet