views:

1345

answers:

5

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".

A: 

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

allesklar
I know that at this point humorous answers are not prized and appreciated on SO but I could not resist.
allesklar
I'd be laughing except that I've been praying for an answer to this all afternoon. I'm building this to help a friend's small business, and since *I* can't get Flash working on one of my browsers, I want to avoid dependent technology if I can.
Sorry. A big reason I made the wisecrack is because I did not have any helpful tip to give. Good luck.
allesklar
+1  A: 

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

cgreeno
Hmm...so they do polling more than 4 times a second and that scales ok? Hmm, then maybe I should think about it, or at least using it as a backup for juggernaut. I suppose hitting 95% of computers and catching the rest should be "ok"
A: 

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.

Jonathan C Dickinson
A: 

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

August Lilleaas
I'm kinda hoping for IRC-level responsiveness, which will transmit multiple messages per second, as they show up.
A: 

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!

Justin Baker