user2065929
user2065929

Reputation: 1095

How to calculate the latency and bandwidth of a network

i have code that pings several machines, and records the time, it does this for various packet sizes ( 1kb to 100gb ), but i would like to know how to calculate the latency of the network, how can this be achieved ?

this is the code i am using to measure the ping :

also how can i measure the bandwidth of the system as well ?

Thanks for the help guys !

Upvotes: 0

Views: 2590

Answers (1)

Cedric Reichenbach
Cedric Reichenbach

Reputation: 9319

In the ideal case where latency and bandwidth are fully constant, it's just a linear problem:

delay = packetsize / bandwidth + latency

There are two variables, bandwidth and latency, so you need at least two different records to solve it. However, I'd suggest to calculate them for many data pairs and e.g. take the median of all your results.

I think solving the above equation should be easy. If not, feel free to ask.

Update: How to solve the above equation

Let
y1, y2 values for delay
x1, x2 values for packetsize
a := 1/bandwith
b := latency

y1 = a * x1 + b
y2 = a * x2 + b
=> b = y1 - a * x1              [1]
=> y2 = a * x2 + y1 - a * x1
=> a = (y2 - y1) / (x2 + x1)
Now put it in equation [1]:
=> b = y1 - (y2 - y1) / (x2 + x1)

Now you have b for the latency and 1 / a for the bandwidth.

Upvotes: 3

Related Questions