# Complex alternative to Ajax polling

**URL:** <https://www.ruby-forum.com/t/complex-alternative-to-ajax-polling/185753>\
**Category:** Rails\
**Created:** [March 25, 2010, 4:47pm UTC](https://www.ruby-forum.com/t/complex-alternative-to-ajax-polling/185753 "2010-03-25T16:47:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [March 25, 2010, 4:47pm UTC](https://www.ruby-forum.com/t/complex-alternative-to-ajax-polling/185753/1 "2010-03-25T16:47:57Z")

</div>

I had seen that many of the periodic update methods looking for  
changes to display in the browser in the rails book poll the server  
every so many seconds which seems to generate alot of traffic.

A project that I had been working on is they want to make an ajax  
request to the server which will just wait and never return until the  
server decides that a change has occurred and at that time which could  
be several minutes or hours the response would go back to the browser.  
The problem with this seems to be that it won’t work with rails  
because each http request is serial. In order for this to work, I need  
some kind of proxy server or alternative server through some other  
means that can have multiple http requests outstanding and these would  
either time out eventually or return at some point.

How can I do this or which rails books, blogs, or websites might have  
examples ? Can webrick or event machine be usefull here ?

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [March 25, 2010, 5:31pm UTC](https://www.ruby-forum.com/t/complex-alternative-to-ajax-polling/185753/2 "2010-03-25T17:31:52Z")

</div>

> The problem with this seems to be that it won’t work with rails  
> because each http request is serial.

And it would tie up a Mongrel/Passenger child during the request…

> How can I do this or which rails books, blogs, or websites might have  
> examples ? Can webrick or event machine be usefull here ?

I’d definitely say go with Event Machine. I’m having great success  
using it  
for highly concurrent short lived requests (serving out of a cache and  
regenerated behind the scenes) - managing about 4,500 requests/second  
per  
process (and we run 1 process per CPU core and it scales fine!).

From my understanding of the architecture, it should also work for lots  
of  
open connections that aren’t doing anything (non-blocking select based  
sockets).

Good luck.

Cheers,

Andy
