Friday, June 30, 2006

More on Ajax/Comet and Server-side vs Client-side Polling

I did some more searching and reading, and my previous entry here was not really "Comet". Comet is synonymous with slow load or "reverse AJAX", and uses a hidden frame to keep a connection literally open to the server. The browser window (at least in FF 1.5) shows the page as continuously loading.

Since I could not originally figure out how to keep the connection open - this is, AFAIK, impossible using the XMLHttpRequest object - I artificially replicated a listening function. Basically like regular AJAX-style polling, but with the onus of the polling placed on the in-memory user array on the server side. The technique avoids connections to the server by the client at regular intervals, and does not seem to add much work to the web server to poll the queue for each user at 100ms intervals. With high traffic however you could potentially get a lot more connections, and I'm not completely sure how or when the framework will release the thread if the connection times out without some more policing on the server-side polling algorithm.

It is pretty responsive in the testing I have done so far, though I have limited resources to really scale the thing up. It is nice to have a more-or-less instant response from the server and not have to poll from the client. I also like the degree of control that the XMLHttpRequest offers. I'll have to play around with the slow load a bit more and see how it compares. Slow load would certainly seem to be more efficient in terms of resources, both on the client and on the server.

No comments: