You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于pm2 scale选项用途及集群数设为-1作用的技术咨询

PM2 Cluster Mode: Explaining scale and -i -1 Usage

Hey there! Let's break down your questions about PM2's cluster mode commands clearly:

1. What does pm2 scale [app-name] 10 do?

You already know that pm2 start app.js -i 4 launches your app with 4 cluster instances right from the start. The pm2 scale command is for adjusting the number of running cluster instances dynamically, without having to stop and restart your entire application.

  • If your app is already running with, say, 4 instances, running pm2 scale my-app 10 will spin up 6 additional instances, bringing the total to 10.
  • Conversely, if you wanted to scale down (e.g., pm2 scale my-app 2), PM2 will gracefully shut down the extra instances, ensuring no in-flight requests get dropped unexpectedly.
  • This is perfect for handling traffic spikes or trimming resource usage during off-peak times—you don't have to kill the whole app to adjust capacity on the fly.

2. What happens when you run pm2 start app.js -i -1?

Setting the instance count to -1 tells PM2 to automatically match the number of cluster instances to your machine's CPU core count.

For example:

  • If your server has 8 CPU cores, PM2 will start 8 cluster instances of your app.
  • This is essentially a shortcut for using -i max (which does the exact same thing).
  • The goal here is to fully leverage your server's multi-core resources—since Node.js is single-threaded by default, running one instance per core lets you maximize performance and throughput for your app.

内容的提问来源于stack exchange,提问作者Srinivas Nahak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:39:47