6

I have created some Java code that measures delay, packet size and bandwidth.

What is the equation needed to calculate the latency?

This is what I am currently using but unsure it is correct:

//latency = packetsize / delay + bandwidth 
System.out.println("latency is " + (len*2) / (duration + transferRateMb));

EDIT the length is multipled by 2 to give the correct value in bytes

duration is the time taken for the ping to complete

transfer rate is found by :

double transferRateMb = ((len*524288.0) / (duration/ 1000000000.0) ) ; //amount of data in megabytes transferred in 1 second. 

I have read various guides, and do not understand them, this is just a simple requirement for a project

also this will be run 20 times and the average taken

any ideas ?

Erik Godard
  • 5,410
  • 6
  • 26
  • 32
user2065929
  • 999
  • 4
  • 19
  • 33
  • 1
    I hope `(duration + transferRateMb)` giving you double value and [---> Latency and bandwidth](http://wirelesstechnol.wordpress.com/2010/07/09/latency-and-bandwidth/) and already asked [---> how to calculate packet time from latency & Bandwidth](http://stackoverflow.com/questions/8682702/how-to-calculate-packet-time-from-latency-bandwidth) – Smit Apr 15 '13 at 23:23
  • Latency is most affected by network congestion, which will vary greatly over time, and the latency in one direction is probably not going to match the return latency. There is no real way to get a formula to tell you what the latency is. That is why we have tools such as IP SLA to continuously measure the actual latency. – Ron Maupin Aug 07 '16 at 19:20

1 Answers1

0

I always measure the latency. The average latency is usually not very interesting, what you really need to know is how bad can be latency be e.g. the 1 in 100, 1 in 1000 or worse case. To do this you need to measure every individual latency and sample it (or keep the maximum) This will be far higher than your calculation e.g. it could easily be 10x

In short, you can't calculate the latency you should care about, you have to measure it.

Peter Lawrey
  • 498,481
  • 72
  • 700
  • 1,075
  • Thanks i plan to run the tests 20 times and take the average, how can i measure latency ? – user2065929 Apr 16 '13 at 15:36
  • I suggest running the test many times and ignoring either the first 20,000 or the first 2 seconds (to allow the test to warm up) Using a timestamp in the message and comparing this with a time stamp on arrival you record how long each message took If you measure another 10,000 you can get a reasonable 99%tile and if you measure 1,000,000 you get a reasonable 99.9%tile. To get the percentiles, sort the results e.g. in an int[] and take the mid value for 50%, the size*9/10 for 90%tile, the size*99/100 value for 99% and size*999/1000 for the 99.9% – Peter Lawrey Apr 16 '13 at 15:55
  • ok thanks, would my equation be ok for calculating ? – user2065929 Apr 16 '13 at 16:01
  • You can calculate what the best case latency will be. This is not very useful. You can obtain the worst case latency only by test it. – Peter Lawrey Apr 16 '13 at 16:13