在 Debian 上“给 Node.js 提速”可以从系统层面、Node 运行参数、代码与依赖、构建部署几个方向来做。下面按实用程度给你一个清单。
Debian 自带源里的 Node 经常很旧(如 12/14),性能差。
推荐方式(NodeSource):
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
或长期支持版:
setup_18.x
✅ 新版本 V8 更快
✅ 更好的 GC
✅ 支持新特性
NODE_OPTIONSexport NODE_OPTIONS="--max-old-space-size=2048"
常用优化:
--max-old-space-size=2048 # 减少 GC 压力
--jitless=false # 默认开启 JIT
NODE_ENV=production
否则:
npm i -g pm2
pm2 start app.js -i max
好处:
查看:
pm2 monit
Node 默认只用 1 个 CPU。
const cluster = require('cluster');
const os = require('os');
if (cluster.isMaster) {
os.cpus().forEach(() => cluster.fork());
} else {
require('./app');
}
pm2 start app.js -i 4
npm prune --production
npm i -g pnpm
pnpm install
或
bun install
sudo swapoff -a
ulimit -n 65535
写入:
/etc/security/limits.conf
sudo apt install cpufrequtils
sudo cpufreq-set -g performance
nginx 做反向代理 + 静态资源node --prof app.js
node --diagnostics
或用:
0x
clinic.js
如果你愿意:
✅ Debian + Node 20
✅ PM2 cluster
✅ Nginx 反代
✅ Redis 缓存
✅ NODE_ENV=production
如果你愿意,可以告诉我:
我可以给你针对性优化方案。