Question

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:

1) In a reasonably efficient chat server, at what point does polling become prohibitive? 2) I really don't want to use Juggernaut. I don't know much about how comet works. I guess I'm wondering if this would be horribly difficult for me to build using Javascript (to create a client side server/poller) and another language (to provide efficient polling for clients behind a firewall, and an integration into the CGI). and 3) (yes, out of 2), whether I'm even going about it the right way?

The simplest answer I could hope for is a quantified "yes, you put 5 lines of Javascript into the client and 20 lines of ruby into a CGI script, and call it a day".

Was it helpful?

Solution

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

OTHER TIPS

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!

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top