kzahel / web-server-chrome

An HTTP Web Server for Chrome (chrome.sockets API)
https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb
Other
1.25k stars 271 forks source link

Server is too slow #94

Open photopea opened 7 years ago

photopea commented 7 years ago

When my local webpage loads a local file (XMLHttpRequest) through your server, it is very slow

A 180 MB file takes 40 seconds to load. It is 4.5 MB/s. I have an SSD drive and I believe, that higher speed is possible. The same file is opened much faster, when I open it through an <input type="file" .

Blue-EyesWhiteDragon commented 7 years ago

I can't confirm this to be true with me.

What browser (+version) & JS framework (if any) for XMLHttpRequest are you using, it may help the dev diagnose issues (if any).

photopea commented 7 years ago

I am using the latest Chrome 57.0.2987.133

I create XMLHttpRequest directly. var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = "arraybuffer"; xhr.onload = ....; xhr.send();

kzahel commented 7 years ago

I did not look into optimizing the speed that the server can send files. I suspect increasing the buffer sizes on both the reading file from disk, and the amount that gets written to the socket, would greatly increase the speed.

Right now it reads from disk in in 4096*16 bytes, and writes in chunks of 4096 bytes. Each operation is asynchronous, so that could cause some slowdown.

I don't have time to test tweaking these values, but maybe one of you might try and test using different values and see what the possible speed increase would be.

https://github.com/kzahel/web-server-chrome/blob/master/handlers.js#L79 https://github.com/kzahel/web-server-chrome/blob/master/stream.js#L94

photopea commented 7 years ago

Seems like this may be the reason of the problem. Sadly, I don't have any experience with the development of Chrome extensions. Can anybody else try to change it?

Blue-EyesWhiteDragon commented 7 years ago

I'll have a wee looksie.

photopea commented 7 years ago

Any news? Did changing the chunk size help? :)

kzahel commented 7 years ago

Also it might be useful to test using https://chrome.google.com/webstore/detail/connection-forwarder/ahaijnonphgkgnkbklchdhclailflinn proxy'ing to nginx to see how fast data can flow through this app (which also uses chrome.sockets)

empirephoenix commented 6 years ago

Since I need to locally stream mp4 files, for testing, I did some tests: With the default values, around 1mbyte/s is archived, using instead values with factor*1024, around 100mbyte/s is possible, without any further changes.

photopea commented 6 years ago

@empirephoenix Thanks! I have no experience with creating browser extensions. Can you send me your version, please? Or fork it and put it on Chrome Webstore separately, and send me the link. Thanks!

photopea commented 6 years ago

Can you update it, so it is faster, please?