Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct usage of PM2 for Node?

I am considering switching from forever to PM2 to keep my node application up and running.

I am confused about the following recommended methods for starting a process:

$ pm2 start app.js -i 4 # Daemonize pm2 and Start 4 clustered instances of app.js
                        # You can also pass the 'max' params to start

Could someone explain to me what is a clustered instance of app.js? How many instances should I start? 1? Max?

like image 474
user1031947 Avatar asked Mar 20 '26 20:03

user1031947


1 Answers

Clustered app means duplicating the application to use each cpu instead of only one,

If you do:

$ pm2 start app.js

It will only launch one application

If you do:

$ pm2 start app.js -i max

It will launch the maximum number applications depending on the number of cpus available, so if it's a networked app, requests will be balanced between all processes!

like image 171
Unitech Avatar answered Mar 22 '26 09:03

Unitech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!