Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of pm2 scale option?

Tags:

node.js

pm2

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

like image 272
anonymous Avatar asked May 09 '18 18:05

anonymous


People also ask

What is the use of PM2?

PM2: A production process manager for Node. js applications that has a built-in load balancer. PM2 enables you to keep applications alive forever, reloads them without downtime, helps you to manage application logging, monitoring, and clustering.

What is PM2 and how it works?

PM2 is a production process manager for Node. js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. Starting an application in production mode is as easy as: $ pm2 start app.js.

What does PM2 reload do?

PM2 allows to reload (auto fallback to restart if not in cluster) an application based on a memory limit/ Please note that the PM2 internal worker (which checks memory), starts every 30 seconds, so you may have to wait a bit before your process gets restarted automatically after reaching the memory threshold.

How does PM2 cluster work?

PM2 is a Production Process Manager for Node. js applications with a built-in Load Balancer. When properly configured, PM2 will automatically run your app in cluster mode, spawn workers for you, and take care of spawning new workers when a worker dies.


1 Answers

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.

like image 184
Rabea Avatar answered Sep 19 '22 22:09

Rabea