vid-streamer
vid-streamer copied to clipboard
Feature Request - Max Chunk Size
Hi, I would like to propose an additional (optional) feature that has great benefit for this module.
Background:
I have been building a demo product using Node-Webkit/NW.js and this video streamer module on the backend. The demo I'm working on basically streams n (up to 80 so far... maybe 100 soon) HD videos simultaneously through a single viewer that places the videos in a grid (all videos hosted on different servers running vid-streamer) in order to demonstrate product performance.
Observation:
In the course of developing this demonstration I observed some interesting behavior among browser clients and the video streamer backend. First of all, most browsers when streaming a video tend to send the starting byte value for a byte range but not an ending value. So something to the effect of "154632-" This poses a major problem when streaming many things simultaneously through a single client because, in its current form, the vid-streamer module does not send a reply to the browser that automatically tells the browser that it is getting back a limited byte range. In practice this breaks down as follows:
Browser: Give me all the Bytes! vid-streamer: Ok, let me now pipe out to you all the bytes beginning at that number you sent me...
This becomes an issue because the bytes for an entire movie all get pumped back to the browser through a single http request (depending on keep-alive time between the server and the client) and this causes http request congestion/binding/whatever you want to call it on the client side. This becomes particularly problematic if you want to play more than 10 streaming HD quality movies at the same time in a single client. Browsers like Chrome, which do not allow more than 10 active http requests at a time, will literally wait on the first 10 requests to completely finish (which in the case of an HD movie can take a very long time), and as a result no other movies even BEGIN to download/play. The http requests for all of the other movies are just sitting in the queue waiting on the first 10 http requests to download gigabytes of data, while 10 vid-streamer servers furiously pump GB's of data into single http responses.
Recommendation
To fix this problem I devised a backend oriented solution that actually has other real world applications outside of a silly demo with tons of videos in a single frame (think of limiting long-running http connections in a production environment...). The problem was stemming from tons of http requests queueing on the client side. To force the client queue to rotate and give equal time to all of the movies that should be playing, the backend servers simply needed to be modified to not send an entire movie on an open ended request. I accomplished this by modifying a single behavior in vid-streamer, and making this behavior adjustable/disable-able. The solution behavior breaks down as follows:
Browser: Give me all the bytes! vid-streamer: You get a chunk of that file equivalent to my max chunk size. After that if you want more you can ask for it.
Internally to vid-streamer there is a single value added to the options hash that is called maxChunk, which by default is false, but if it is a number then chunking is enabled. Chunking is only applied to http range requests, and any request without a range is treated normally.
Solution
I have already built out the feature and would like to merge it into your mainline. Please advise on whether you want said feature in the code base, and if so I will create a pull request to close this issue.
TLDR
I want to add a feature to vid-streamer mainline (coding done) to allow vid-streamer to enforce max-chunk-size on byte range requests.
Thanks, Mike