views:

694

answers:

3

Hello,

I am looking to implement something similar to facebook/gmail chat. I know they use comet & jabber as their technology. But am confused about a couple of things.

  1. Do i really need jabber? Can I instead use a simple mysql table with from, to, message, sent and recd? Are there any inefficiencies in using mysql? Is there any performance loss?

  2. Can comet be implemented using regular web-servers? Do i need to have some special servers? AFAIK, apache+php cannot handle too many open connections? Should I use simple polling, will that have an adverse effect on my system? What can I use out-of-the-box on ordinary webhosts? (Cause if i sell the chat app, it should work for most people.)

  3. Which is the best way (currently) to implement comet? Is the infinite iframe a good idea? Wont php timeout after a while? Will it be a cross browser solution or do i have to write some ugly hacks? Will that lead to server load? What do gmail and facebook use for the forever connection?

Thank you very much for your time.

A: 

I think Jabber can be safely conceptualized as a (mom) middleware, where as MySQL is certainly (persistent store) backend. So that's apples and oranges.

None of the mega scale web2.0 applications can rely on RDBMS for realtime messaging given the limits that is encountered due to the ACID guarantees of a RDMBS, and its scaling characteristics. (Think of partitioning your SQL tables on the fly to add more servers to get a sense of just one of the issues involved.)

The most important consideration is the durability of the messages in your system. Are they to be persisted forever or only during a given time window. Given that its a chat application, more than likely it is the latter. Why not use a memory based store instead of an RDBMS?

Why should you use Jabber? Well, its a sort of standard, so you'll open up the interop possibilities in the future, even if that is not an issue at this point.

More importantly, it is a system that's been under serious development for a long time (in internet dog years), so its certainly fair to assume that it is (as of now) and will continue to be more mature than whatever you manage to design, implement, debug, and make production ready in house.

Entirely clueless about comet, so no comment!

+3  A: 

Great questions, hopefully this won't get lost in the stack on the weekend. If you want to use flash kirupa has a good tutorial on how to use PHP and sockets. As far as comet goes, I believe you have to have some sort of server implementation. That is about where my feeble knowledge ends right now.

Simple polling example (jquery + asp.net) http://trappedinhoth.blogspot.com/2009/04/ajax-jquery-chat-demo.html

Kirupa's tutorial (php5 sockets + flash 8) http://www.kirupa.com/developer/flash8/php5sockets_flash8.htm

Open source flash chat client (google, plenty more) https://blueimp.net/ajax/

Comet info http://cometdaily.com/

I'm not really answering your question, just pointing you to more resources. I'm very curious as to what others will answer.

infocyde
A: 

Do i really need jabber? Can I instead use a simple mysql table with from, to, message, sent and recd? Are there any inefficiencies in using mysql? Is there any performance loss?

Yes, you do need to use jabber and not mysql. You can read [The End of an Architectural Era (It’s Time for a Complete Rewrite)][1] by Stonebraker et al for the details of why using an RDBMS is a bad fit.

Can comet be implemented using regular web-servers? Do i need to have some special servers? ... Should I use simple polling, will that have an adverse effect on my system? What can I use out-of-the-box on ordinary webhosts? What do gmail and facebook use for the forever connection?

Comet is a bit of a nebulous term but not to worry. You don't need special servers, you shouldn't use polling. You can use [BOSH][2] - which is also what Facebook (and I suspect Gmail) uses.

Use [JSJaC][3] (or [my fork on Github][4]) on the client side and [ejabberd][5] on the server side. Both support [BOSH][6] (and [XMPP over BOSH][7]) meaning you can make HTTP connections to your XMPP server directly, avoid polling and handle high traffic loads.

Links for all of these are bookmarked at http://delicious.com/petef/stackoverflow-843889