Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support child process monitoring #1869

Open
jadbox opened this issue Jan 1, 2016 · 32 comments
Open

Support child process monitoring #1869

jadbox opened this issue Jan 1, 2016 · 32 comments

Comments

@jadbox
Copy link

jadbox commented Jan 1, 2016

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

@jadbox jadbox changed the title Using native Node Cluster support Support native Node Cluster.fork Jan 1, 2016
@Unitech
Copy link
Owner

Unitech commented Jan 4, 2016

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

@Unitech Unitech closed this as completed Jan 4, 2016
@jadbox
Copy link
Author

jadbox commented Jan 4, 2016

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
Copy link
Collaborator

soyuka commented Jan 4, 2016

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.

@soyuka soyuka changed the title Support native Node Cluster.fork Support child process monitoring Jan 5, 2016
@soyuka soyuka reopened this Jan 5, 2016
@mattisx
Copy link

mattisx commented Jan 24, 2016

I'd love this too.

@ochart2
Copy link

ochart2 commented Apr 26, 2016

+1

3 similar comments
@MoLow
Copy link

MoLow commented Jul 22, 2016

+1

@scippio
Copy link

scippio commented Nov 3, 2016

+1

@jackycute
Copy link

+1

@soyuka
Copy link
Collaborator

soyuka commented Dec 24, 2016

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

@Unitech
Copy link
Owner

Unitech commented Dec 24, 2016 via email

@Unitech
Copy link
Owner

Unitech commented Dec 24, 2016 via email

@DevBrent
Copy link

@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
Copy link
Contributor

vmarchaud commented Feb 15, 2017

@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
Copy link

DevBrent commented Feb 16, 2017

@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
Copy link

Ami777 commented Apr 26, 2017

+1

@yourfavorite
Copy link

+1

1 similar comment
@nickhaughton
Copy link

+1

@Unitech
Copy link
Owner

Unitech commented Jul 20, 2017

Will be shipped in PM2 3.0

@Unitech Unitech added the PM2 v3 label Jul 20, 2017
@FelipeBrizola
Copy link

+1

@Frondor
Copy link

Frondor commented May 12, 2018

and?

@nianurag
Copy link

Any update on this?

@yuripg1
Copy link

yuripg1 commented Jul 27, 2018

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

@morgano86
Copy link

Was this ever implemented/fixed?

@LenonLopez
Copy link

Would love this feature!

@JMTK
Copy link

JMTK commented Apr 23, 2020

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
Copy link
Collaborator

soyuka commented Jul 17, 2020

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
Copy link

gcubeda commented Nov 9, 2020

any news on this?

@zellb
Copy link

zellb commented Nov 24, 2020

+1

1 similar comment
@ScottAustin
Copy link

+1

@DevBrent
Copy link

DevBrent commented May 6, 2021 via email

@andig89
Copy link

andig89 commented Jul 2, 2021

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
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests