2

By running sails with forever or calling it directly with node app.js --prod, according to htop i have a 4 child process that look like clones under it.

enter image description here

If i leave out the --prod argument, i get an equal quantity of grunt processes. As you can see they all have the same amount of memory used, different PID and different TIME+ readings.

I'm pretty sure sails its not auto clustering, or is it? This is a single core machine (virtual), so i have no idea what are those processes, or is it an error in htop?

According to this question htop-showing-multiple-java-processes-with-different-pids?rq=1

htop shows threads as different process, but isn't node single threaded? If those are threads where are they comming from?

Andy W
  • 55
  • 5

1 Answers1

1

The threads you see using htop is userland threads(user's thread) but when you run your application in cluster mode(say 4 instances),it makes kernel thread. more on user threads

when you hide userland threads then whatever you see is kernel thread.while running application in cluster mode you will create multiple kernel threads of an application.And for each application's kernel thread there are several userland threads associated with it.

(for htop you can hide userland thread by F2 and display options)

please see the screen shots for explanation.

four instances of my app in cluster mode since number of cores==4 enter image description here

ps commands showing kernel threads only

htop showing kernel threads only enter image description here

htop showing kernel threads along with userland threads enter image description here

In last screenshot you see a few kernel and userland's threads but there are more. I mean for each kernel thread there are some userland's thread associated with it.

Community
  • 1
  • 1
vkstack
  • 1,582
  • 11
  • 24
  • So are those user threads the node.js thread pool (I know node event loop is single threaded but it needs threads behind the scenes for everything else)? or those are created by the framework? – Andy W Mar 15 '16 at 15:36
  • 1
    yeah... those are the thread which node aplication uses to mainatain it's eventloop and every thing else... by default every app has it's own several numbers of userland threads.which are created and controlled by the the app only. – vkstack Mar 15 '16 at 16:51