views:

45

answers:

1

I am trying to work out how to calculate the latency of requests through a web-app (Javascript) to a .net webservice.

Currently I am essentially trying to sync both client and server time, which when hitting the webservice I can look at the offset (which would accurately show the 'up' latency.

The problem is - when you sync the time's, you have to factor in latency for that also. So currently I am timeing the sync request (round trip) and dividing by 2, in an attempt to get the 'up' latency...and then modify the sync accordingly.

This works on the assumption that latency is symmetrical, which it isn't. Does anyone know a procedure that would be able to determine specifically the up/down latency of a JS http request to a .net service? If it needs to involve multiple handshakes thats fine, what ever is as accurate as possible.

Thanks!!

A: 

I think this is a tough one - or impossible, to be honest.

There are probably a lot of things you can do to come more or less close to what you want. I can see two ways to tackle the problem:

  1. Use something like NTP to synchronize the clocks and use absolute timestamps. This would be fairly easy but is of course only possible if you control both, server and client (which you probably do not).
  2. Try to make an educated guess :) This would be along the lines what you are doing now. Maybe ping could be of some assistance in any way?

The following article might provide some additional idea(s): A Stream-based Time Synchronization Technique For Networked Computer Games.
Mainly it suggests to make multiple measurements and discard "outliers". But in the end it is not that far from your current implementation, if I understand correctly.

Otherwise there is some academic material available for a more theoretical approach (by first reading some stuff, I mean). These are some things I found: Time Synchronization in Ad Hoc Networks and A clock-sampling mutual network time-synchronization algorithm for wireless ad hoc networks. Or you could have a look at the NTP-Protocol.

I have not read those though :)

scherand
That's great - some good reading. First link is nearly exactly what I am doing at the moment, but will implement the use of SD to cull outliers responses. If that's as close as it can get, ill have to be happy with that. Thanks again! =)
Brodie