0

I'm making a internet speedtest app with Node.js. Everything works fine expect the download test. I normally download at 8Mbits/s but when I try XHR requesting a text file / image (about 256 MByte) at /public/chunk/somefile.txt for example, it downloads it within 1 second which is impossible. Then I checked the onprogress log:

Image

How comes that it loads the image so fast? I mean it isnt cached or anything. Anyways here's the code:

const fileUrl= "/public/chunk/d.jpg";

xhr = new XMLHttpRequest();
xhr.onprogress = (e) => console.log(e, e.loaded - e.total);
xhr.onloadend = () => { console.log("end")};
xhr.open("GET", fileUrl, true);
xhr.setRequestHeader('Cache-Control','no-cache');
xhr.send();

BUT: Here's the thing, if I put in a image url for example: https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg . It works! Why?

Please let me know why it doesn't work, I've been trying around since 5 hours now. Thanks in advance.

saibot-tsch
  • 101
  • 1
  • 8
  • Is the server app running on the same machine while testing? If so, you will be able to download the file at a similar speed as if you would copy it on a local drive. – Christopher Dec 12 '21 at 20:49
  • Yes. But I tried it on my phone too and there it was the same. – saibot-tsch Dec 12 '21 at 21:10
  • If the phone is in the same network, 50MB are nothing. Gigabit LAN connections transfers up to 125MB/s. Wireless connections with 866MBit transfer up to 108MB/s. Maybe [this answer](https://stackoverflow.com/a/38926250/10304804) helps you. – Christopher Dec 12 '21 at 23:29
  • Yes but i download max. 1MB/s. So this cant be possible. Also if i put in the wikipedia url i get a normal result of 0.9MB/s – saibot-tsch Dec 13 '21 at 12:05
  • This doesn't matter, if you load a file from within the LAN (Local Area Network), the transfer rate is not limited to rate your ISP (Internet Service Provider) provides in your area to access the WAN (Wide Area Network). – Christopher Dec 13 '21 at 13:41
  • I posted it as an answer. Glad it helps you understanding transfering files over a (local) network a bit better. – Christopher Dec 13 '21 at 15:12

1 Answers1

0

If you run the web server in on a local machine, the transfer rate is not limited to the rate your ISP provides in your area to access the WAN.

If you test it with another device in the same local network, 50MB might be nothing and will be transfered at half of a second or less.

  • A gigabit LAN connection can transfers up to 125MB/s
  • Wireless connections with 866MBit transfer up to 108MB/s

Depending on the hardware and network setup you can transfer larger files within seconds which may give you unexpected results on speedtests. You can throttle the download speed on the client side using the dev tools of the browser or plugins as mentioned in this answer.

Christopher
  • 3,124
  • 2
  • 12
  • 29