集群

The cluster_mode will automatically wrap your Node.js app into the cluster module and will enable you to reload your app without downtime and to scale your processes across all CPUs available.

To enable the cluster_mode, just pass the -i option:

$ pm2 start app.js -i 1

To launch max instances (max depending on the number of CPUs available) and set the load balancer to balance queries among process:

$ pm2 start app.js --name "API" -i 0

DEPRECATED (STILL COMPATIBLE):

$ pm2 start app.js --name "API" -i max

If your app is well-designed (stateless) you'll be able to process many more queries.

Important concepts to make a Node.js app stateless: