4 ms·
Really? No Let me repeat: don't do streaming using RoR (or Django, or PHP) This belongs in the web server. There are several extensions that do exactly that,
by raverbashing 14y ago
Really? No
Let me repeat: don't do streaming using RoR (or Django, or PHP)
This belongs in the web server. There are several extensions that do exactly that, in NGINX, Apache, etc. Including streaming, seeking, etc
Unless you want your server to have a ridiculous cpu usage and maybe only serve 1, 2 concurrent requests, do it in the web server.
- robotmay 14y agoI'm not sure I understand your last line there. The request takes exactly the same amount of time as if you weren't using Rails' streaming support and will occupy a web process for the same duration; it just results in some of the data being sent before the response is complete. This yields no net performance increase/decline; it's merely an improvement of the user experience. And yes, there are plenty of ways to perform streaming in the web server itself. I'm not talking about that, but please feel free to write up a post of how to do that and achieve similar results; I'd be genuinely interested.
- raverbashing 14y agoDisclaimer: I didn't try this with rails, but tried this with Django, so YMMV Yes, the request will take more or less the same time But 'pushing' the data through rails/php/python uses a lot of CPU "will occupy a web process for the same duration" no, because then the server will do the work The real question is the CPU usage, if you measured it and it's acceptable, congrats. (In my Django tests, it was around 40% - for one request streaming video) The issue is that, for static data (like files), NGINX (and Apache) can serve a huge amount of requests without flinching. One way to do it is like this: http://wiki.nginx.org/XSendfile http://wiki.nginx.org/XSendfile then your RoR app sends the request to NGINX and it will send the file (and this works with the streaming modules so you can pass the start position, etc)
- robotmay 14y agoOh when it comes to streaming files then I totally agree that the server should do the work. This is more about reducing the visible load time for dynamic pages on a site. My example points to my site (e.g. http://daysoutnearme.com/hubs/city/bath http://daysoutnearme.com/hubs/city/bath) which uses it to improve the load speed of a heavy processing page; the map loads instantly when the remaining chunks of the page come through as the JavaScript has already been processed by the browser.
- raverbashing 14y agoYes, sorry about that, I guess I read 'streaming/chuncking' and got carried away After reading the article I have to say it's quite interesting, and rails makes it very easy to do.
- Loic 14y agoYou can easily do it in PHP, Python or your language of choice using Mongrel2[0]. Because of the asynchronous nature of the messaging between your processes and the Mongrel2 webserver, a single process can efficiently serve 1000's of clients to stream mp3 or whatever file you want. This is because you are not "locking" a process or a thread for a single client. [0]: http://www.mongrel2.org http://www.mongrel2.org
- raverbashing 14y agoThat's what I was trying to remember!