tcp-base
tcp-base copied to clipboard
异常堆栈优化
Checklist
- [x]
npm testpasses - [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [x] commit message follows commit guidelines
Affected core subsystem(s)
Description of change
使用 setTimeout 和 setInterval 现有调用堆栈中看不到调用来源,无法排查原因 移到外面使 err 有完整堆栈信息
可以给个前后效果对比?
唯一的疑惑是每次都 new Error,性能会增加多少开销?
修改前
[pid: 36908][APIClient] ResponseTimeoutError: Server no response in 10000ms, address#xxxxxx (address: xxxxxx)
Error Stack:
ResponseTimeoutError: Server no response in 10000ms, address#xxxxxx (address: xxxxxx)
at Timeout._invokes.set.timer.setTimeout [as _onTimeout] (.../node_modules/tcp-base/lib/base.js:225:21)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
修改后
[Wed Aug 28 2019 14:50:45 GMT+0800 (CST)][pid: 38569][APIClient] ResponseTimeoutError: Server no response in 10000ms, address#xxxxxx (address: xxxxxx)
Error Stack:
ResponseTimeoutError: Server no response in 10000ms, address#xxxxxx (address: xxxxxx)
at Connection.send (.../node_modules/tcp-base/lib/base.js:218:17)
at Connection.sendRequest (.../node_modules/xxxxxx/lib/connection.js:100:11)
at Connection.sendHeartBeat (.../node_modules/xxxxxx/lib/connection.js:142:10)
at Timeout._heartbeatTimer.setInterval [as _onTimeout] (.../node_modules/tcp-base/lib/base.js:442:12)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
至少可以缩小异常来源的范围到某个包了
new Error 本身开销测了下和 setTimeout 也差不多,加了以后整个包的性能还没想好怎么测