Node using all processors without clustering. How come?

40 views
Skip to first unread message

harsh atal

unread,
Jul 20, 2016, 10:47:01 AM7/20/16
to nodejs
Dear All

I have a nodejs application that gets data from one server and pushes into another. It is a simple app made using following modules - Q, moment, express,request and log4js

For testing I sent 1000 requests to my node server and saw what happens on the system monitor. There I could see that all 4 processors were 100% occupied.

Now, from what I have read on nodejs, it seems that it by default uses only 1 thread(which amounts to 1 processor?). But how come all my computer's processors were occupied? Is this load balancing happening at OS level(I am on ubuntu 14)

And in case the balancing was done by OS then what is the difference between this automatic OS level load balancing and explicitly using clusters to divide the load??

Any help would be deeply appreciated :)

Thanks
harsh

Ryan Graham

unread,
Jul 20, 2016, 3:00:09 PM7/20/16
to nodejs

The part of node that is single threaded is the JS execution. All of the async calls like I/O and most system calls are handled by a combination of a thread pool and the OS's scheduler.

If your app mostly just passing data around and not doing a lot of processing on it then it is certainly a possibility that you are saturating the CPU cores with these other operations.

Another contributing factor could be native add-ons, which have direct access to the thread pool and can run their own threads for out-of-band execution. Examples would be performing crypto operations or database query serialization and deserialization.

And just to cover all the bases, you didn't actually say that it was your node process that was using the CPU. Unless you're looking at a docker container, your system is going to have many other processes running on it at the same time which could be monopolizing the other cores.

~Ryan


--
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 nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/be8cae17-841e-47e6-b74e-68ed3a151480%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

~Ryan

Reply all
Reply to author
Forward
0 new messages