2

How to calculate internet speed in server side node.js, From client side i am sending current time stamp while making the http request in query string.

client side code

  var image = document.createElement("img");
      image.width = 1;
      image.height = 1;
      image.src = url+"?"+new Date().getTime();

url looks like below

  http://localhost:8080/server?1369654461767

Internet speed calculation can be done using start time, end time and downloadable file size of the request.

But, My problem above request is 1x1 pixel so image size can't be determined, and i don't want one separate sever call for calculating net speed.

Any solution for calculating internet speed using start time from client and data which is present in request and response.

Any idea will be helpful.

Community
  • 1
  • 1
karthick
  • 5,998
  • 12
  • 52
  • 90

1 Answers1

5

You're not going to be able to calculate the internet speed on the server. One critical problem is the start time is based on the client clock and the server's clock will never be in sync enough for the purpose of calculating speed.

To calculate speed you need a full round-trip where you can capture start and end time accurately from the same machine--both on the client. You also need to send something more significant than a 1px image. The smaller the payload, the less accurate the calculation.

Typically speed is calculated by requested several large responses of known sizes.

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182