0

So I have read a few articles now about how if you have an image of a known size and then you time how long it takes to download that image, you can infer connection-speed/bandwidth.

My thought is, why not use the data from window.performance.getEntries() and take the total transferSize / total duration as the sample size would be much greater and I wouldn't have to instrument any of my own timing or inject any extra arbitrary images as measurement fodder.

Here is what I have done so far just to proof it out.

First I get all the entries with type, size, and duration in tabular-esque format. window.performance.getEntries().map(i => i.initiatorType + ' ' + i.transferSize + ' ' + i.duration );

enter image description here

Then I copy and paste it into notepad++ to do a little regex to clean it up before I stuff it in a spreadsheet.

^\d*:\s"(\w*\s\w*\s[\w\.]*)" enter image description here

From here I am able to paste into Excel.

I am filtering out undefined & navigation initiatorType, and 0 for both transferSize & duration. enter image description here

And a few calculated columns just to get everything into the correct Units.

  • transferSize in MB =(B3/1000000)
  • duration in Seconds =(C3/1000)
  • MBps =(D3/E3)

enter image description here

Then I created a PivotChart enter image description here

Question: Is my math correct? What flaws are there in my logic?

My plan is to codify this, but first I wanted a way to present my logic in a easy to follow layout before I proceed.

Motivation and Sources:

How to detect internet speed in JavaScript? https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/transferSize https://developer.mozilla.org/en-US/docs/Web/API/PerformanceServerTiming https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry

Devin Gleason Lambert
  • 1,516
  • 1
  • 13
  • 22
  • what is the objective of this? Is to identify end user's bandwidth? – karthick Oct 30 '18 at 19:12
  • Yes, I will use this data in our APM software so I can group different segments of users by connection-speed – Devin Gleason Lambert Oct 30 '18 at 19:16
  • Just like what @xjedam has suggested. I was about to write in similar way. Browsers tend to send parallel requests 6 in chrome for http 1.1 so you won't be able to determine the actual bandwidth since it's a sum of the 6 sockets in use. Best is to load a large file after your window is loaded and then analyze that – karthick Oct 30 '18 at 19:58

1 Answers1

0

While its possible to roughly estimate bandwidth this way you will probably have large uncertainity in this measurment.

You are using a large ammount of small files that are potentially loaded in parallel, so you may be measuring transfer time for files sharing the bandwidth between them. Smaller files also tend to give off unreliable results for many reasons.

It would be better to use large file/files like images that can be downloaded while no other network traffic is in play. The longer the measurment the better the results - higher chance to hit a spot when a user is not using his connection for anything else.

This won't be accurate but may give you some idea for profiling purposes if thats what you are going for.

xjedam
  • 1,026
  • 12
  • 15