New Chat Prototype using Comet and Prototype

Written by on December 18th, 2006 in Ajax News.

Chris Chabot has recently announced a new chat prototype based on a comet iframe connections for real time messaging, ajax for posting messages and sending commands, prototype.js and script.aculo.us as javascript framework, and bases of the newly written dhtml components.

As a side effect of this project, the library & socket daemon framework used by the chat application is released as open-source at http://www.chabotc.nl/phpsocketdaemon

Check out the demo

Chat Prototype

We talked to Chris about his project, and asked him if he could share with us the biggest challenges. He kindly came up with:

The greatest challenge writing this was to make it scale up, and keep IO in check. The orignal plan was to layer out the http, irc and comet components, but the overhead of sending all the event trafic over local loops/connections when dealing with hundreds to thousands of connections, is just to much. All the memory bandwidth used would then be multiplied 3x, which was just a to high of a strain on the system.

Second challenge was that there were no decent comet implementations available (except for dojo’s which i used as a reference), and there was definitely a challenge that there were no PHP (my preferred language) libraries or tools available which could deal with a large amount of always-on connections, even fast-cgi with something like lighttp just wouldn’t scale to hundreds of live connections, and the memory needed would be horrendous, hence the new php socket daemon library was born, its a riskier model, if the program has a fatal crash (great care was taken to avoid this) the service has to be restarted again (happens automaticly), loosing the client connections in the process, however it now only takes 15Mb of memory under moderate load, and guarantees responses in under 0.15ms, something that would be unfeasible with a clasic apache/php situation.

Also most of the heavy lifting (such as link and color parsing, etc) has been lifted to the client, it would be way to heavy for the server to do all of this, and still be able to scale up

Likewise the javascript side of things took a bit of trial and error too, some channels can have thousands of messages, and hundreds of members, so browser speed has defiantly been an thing to optimize too.

Lastly the back-end uses a plain old IRC server, which is almost infinitely scalable, just add a server, link the IRC servers together, and run another web chat back-end on it, repeat ad infintum.. (irc networks are known to have many hundreds of thousands of people connected, using this as the backbone of the messaging provides guaranteed scalability)

Source: Ajaxian
Original Article: http://ajaxian.com/archives/new-chat-prototype-using-comet-and-prototype

Leave a Reply

You must be logged in to post a comment.



Site Navigation