Need help with a couple of javascript programs

blr_p

Skilled
There are two scripts i found for network bandwidth measurement. One is a simple JS to measure download/upload. The problem i have with this one is the script requires to be customised to accept POST commands and that depends on the server. So it allows download to the client browser but won't allow upload.

The other is a NodeJS script, but i cannot get the script to work reliably for some reason. The author provides the sources on github and provides a demo which woks very well.

Anybody good with JS that can help out here ?
 
Just post the details and if someone can help, they'll post.
I've been working on a lot of JS lately. I could try and have a look if I get some time.
 
Ok, so the idea is to do a wifi bandwidth test if you have a mobile, tab, smart tv, ps3. Just point the devices web browser at your designated web sever and perform a bandwidth test so you can tell how fast the wifi connection is at different distances from the wifi router.

This is the first script.

JSBandwidth

Now for the webserver, i found mongoose to be simple, just one exe, drop the script in, start it up and everything is good to go.

Now the upload bit is what i need help with and is sperver specific. The script writer says the following...

Caveat: The upload test needs to be able to send a POST request to the server. The receiving page doesn't have to do anything with the data. However, some servers will not allow you to send a POST request to a .htm file. Therefore, the project includes several blank server side script files (post.aspx, post.php, post.pl). If the default script doesn't work, you'll need to edit the javascript at the top of the default.htm page to post to a different page that is compatible with your web server configuration.

There needs to be a specific server side script that allows a POST. I don't know how to do this bit. Can you help with that ?

Alternatively suggest another webserver that is as light and easy to use which will work.

The idea is to make it easy to do bandwidth tests. ideally just one exe click and point the browser would suffice but people are not supposed to take exe's from strangers and run on their machines, getting it from the official sources is safer but a little more cumbersome. I don't think there is any way around it atm.
 
Were you able to get the download part working okay? What did you use to serve the bigfile.bin file? Did you set up your Mongoose server?

Also, wrt the upload part... if you're going to make a POST to your webserver via JS, you're going to be restricted by the same-origin policy. That means that, to keep things simple, you have to serve your default.htm page through the same web server that is accepting the upload requests. In other words, you can't setup your server just for the POST url and then run your default.htm page as a standalone page just by double-clicking it anywhere. They both have to be part of the same 'web app'.

Well, you can get around the same-origin policy by mucking around with JSONP requests, but I don't know if you want to spend time in that direction.
 
Download works fine, need help to get the upload part to work.

That is specific to mongoose and i'm not sure how to do that. It depends on which webserver is chosen, there are other servers that could handle it as is but that would be difficult for people to setup and to explain by me compared to mongoose (or so i think).
 
There needs to be a specific server side script that allows a POST. I don't know how to do this bit. Can you help with that ?
I've never used Mongoose, so I don't know if it'll work for sure, but the author's idea is to change "post.aspx" in line 38 of default.htm to something else, like "post.php" or "post.pl" (just make sure a file with that name exists).

You might also want to check if there's a size limit for uploads. You can probably change it in Mongoose.

Alternatively suggest another webserver that is as light and easy to use which will work.
If you haven't set up web servers before, you'll probably have to stick to Mongoose. If you're willing to learn and spend some time, try Apache or Nginx.

A suggestion: I don't know what exactly you plan to use this for, but if you plan to make it publicly available, either hire someone to secure your server or get a shared hosting plan.

Edit: I missed the part in which you explained how you plan to use this. I think you'll have to stick to Mongoose.
 
A suggestion: I don't know what exactly you plan to use this for, but if you plan to make it publicly available, either hire someone to secure your server or get a shared hosting plan.
Plan to post it on this forum to help members measure wifi throughput.

It needs to be easy to setup for members.

That's why i thought mongoose was simple. Provided the script works. It does but only the download part, not the upload.

[DOUBLEPOST=1374442267][/DOUBLEPOST]
I've never used Mongoose, so I don't know if it'll work for sure, but the author's idea is to change "post.aspx" in line 38 of default.htm to something else, like "post.php" or "post.pl" (just make sure a file with that name exists)
I tried that but i think the files need some code in them and im not sure what mongoose expects there.
 
Okay, I did some quick tests and it looks like Mongoose by default simply terminates the connection if you try to make a POST request.

Firefox reports an NS_ERROR_NET_RESET and Mongoose reports this:
Code:
[<timestamp>] [error] [client 127.0.0.1] POST /post.aspx: mongoose.c:1349: CreateProcess(/path/to/post.aspx): 193

It makes sense, cause a POST request is meaningless without a CGI handler.

The remedy is to use the Mongoose + PHP bundle and change "post.aspx" to "post.php" in default.htm.

Tip: If you rename default.htm to index.htm, you can start the test simply typing http://[IP address]:8080/ (no need to type index.htm)
 
Was busy with other stuff so missed this. Thx for that, upload now works with the php bundle.

Have to say the upload speeds seem a bit on the high side compared to the download so not too sure whether to trust it. Might have something to do with the cgi handler.

Can we try with the other script which uses NodeJS ?
 
Thx for that, upload now works with the php bundle.
You're very welcome.

Have to say the upload speeds seem a bit on the high side compared to the download so not too sure whether to trust it. Might have something to do with the cgi handler.
I'm not completely sure, but it's probably because when downloading, the file has to be read from the hard drive but while uploading, the data is only stored in RAM.

To normalize the upload and download speeds, you can replace the download file with a simple script which outputs something without reading from a hard drive. Use the following PHP script instead of bigfile.bin (change references to bigfile.bin in the HTML file).

