Wednesday, July 30, 2008

Server Push with Rails

The web project I'm currently working on just got server-push enabled live web chat. Whole web thing is written in Rails (with Mongrels, Nginx, Memcached and zillion of gems and plugins) and It's quite amazingly simple. I sure didn't expect it to be so simple and straightforward.

First version of this live web chat was made by using Rails periodically_call_remote helper. Every second a request was dispatched to get the fresh set of chat data. This was banging our server quite hard with few tens of users using different chat rooms. We couldn't scale this way. I found several Rails based (or at least being capable of use within Rails) server push options but one stood out - Juggernaut. It uses Flash to keep connection to the client open, supports sending to individual clients as well as sending to groups of clients (with use of channels).

After deploying Juggernaut based live chat code, server load fall dramatically and web app responsiveness increased. It's probably just my enthusiasm but a whole new dimension of possibilities has occurred to me. Presence information and event based actions are just two of what I think endless array of options available with using push instead of standard poll.

No comments: