Node.JS Response Time

前端 未结 2 544
青春惊慌失措
青春惊慌失措 2021-01-04 07:22

Threw Node.JS on an AWS instance and was testing the request times, got some interesting results.

I used the following for the server:

var http = req         


        
2条回答
  •  迷失自我
    2021-01-04 08:14

    While Chrome Developer Tools is a good way to investigate front end performance, it gives you very rough estimate of actual server timings / cpu load. If you have ~350 ms total request time in dev tools, subtract from this number DNS lookup + Connecting + Sending + Receiving, then subtract roundtrip time (90 ms?) and after that you have first estimate. In your case I expect actual request time to be sub-millisecond. Try to run this code on server:

    var http = require('http');
    function hrdiff(t1, t2) {
        var s = t2[0] - t1[0];
        var mms = t2[1] - t1[1];
        return s*1e9 + mms;
    }
    http.createServer(function(req, res) {
      var t1 = process.hrtime();
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.write('Hello World');
      res.end();
      var t2 = process.hrtime();
      console.log(hrdiff(t1, t2));
    }).listen(8080);
    

    Based on ab result you should estimate average send+request+receive time to be at most 4.2 ms ( 4200 ms / 10000 req) (did you run it on server? what concurrency?)

提交回复
热议问题