Node.js 事件循环阻塞
Node.js 服务健康检查超时、接口延迟抖动,但 CPU 可能不高;日志时间戳跳跃,定时器延迟,Prometheus 的 event loop lag 指标升高。
node --prof app.js
node --prof-process isolate-*.log > profile.txt
使用 clinic:
npx clinic doctor -- node app.js
npx clinic flame -- node app.js
监控 event loop lag:
const { monitorEventLoopDelay } = require('perf_hooks')
const h = monitorEventLoopDelay({ resolution: 20 })
h.enable()
setInterval(() => console.log(h.mean / 1e6, h.max / 1e6), 5000)
fs.readFileSync。worker_threads 或独立服务。*Sync 调用。node --prof — V8 profilerclinic — 性能诊断0x — 火焰图pm2 — 多进程管理