# Difference between Background DRb and AJAX

**URL:** <https://www.ruby-forum.com/t/difference-between-background-drb-and-ajax/91095>\
**Category:** Rails\
**Created:** [April 4, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/difference-between-background-drb-and-ajax/91095 "2007-04-04T17:29:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [April 4, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/difference-between-background-drb-and-ajax/91095/1 "2007-04-04T17:29:31Z")

</div>

Hi,

I need a user to initiate a long running task … say five minutes. And  
I want the user to wait for a response before doing anything else.

The way I see it, using a straight HTTP POST is gonna time out.

So, I could start up a new thread using Backgroundrb (after an AJAX form  
post), and use AJAX to ping the server every second to look at the  
progress.

Or, I could just use an AJAX form post, and using AJAX poll the server  
every second to see what’s up.

The way I see it, an AJAX call doesn’t time out the same way a normal  
HTTP call could times out on the browser.

Therefore … is there any need to complicate things by using  
backgroundrb in this scenario?

Or am I missing some major advantage using backgroundrb, or some major  
disadvantage using a regular AJAX call?

Thanks  
Joerg

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [April 4, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/difference-between-background-drb-and-ajax/91095/2 "2007-04-04T17:41:26Z")

</div>

On 04 Apr 2007, at 17:29, Joerg D. wrote:

> Therefore … is there any need to complicate things by using  
> backgroundrb in this scenario?
> 
> Or am I missing some major advantage using backgroundrb, or some major  
> disadvantage using a regular AJAX call?

Backgroundrb will release the thread, while a normal AJAX request  
where you wait for a response will block one of your server  
connections. This will be the best way to go btw, as your subsequent  
AJAX calls will only take a few fractions of a second to query the  
Backgroundrb process, then release the thread for other users.

To illustrate: suppose you’re running a mongrel cluster of 5 mongrels  
and you have 5 people making such a long running task at the same  
time, all mongrels will be in use and no one will be able to connect  
to your site anymore if you use a normal AJAX request which waits for  
a server response.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [April 4, 2007, 6:21pm UTC](https://www.ruby-forum.com/t/difference-between-background-drb-and-ajax/91095/3 "2007-04-04T18:21:51Z")

</div>

Ah right. Yes - now I see the advantage of using backgroundrb …  
Thanks!

Peter De Berdt wrote:

> To illustrate: suppose you’re running a mongrel cluster of 5 mongrels  
> and you have 5 people making such a long running task at the same  
> time, all mongrels will be in use and no one will be able to connect  
> to your site anymore if you use a normal AJAX request which waits for  
> a server response.
