-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Possible to run multiple instances of same app on different ports #322
Comments
You could clone your app 4 times... I think there are better solutions as load-balancing for those kind of things but pm2 can't handle this without some heavy mods. |
... where NODE_PORT is an arbitrary name that you add as (-f flag is necessary to force re-execution, since pm2 will complain otherwise) |
What is the benefit of doing so ? @waygee |
https://pm2.keymetrics.io/docs/usage/environment/
|
Load balancing with NGINX, an example
Then in PM2 module.exports = {
apps : [
{
name: "myapp",
script: "./app.js",
instances: 4,
exec_mode: "cluster",
watch: true,
increment_var : 'PORT',
env: {
"PORT": 3000,
"NODE_ENV": "development"
}
}
]
} Although PM2 with instances already does load balancing, so I don't know if it's worth the effort. The nice thing here is that you're not limited by the number of cores Check this article |
hiii!!! @jfoclpf if I use 4 instances with exec_mode: 'cluster' (having 2 cores) I will get 8 instances running? |
In my case i need to do it because pm2 doesn't work well with socket io long polling so i used this approach to let nginx load balance my app with ip_hash. |
Hi,
I wanted to inquire whether it's possible to run my app.js multiple clusters like so:
app.js Cluster1 port 80
….
app.js Cluster2 port 81
….
app.js Cluster 3 port 82
….
app.js Cluster 4 port 83
My hosting provider, Rackspace, has advised me to try to set up this way.
Is this possible to do this under pm2 and have my app.js be running multiple clusters under different ports?
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: