-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
question: Average CPU consumption range and threshold for Node.js apps in Production #11937
Description
Given that Node.js provides a single threaded, asynchronous, event driven programming model which handles the I/O and CPU bound operations efficiently, through multiplexing between them, consider this program:
Client code
Server code
In short, some clients are connecting (and reconnecting) to a server and downloading some data. From server standpoint, it is addressing the needs of many clients, triggered by events in the uv loop, in a heavily concurrent manner.
The top command shows that node is utilizing more that 99% of CPU time.
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23766 bidisha 20 0 672m 14m 9828 R 99.9 0.1 4:03.43 node
In a multi-threaded server program execution environment (such as Java application server) which works with a thread-pool to handle concurrent clients, a healthy CPU consumption is considered to be less than 20% (IMO).
In node, the increased CPU consumption is understood to be root caused by increased activity by a single thread across many transactions without blocking on I/O and consuming most or all of its CPU share. And in this case, I don't see any issue, as the increased consumption is translated to useful work done.
But then, what is optimal range of CPU consumption which is considered to be healthy? And what is the threshold point beyond which one should start suspecting its consumption and start profiling for CPU? Are there guidance values available?
Thanks in advance!