Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.56k stars 2.62k forks source link

Support child process monitoring #1869

Open jadbox opened 8 years ago

jadbox commented 8 years ago

I'm using the below standard lib to manually fork processes for my worker; however, those forks do not actually show up in the pm2 monit/list read out. This makes me think that pm2 is unable to detect that a script has manually forked. Is there a way to support showing these manual forks in list/monit?

https://nodejs.org/api/cluster.html

Unitech commented 8 years ago

PM2 embeds the Node.js cluster logic for you, you do not need to do it manually. We may add the feature of monitoring child processes at some point but not for now,

Best

jadbox commented 8 years ago

For my use-case, I require to do it manually. This is because the app is not a web server where ports can be routed between, but rather a worker that needs to fork at will depending on its job.

I'll be looking forward if pm2 supports monitoring when processes get forked internally.

soyuka commented 8 years ago

For this to work, we'd need to access the child processes. I haven't found a way to automate this and child processes would have to notify PM2 they exists.

I'd love this feature too and I'm looking for a way to implement it.

Actually based on the above idea, api could look like this:

const pm2Child = require('pm2-child')

let child = fork('mychild.js')

//bind to pm2, with the fork object we can get back pid. args etc. (maybe streams)
pm2Child(child)

It should work the same way with cluster.

Not sure how pm2 internals will handle those because they won't be "linked" to pm2 as pm2-launched processes would.

mattisx commented 8 years ago

I'd love this too.

ochart2 commented 8 years ago

+1

MoLow commented 8 years ago

+1

scippio commented 8 years ago

+1

jackycute commented 7 years ago

+1

soyuka commented 7 years ago

We need to implement this IMO: https://github.com/soyuka/pm2-childprocess-test

Unitech commented 7 years ago

I still think that using a command based on ps would allow to track the number of child processes for any kind of app managed by pm2

Unitech commented 7 years ago

Or directly via procfs

DevBrent commented 7 years ago

@Unitech I would like to implement our own load distribution algorithm while still maintaining the benefits of pm2 cluster's features. We run unpredictable programs that will stop responding to requests, so we're looking to schedule shut down and load balancing based on a request failures/timeouts closer to how NGINX handles upstream server pools. I sense if we could hook the messaging for scale up/down and shut down instance id X we would have a way to achieve our goals while still maintaining the pm2 cluster functionality.

vmarchaud commented 7 years ago

@DevBrent You should check the API to remove/add process easily, i'm pretty sure you can setup a worker outside of the cluster that is connected to the daemon. EDIT : if you want more informations come over our slack (http://slack.pm2.io) and pm me.

DevBrent commented 7 years ago

@vmarchaud Thanks for the suggestion. In this case we would have to dynamically reconfigure our nginx to use the separate instances. I think we're just going to refactor our request handling servers to no longer perform work and instead have worker processes in another cluster consume them using a job queue. This will allow us to more gracefully (stop consuming, wait for completion) schedule shutdowns prior to/when workers begin to misbehave while not interrupting long-running processes.

Ami777 commented 7 years ago

+1

yourfavorite commented 7 years ago

+1

nickhaughton commented 7 years ago

+1

Unitech commented 7 years ago

Will be shipped in PM2 3.0

FelipeBrizola commented 7 years ago

+1

Frondor commented 6 years ago

and?

nianurag commented 6 years ago

Any update on this?

yuripg1 commented 6 years ago

Are there still plans to make it available in PM2 v3 in a future version?

morgano86 commented 5 years ago

Was this ever implemented/fixed?

LenonLopez commented 5 years ago

Would love this feature!

JMTK commented 4 years ago

Does this work properly if I use the new experimental workers? They all show up under the same process ID rather than separate child processes.

soyuka commented 4 years ago

I tried this and had issues with performances.

  1. make https://github.com/Unitech/pm2/pull/3554/files green
  2. introduce the tree in the monit part (on-demand with a new option)
  3. check perfs

feel free to help!

gcubeda commented 4 years ago

any news on this?

zellb commented 3 years ago

+1

ScottAustin commented 3 years ago

+1

DevBrent commented 3 years ago

There is a reaction system for that. You don't need to waste space commenting.

On Thu, May 6, 2021, 12:11 PM ScottAustin @.***> wrote:

+1

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Unitech/pm2/issues/1869#issuecomment-833648447, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7C36KCVG36VLKSLVLTGTTTMK5TDANCNFSM4BXV4H7A .

andig89 commented 3 years ago

It would be nice if pm2 works with https://www.npmjs.com/package/nps-plus :). For example:

module.exports = {
    default: {
        script (name_script, args) {
            if (process.env.name_lifecycle_event === undefined) {
                process.env.name_lifecycle_event = 'start';
            }

            const nps = spawn(path.join('node_modules', 'nuxt', 'bin', 'nuxt.js'), ['start']);

            nps.stdout.pipe(process.stdout);
            nps.stderr.pipe(process.stderr);

            return '';
        },
    }
}

It works but not in cluster mode :/. Pm2 returns that for example port 3000 is in use.

jackbyebye1024 commented 3 years ago

+1