event-loop-blocked

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)

常见根因

修复

相关命令