0

I want to measure how long it spend when I post http request from server1 to server2, one thing I need consider is that, server1 and server2 are not in the same host, and there time is not consistent, my plan like this:

I need to post a parameter named startTime before http request post to server2, the value is:

 long startTime = System.currentTimeMillis();

When server2 received the request from server1, another variable name endTime:

long endTime = System.currentTimeMillis();

and the result is :

long result = endTime - startTime;

if the time of server1 and server2 is not consistent, the result is meaningless, so I need to know how to get absolute time of startTime and endTime, can you help me ?

znlyj
  • 1,109
  • 3
  • 14
  • 34
  • I would recommend using a tool to measure the latency time. This Q/A may guide you to solve this problem: http://serverfault.com/q/219982 – Luiggi Mendoza Oct 06 '13 at 15:33

1 Answers1

0

Why aren't you using NTP to get the two host in sync?

It's a really complicate task to get a millisecond precision evaluation of the latency introduced by an Internet communication between two hosts, and you really need to use an external absolute reference.

If your hosts are linux boxes you can use ntpdate to update the system time. If you want to be cool you can also integrate a Java NTP client in your app (even if it'll be easier to just sync the host timing with ntpdate). An NTP java client can be found here http://support.ntp.org/bin/view/Support/JavaSntpClient

elbuild
  • 4,869
  • 4
  • 24
  • 31
  • why I can't see source code with your url? – znlyj Oct 06 '13 at 15:35
  • click on Attachment, in the bottom part :) – elbuild Oct 06 '13 at 15:37
  • you're welcome. I really suggest you to sync you hosts using NTP from the OS itself, it's easier and safer as well. If you're using them in a professional environment where accurate timing is needed (ecommerce for instance). If you find my answer useful please accept or upvote it :) – elbuild Oct 06 '13 at 15:45