Realtime web apps rails

  • Published on
    23-Jun-2015

  • View
    2.271

  • Download
    0

Transcript

  • 1. From Web sites to Web apps in Rails Ambert Ho *all images were has7ly ripped o the internet and belong to their respec7ve owner

2. What is a web site vs. web app? Content consump7on vs. interac7on? Facebook and TwiCer blur the line 3. Emerging importance of real7me I use this term loosely since real7me has predened meanings in terms of RTOS Applica7ons should change state regardless of interac7on Even for content sites: TwiCer and Google News update themselves while you look at it Same with Facebook wall, plus FB no7ca7ons Previously, real7me primarily used for chat 4. How does it work? 5. What is comet/reverse ajax/ajax push? (push data to client) Long polling Websockets (ash sockets too) 6. Details: how to actually go about doing this? To bolt onto Rails you need: 1. A real7me endpoint (more on this later) 2. Way to communicate with that endpoint 3. Clientside code organiza7on to process what happens Gimme a real example 7. Juggernaut hCps://github.com/maccman/juggernaut Used to be EM, now uses Node.js Juggernaut logic Redis Gem for interface Node.JS Socket.IO (server) Rails Socket.IO (client) Your JS Client 8. Event Loop (For the real7me endpoint) Why not use Rails all the way? Your web server spins up a worker pool of en7re Rails instances # persistent connec7ons limited by # Rails instances that t in memory spinning up Rails also takes 7me BeCer with REE and CoW Event loops excel at I/O bound tasks* Lot of simple web stu, par7cularly *Its more complicated managing connec7ons like with real7me, If you want to know why is I/O bound research concurrency on JVM 9. Review on what does what Rails, using the Redis gem or some Do it OOB? (Net::HTTP is wrapper like the Juggernaut gem, blocking) publishes to Redis, and since Node.js is subscribed it gets the message, which it boots to the client through Socket.IO the client then uses a framework (like Backbone.js) to work with the piece of data. Backbone is designed towards working with serialized remote data 10. Alterna7ves Pusher Dont have to setup Node and Redis Considera7on with websockets (HTTP 1.1) and servers proxied behind NGINX benets of having it run as a service, but costs $$$ Run the en7re app in Node.js LinkedIn mobile is like this Consider hos7ng (Dotcloud, Heroku, NodeJitsu) 11. Slides http://www.slideshare.net/ambertchContactambert@opzi.comDiscussion/Questions?