You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible to run multiple instances of same app on different ports #322
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 .listen(process.env.NODE_PORT) into your program.
(-f flag is necessary to force re-execution, since pm2 will complain otherwise)
Reacted by Krishna Gopinath, amayoral, Yojan Shrestha, Ghazi Triki, VirtualAdrian, Alec von Barnekow, Ron Karroll, Test account, Matthew Smith, AC and 15 more
Reacted by Nguyễn Vĩnh Hải, Shakir Abdo and nguyen nhut duy
What is the benefit of doing so ? @waygee
Deploying the same application on multiple ports and then attaching a proxy say nginx will help you serve requests better ?
What is the benefit of doing so ? @waygee Deploying the same application on multiple ports and then attaching a proxy say nginx will help you serve requests better ?
hiii!!! @jfoclpf if I use 4 instances with exec_mode: 'cluster' (having 2 cores) I will get 8 instances running?
instance 1 - port 3000 (2 in cluster)
instance 2 - port 3001 (2 in cluster)
....
What is the benefit of doing so ? @waygee Deploying the same application on multiple ports and then attaching a proxy say nginx will help you serve requests better ?
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.
I do have some concerns if this approach will take away perks from pm2 like reload with zero down time. please answer if anyone knows. Thanks
Activity
soyuka commentedon Jun 13, 2014
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.
rlidwka commentedon Jun 22, 2014
... where NODE_PORT is an arbitrary name that you add as
.listen(process.env.NODE_PORT)into your program.(-f flag is necessary to force re-execution, since pm2 will complain otherwise)
Mention #322 tip
aagam29 commentedon Jun 14, 2019
What is the benefit of doing so ? @waygee
Deploying the same application on multiple ports and then attaching a proxy say nginx will help you serve requests better ?
alikarimii commentedon Feb 14, 2020
https://pm2.keymetrics.io/docs/usage/environment/
module.exports = { apps : [ { name: "myapp", script: "./app.js", instances: 2, exec_mode: "cluster", watch: true, increment_var : 'PORT', env: { "PORT": 3000, "NODE_ENV": "development" } } ] }Use increment_var as in example
jfoclpf commentedon May 22, 2022
Load balancing with NGINX, an example
Then in PM2
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
joneldiablo commentedon Nov 24, 2022
hiii!!! @jfoclpf if I use 4 instances with exec_mode: 'cluster' (having 2 cores) I will get 8 instances running?
instance 1 - port 3000 (2 in cluster)
instance 2 - port 3001 (2 in cluster)
....
mfahadshah commentedon Jan 13, 2023
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.
I do have some concerns if this approach will take away perks from pm2 like reload with zero down time. please answer if anyone knows. Thanks