cloudflare / speedtest

Component to perform network speed tests against Cloudflare's edge network
https://speed.cloudflare.com
MIT License
385 stars 28 forks source link

CLI #26

Open notpushkin opened 9 months ago

notpushkin commented 9 months ago

Thanks for this project! Are you also planning to add a CLI interface? Someone on HN has already started an implementation, but perhaps you could collab and release it as part of this package.

bmo-at commented 9 months ago

Oh hi, I am that someone :) It's more for a personal project of mine, but I'd be happy to contribute back if there is interest. Unfortunately, according to #17 a CLI is out of reach (for now) due to nodejs being incompatible with this library.

ToshB commented 5 months ago

https://github.com/nodejs/undici/pull/2481 was just merged, which adds the PerformanceTiming API entries needed for this library. So we're getting closer to getting this working in node.

hakonk commented 4 months ago

That's great @ToshB! Any idea of how long it will take of the release of Node with the mentioned features?

ToshB commented 4 months ago

Looks like it was merged into Node two days ago, https://github.com/nodejs/node/commit/05f81721889571f615e36bf70fac759f4d118513, so it shouldn't be too long.

bmo-at commented 4 months ago

And works like a charm too with the nightly build of node 22:

❯ node
Welcome to Node.js v22.0.0-nightly202401090090c10782.
Type ".help" for more information.
> const {default: Speedtest } = await import('@cloudflare/speedtest');
undefined
> (node:50124) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
> new Speedtest().onFinish = results => console.log(results.getSummary());
[Function (anonymous)]
> {
  download: 225662382.7740472,
  upload: 37244214.56244167,
  latency: 17.63653700000069,
  jitter: 1.0500115789465496,
  downLoadedLatency: 27.033390500009148,
  downLoadedJitter: 16.086571000001342,
  upLoadedLatency: 42.60906900000435,
  upLoadedJitter: 70.95178205555446
}

I was gonna try and run this in my golang based speedtest background task as some sort of abomination where I'd use it in chrome via devtools and get the results that way, but I was too busy lately and my current speedtest provider was ok enough. But now I will definitely rebuild this with the cloudflare speedtest. Thanks @ToshB for your effort!

hakonk commented 4 months ago

I tried it too with v22 nightly. Very smooth! Thanks @ToshB!

ToshB commented 4 months ago

Very cool! I am curious to see if the Node speedtest results are comparable to the browser results. I would assume the fetch-implementations in browsers are tuned to the extreme..

Note that there are some speedtest engines which is still not compatible with Node. Specifically the packetloss tests, which requires WebRTC. I was not able to find a working Node implementation of RTCPeerConnection.

hakonk commented 4 months ago

Very cool! I am curious to see if the Node speedtest results are comparable to the browser results. I would assume the fetch-implementations in browsers are tuned to the extreme..

I've tried a browser based speed test in chromium on a raspberrypi where the bandwidth was severely limited for reasons I don't know. The ookla speed test CLI works, but I'm a bit cautious as it collects so much data from the client.

This node based speed test seems to be a better alternative.