7

Actually I'm unable to understand the use of pm2 scale [app-name] 10 but I know pm2 start app.js -i 4 is used for starting instances of app in cluster mode.

And one other question what would happen if I'll set number of clusters as -1 means

pm2 start app.js -i -1

Srinivas Nahak
  • 1,846
  • 4
  • 20
  • 45

1 Answers1

14

PM2 is able to create new processes or delete currently running ones depending on the number you provide for the scale option, pm2 scale N, from the documentation: N is a consistent number which the cluster will scale up or down.

pm2 scale app +3 - Adds 3 new processes to the current ones running.

pm2 scale app 3 - Sets the number of instances to 3. thanks @Jolly for the correction.

Regarding the -1 in pm2 start app.js -i -1, it means that PM2 will create a number of new processes that is equal to (Number of Cores)-1.

Rabea
  • 1,938
  • 17
  • 26
  • 1
    Thanks for your great answer by the can i use **pm2 scale app +3** in my server it has 2 gb ram and dual core processor – Srinivas Nahak May 09 '18 at 19:38
  • 1
    Actually pm2 scale [app] 3 will set the number of instances of [app] TO 3. – Jolly Dec 12 '20 at 16:26
  • Correct, thanks for the comment, in the example above, whether it is more than 3 or less, `pm2 scale [app] [number]` will either kill the extra processes, or spin up new ones to match the number, – Rabea Dec 14 '20 at 15:03