1

我有 node10 express 应用程序,例如:

const app = express();
app.use(function(req, res, next) { ..}
app.use(  bodyParser.text({
    limit: '1mb',
    type: '*/*',
  })
); 
more of those..
app.post('myApiName', [(req, res, next) => {..}, (req, res, next) => {..} .. etc many more]);
https.createServer(sslOptions, app) ...

但是有更多的路由和中间件。由于我遇到的阻塞问题,其中 cpu 正在处理某些事情并且“没有响应”几秒钟,我添加了https://github.com/naugtur/blocked-at/blob/master/README.md模块。但它为我提供的大部分堆栈跟踪都是以at Server.connectionListener (_http_server.js:319:3),.... 在自述文件中,它谈到了这一点: In some cases your code is not directly called and tracking it down will still be difficult. See how the HTTP test case produces a stack pointing to Server.connectionListener as the slow function, because everything inside of it is synchronously called. You can always wrap your handlers' code in setImmediate if you become desperate. Or use resources.. 我知道我需要从另一个“来源”运行我的处理程序,该“来源”将从事件循环中的另一个任务开始(我可能措辞不好),但我真的不明白使用 setImmediate 的建议我能做什么. 我看到有一些 npm 库https://www.npmjs.com/package/express-async-handler用于错误处理,但我仍然不确定我的代码应该是什么样子(特别是因为我有很多处理程序和中间件)。我很乐意获得一些建议或一些代码片段,以了解如何获得更好的堆栈跟踪。

4

0 回答 0