small medium large xlarge

09 Mar 2013, 00:05
James West (104 posts)

Hi Sam First of all congratulations on the new edition, I know it must have been a lot of hard work to refactor the book with the changes made in Rails 4 but I would like to make a suggestion for an addition to the book.

ActionController::Live is a major new feature of Rails 4 that will have a major impact in the Rails world and it’s ommission from the book is a major oversight. Live streaming would majorly enhance the Depot application and it has a major impact on a production server as regards top performance, server resources needed and what rails servers should be used if implementing ActionController::Live

It would be fantastic to see how you would implement ActionController::Live to say update available quantities or show a count of number of books sold today. I can think of many examples where live streaming would be a good fit but most importantly your opinions on where and how it should be used and where it is not a good idea to use it would be an invlauable section.

I appreciate that re-working the book to change what was already there must be a lot of work but it is equally important to include the newer features available.



09 Mar 2013, 01:32
Sam Ruby (634 posts)

Initial thoughts: update available quantities or count of number of books sold today don’t really require keeping a socket open. A combination of setTimeout and AJAX are fine for that.

Bookstores these days, however, often have a downloadable link providing the book in one of various eBook formats. Reading a multi-megabyte file into memory before you stream the first byte and keeping the entire file in memory until you complete the request is somewhat suboptimal.

Changing the stream to loop on reading and writing blocks (or generating gibberish) would do the trick. Very simple example that can be easily understood.

One problem is that webrick doesn’t stream. I see that Unicorn isn’t optimal for this (it apparently closes streams that are kept open). I haven’t tried Apache/Passenger yet.

09 Mar 2013, 01:44
James West (104 posts)

I believe rainbows and puma servers are both capable of handling streaming and seem to be mooted as the server to use.

That’s an interesting thought on setTimeout and AJAX. Not something I had considered myself.

09 Mar 2013, 02:12
Sam Ruby (634 posts)

Initial feedback I got was that passenger/apache “should” work. Initial testing indicates that that combination doesn’t (yet?).

setTimeout and AJAX are fine for “human” timeframes (e.g. seconds and minutes), and have the advantage of being able to dynamically distribute requests across a pool of servers. Works fine for applications like “realtime” stock quotes which actually update every “n” seconds. The downside is the latency and overhead of separate requests.

Streaming is best for when you need “computer” timeframes (e.g. milliseconds).

I also would like to only “whet your appetite” for this, and point to the Rails Guide for those that want to dig in. Unfortunately, they don’t have a Rails Guide for this yet.

You must be logged in to comment