Why are there multiple PM2 processes listed on my server?
Asked Answered
M

2

7

I have a Node application running on a production server using PM2. When I ssh into the server and run htop I can see multiple PM2 God Daemon processes listed. I don't understand why there would be multiple processes since there's only one Sails app running through PM2.

I was under the impression that Node apps only use a single thread so I'm not sure why there would be multiple PM2 processes listed. Can someone help shed some light on this?

enter image description here

Mohenjodaro answered 19/1, 2016 at 20:18 Comment(0)
A
2

There aren't multiple processes (at least not in a replicated sense). What you see is due to the default sorted representation of (sub-) processes in htop.

You can press F5 to switch to a tree representation of the process tree. It will then display a hierarchical representation of all sub-processes launched by the initial program, here: PM2. In fact, there might be quite a few.

For further details, see the description from the official htop man page (at ubuntu.com):

F5, t

Tree view: organize processes by parenthood, and layout the relations between them as a tree. Toggling the key will switch between tree and your previously selected sort view. Selecting a sort view will exit tree view.

Hope it helps.

Apia answered 19/1, 2016 at 20:31 Comment(2)
You are wrong, those are not threads, those are multiple PM2 processes that are spawned, each with its own set of threads. I'm now having the same issue, having 20 of them spawned at the moment - I'm 100% sure about this, can't post a screenshot here.Ruisdael
Well, my answer does not state that those are threads. Read carefully again, and maybe reflect the other answer provided by the author of htop.Apia
A
26

htop author here: those are threads of your process. Press uppercase H to toggle hiding/showing threads, and F2 to go to the Setup screen, and then navigate to "Display Options" and check the option "[x] Display threads in a different color". This will let you differentiate threads from regular processes.

Aurore answered 21/1, 2016 at 16:34 Comment(1)
cool, thanks for adding this answer as it gives further explanation and details to all interested in this topic. Maybe it's worth displaying threads in different color by default? Just a thought to further improve this great tool for the future.Apia
A
2

There aren't multiple processes (at least not in a replicated sense). What you see is due to the default sorted representation of (sub-) processes in htop.

You can press F5 to switch to a tree representation of the process tree. It will then display a hierarchical representation of all sub-processes launched by the initial program, here: PM2. In fact, there might be quite a few.

For further details, see the description from the official htop man page (at ubuntu.com):

F5, t

Tree view: organize processes by parenthood, and layout the relations between them as a tree. Toggling the key will switch between tree and your previously selected sort view. Selecting a sort view will exit tree view.

Hope it helps.

Apia answered 19/1, 2016 at 20:31 Comment(2)
You are wrong, those are not threads, those are multiple PM2 processes that are spawned, each with its own set of threads. I'm now having the same issue, having 20 of them spawned at the moment - I'm 100% sure about this, can't post a screenshot here.Ruisdael
Well, my answer does not state that those are threads. Read carefully again, and maybe reflect the other answer provided by the author of htop.Apia

© 2022 - 2024 — McMap. All rights reserved.