0

So my question is really two parts, firstly; I want to measure the total latency of my requests and client-side js, including time spent waiting for dns to resolve etc.

This all works fine in development because my server and web browser are all on the same machine, so when I compare Time.now.to_i, with the current time as determined with Javascript in the browser it's the true latency of the entire request end-to-end.

The second part of my question is, am I just thinking about this whole thing in the wrong way? Should I be measuring my requests in a different fashion?

P.S., this is not a rails app.

JP Silvashy
  • 46,977
  • 48
  • 149
  • 227

1 Answers1

4

You can't reliably sync time in a browser.

If you just want to measure request time, you don't really need to care what time the server thinks it is. In the browser, just measure the time between initiating the request and when you get a response.

var start = Date.now();
$.get('/url', function() {  // or equivalent in whatever JS framework
    var latency = Date.now() - start; // in ms
});
josh3736
  • 139,160
  • 33
  • 216
  • 263