Server-side Push in Rails

前端 未结 5 1164
萌比男神i
萌比男神i 2021-02-10 10:36

I\'d like to implement a scalable chatroom in rails using AJAX. I know from research that the only scalability happens with a server-side push.

My two questions are:

相关标签:
5条回答
  • 2021-02-10 10:42

    yes, you put 5 lines of Javascript into the client and 20 lines of ruby into a CGI script, and call it a day

    0 讨论(0)
  • 2021-02-10 10:42

    What about Campfire? It polls the server every 5 seconds. Works like a dream.

    0 讨论(0)
  • 2021-02-10 10:49

    If it was that easy to do people would not have built those technologies. IMHO I think polling is always a going to be a hacky way to do it. That Said....

    I am not sure why Juggernaut is off the cards A guy a work for built this site 64Squares with it and is works great.

    I know other sites such as WeeWar use the polling method and they have upwards or 400 request a Min. So I think it would take sometime before the scaling became an issue.

    Good luck

    Cheers

    0 讨论(0)
  • 2021-02-10 10:49

    I'm attempting to do the same right now. Juggernaut works well, but not for Rails 3, and if that isn't a requirement then I suggest using it, because it is dead easy to make a chat. My project uses Rails 3, and polls the server every 3 seconds(Campfire does 3 as well). I'm using Rails Metal to make the polling super fast. If you want to use Juggernaut, then great, 2 lines of client side js, and 1 or 2 of server side. Otherwise, get to work!

    0 讨论(0)
  • 2021-02-10 10:50

    COMET works by keeping the connection to the server open in Javascript (there are plenty of examples on how to get this async data on the COMET website). The server essentially writes the data out and flushes it, this can be done using a Mutex in a tight loop. You will also probably need a message queue of sorts.

    It might be better to learn about BOSH in the long run. It is the natural progression from COMET.

    Although Juggernaut has a learning curve (or it might not really), learning how to do COMET is a steeper one. Even just async pushing is harder. Not only that, but you then need to consider how to make it scale well. I have never used Juggernaut, but as far as ROR plugins go I assume it's trivial. And if they figure out how to make it scale better, you get faster performance for free.

    Polling is another options which should technically work out simpler, however, I am passionate about not using polling as it can kill your server - so I won't elaborate on it here because I feel that polling is the lazy route.

    0 讨论(0)
提交回复
热议问题