1

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秒かかることを意味しますか?

クライアント側で測定しましたが、インターネットがかなり遅いので、アプリケーション自体とは関係のないラグがあると思います。リクエストがどのくらいの速さで処理されているかをすばやく簡単に確認する方法は何ですか?

4

1 に答える 1

2

ここで恥知らずなプラグイン。すべての Express リクエストの時間の使用状況を追跡するエージェントを作成しました。

http://blog.notifymode.com/blog/2012/07/17/profiling-express-web-framwork-with-notifymode/

実際、私が最初にエージェントを書き始めたとき、私は同じアプローチを取りました。しかし、すぐにそれは正確ではないことに気付きました。私の実装では、Express ルーターを代用することで、リクエストとレスポンスの間の時間差を追跡します。これにより、トラッカー機能を追加できました。お気軽にお試しください。

于 2012-07-27T03:04:16.670 に答える