What is the use of pm2 scale option?
Asked Answered
P

1

8

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

Purusha answered 9/5, 2018 at 18:18 Comment(0)
J
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.

Jackass answered 9/5, 2018 at 19:26 Comment(3)
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 processorPurusha
Actually pm2 scale [app] 3 will set the number of instances of [app] TO 3.Seedbed
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,Jackass

© 2022 - 2024 — McMap. All rights reserved.