进行多次http调用以呈现页面的处理程序需要很长时间才能返回。我想知道哪些电话需要很长时间才能完成。我通过Google搜索找到的分析方法[1]
我正在使用express和Q promises嵌套了几层深层,如果它有任何区别
答案 0 :(得分:0)
使用中间件跟踪请求并记录它们,如果它们花费的时间太长。
一个例子是:
app.use(function(req, res, next) {
var start = new Date;
var maxDuration = 3000; //3 seconds
var url = req.protocol + '://' + req.get('host') + req.originalUrl;
if (res._responseTime) {
return next();
}
res._responseTime = true;
res.on('header', function() {
var duration = new Date - start;
if (duration > maxDuration) {
//this request took longer than 3 seconds, log it.
log('This request took longer than 3 seconds. URL: ' + url + ' Time: ' + duration + 'ms'); //Pseudo code
}
});
next();
});