【发布时间】:2012-08-16 19:22:41
【问题描述】:
在我的 node.js / express 应用程序的一开始就有一个 microtime() 函数。
function microtime (get_as_float) {
// Returns either a string or a float containing the current time in seconds and microseconds
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/microtime
// + original by: Paulo Freitas
// * example 1: timeStamp = microtime(true);
// * results 1: timeStamp > 1000000000 && timeStamp < 2000000000
var now = new Date().getTime() / 1000;
var s = parseInt(now, 10);
return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}
实际应用的代码如下所示:
application.post('/', function(request, response) {
t1 = microtime(true);
//code
//code
response.send(something);
console.log("Time elapsed: " + (microtime(true) - t1));
}
经过的时间:0.00599980354309082
我的问题是,这是否意味着从 POST 请求到达服务器到发出响应的时间大约为 0.005 秒?
我已经在客户端对其进行了测量,但我的互联网速度很慢,所以我认为存在一些与应用程序本身无关的延迟。有什么方法可以快速简便地检查请求的处理速度?
【问题讨论】:
-
这只是告诉你处理函数所需的时间很短。要完成整个过程,您必须在第一个输入处挂钩 express 并登录 express 流程循环的最终退出。您可能可以为此使用 express.logger,或者您可能希望为此编写自己的中间件提供程序。
-
在heroku上托管时可以做这些事情吗?
-
我不知道你可以在heroku上配置什么,对不起
标签: performance node.js heroku express