[Mongrel] mongrel and comet "implementation"

Zed Shaw zedshaw at zedshaw.com
Thu Aug 10 11:36:04 EDT 2006

On Wed, 2006-08-09 at 23:45 -0700, Topher Cyll wrote:
> Hey folks,
> I was playing around with adding Comet (a javascript technology used
> to receive events without AJAX polling) support to Mongrel. More info
> about Comet here:
> http://en.wikipedia.org/wiki/Comet_%28programming%29)
> I sort of got it working. My code is available at:
> http;//cyll.org/comet.tar.gz

Pretty cool.  So you're using a chunked encoding to stream out the new
data.  One thing:

      @response.write(sprintf("%x;\r\n", size))

You don't need the ";".  That's only required if you add parameters to
the chunked encoding header.  Just give the size (in hex).

I've contemplated doing chunked encodings for Mongrel, but I still have
the problem that frameworks do their headers and body out of order, so
it gets ugly (and also most proxies don't grok chunked encoding).

> The fly in the ointment is that until a Comet request finishes, that
> URL mount point stops responding. I assume this is because of how
> thread management happens in Mongrel. Leaving the request unfinished
> like I do is probably uncool.
That shouldn't happen.  Mongrel isn't locking or anything when running,
so you should be able to server multiple requests.  I'll take a look at
this further.

> One way to sort of work around the problem is to use a dispatcher that
> registers a new handler at a unique URL for each Comet user. You can
> see that both the main page and:
> http://localhost:5555/2
> work simultaneous. And neither affects other mounted handlers, so you
> can also access:
> http://localhost:5555/moose
> Anyways, I'm not really doing anything with this code and I'm sure it
> has problems, but I thought I'd put it out there in case anyone else
> wanted to play around with Mongrel and Comet.

And no idea why that would work.  Like I said, no locking in mongrel but
I'll look at it.

Cool job.  If you get a chance to work this further keep sending me
feedback and code.

Zed A. Shaw
http://www.railsmachine.com/ -- Need Mongrel support?

More information about the Mongrel-users mailing list