PHP script (untested and perhaps inefficient) -
PHP:
<?php

// Echo 32 MiB of crap
for ($i = 0; $i < 32 * 1024 * 1024; $i++) {
    echo 'a';
}

Can we try with the other script which uses NodeJS ?
I'm really not a node.js guy, but post the code here and I'll try.
 
Last edited:
I'm not completely sure, but it's probably because when downloading, the file has to be read from the hard drive but while uploading, the data is only stored in RAM.
Believe you're right about this and indicated the weakness of this script with uploads .

However the download figures are in the right ball park.

To normalize the upload and download speeds, you can replace the download file with a simple script which outputs something without reading from a hard drive. Use the following PHP script instead of bigfile.bin (change references to bigfile.bin in the HTML file).

PHP script (untested and perhaps inefficient) -
PHP:
<?php

// Echo 32 MiB of crap
for ($i = 0; $i < 32 * 1024 * 1024; $i++) {
    echo 'a';
}
Since the purpose is to test streaming ability and files are necessarily on a HDD somewhere i don't think this will work. The download part simulates a download, the upload however should also have something to send but i think that will require local permissions and the user to select a file to send back to the server which will be more complicated.

Anyway, the download part is the most important bit here as that is what most people will be interested in.

I'm really not a node.js guy, but post the code here and I'll try.
Are you aware of any php scripts that do the same, i'm not too tied to mongoose, any language or server will do so long as its simple to setup for novices to do some testing.

This Node JS script does 3 downloads of increasing size and then calculates an average, same with upload compared to the previous JS. Multiple transfers are more reliable than just one transfer. Here is the script.

Speedtest

The demo for the script referenced by the blogger provided here works perfectly. The problem is i can't get the scripts he put up on github to work. Either there is a configuration problem or the script is buggy

There are four branches there, tried with master, nothing, then experimental, also nothing. By nothing i mean the browser does not even get a response from nodeJS. Split seemed to work in the sense i could get the webpage to display but the formatting was all over the place. Reason i picked nodejs was simplicity and cross platform support, tried on XP with the windows 32 bit binary from here.

What can be simpler that unzipping the script, drop the nodejs exe in the same folder and run it.

Appreciate you taking the time to look at this :)
 
Last edited:
The code honestly looks horribly written and I don't even understand the purpose of some parts of it, but I was able to find a solution that works: delete lines 33 and 104 from bin/speed.js
 
Thx a lot man, you made quick work out of that and the master now works.

The jsbandwidth script gives a 50% higher reading on downloads than the second script. However when i did ftp tests the readings i got were closer to the second set of results than the first. The average isn't the correct result as it gets overly skewed at the beginning. Rather its the median Mbs rate that is more important here.

What i notice with this script is that there are no physical files required at the outset to be transferred but rather the script generates files on the fly and sends them over to the client. Don't know what to make of that but the speeds don't seem to far off.

When i write these up on the networking section will credit you for helping out :)
 
Last edited:
Thx a lot man, you made quick work out of that and the master now works.
You're welcome.

The jsbandwidth script gives a 50% higher reading on downloads than the second script. However when i did ftp tests the readings i got were closer to the second set of results than the first.
I do suggest you try this on multiple setups. The fact that the speeds reported by the app and your FTP program are similar could be a co-incidence and might not be true for everyone.

What i notice with this script is that there are no physical files required at the outset to be transferred but rather the script generates files on the fly and sends them over to the client. Don't know what to make of that but the speeds don't seem to far off.
I don't know why that could be happening either, but my best guess is that node.js isn't optimized for high-speed data transfer. I believe a separate web server is often recommended for static files when using node.js. That could be for the same reason.

When i write these up on the networking section will credit you for helping out :)
Thanks. Don't feel compelled though.
 
I do suggest you try this on multiple setups. The fact that the speeds reported by the app and your FTP program are similar could be a co-incidence and might not be true for everyone.
Hence the idea of getting people here to try it out. The problem is deciding who is right. Measurements are a very tricky business. People have the expectation they will get a reading they can trust. Right now i'm not sure what to trust. I have yet another tool made by a networking company but it sends payloads of max 1kByte and its readings are the highest i've seen. Correlates more with specs, 5Ghz gives better throughput than 2.4Ghz etc. Thing is i don't see that kind of performance improvement in real life at least not for the specific purposes i'm interested in. The two scripts here don't show those improvements at all.

These scripts send MBs of data over HTTP which is what happens with DLNA and is much closer to real life use when streaming movies that can be in the hundreds of MBs and even a few GBs. Smaller payloads get higher throughput figures whereas bigger payloads tend to slow down and then stabilise at a lower figure. That figure is what matters as it ultimately determines what can be streamed or not.

II don't know why that could be happening either, but my best guess is that node.js isn't optimized for high-speed data transfer. I believe a separate web server is often recommended for static files when using node.js. That could be for the same reason.
That's a good point, i need to try this with a server that is capable and then see the difference. Any industry strength webservers you want to suggest. Apache, nginx etc ?

Thanks. Don't feel compelled though.
Could not even get these scripts running in the first place without your help. I'm now in a better position to evaluate their utility.
 
Last edited:
That's a good point, i need to try this with a server that is capable and then see the difference. Any industry strength webservers you want to suggest. Apache, nginx etc ?
You can use the first script with Apache or nginx. The performance should be about the same with either of them for your usage.
 
Back
Top