Open jadbox opened 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
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.
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.
I'd love this too.
+1
+1
+1
+1
We need to implement this IMO: https://github.com/soyuka/pm2-childprocess-test
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
Or directly via procfs
@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.
@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.
@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.
+1
+1
+1
Will be shipped in PM2 3.0
+1
and?
Any update on this?
Are there still plans to make it available in PM2 v3 in a future version?
Was this ever implemented/fixed?
Would love this feature!
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.
I tried this and had issues with performances.
monit
part (on-demand with a new option)feel free to help!
any news on this?
+1
+1
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 .
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.
+1
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