Forum: Ruby on Rails Difference between Background DRb and AJAX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2007-04-04 17:29
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
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2007-04-04 17:41
(Received via mailing list)
On 04 Apr 2007, at 17:29, Joerg Diekmann 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
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2007-04-04 18:21
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.
This topic is locked and can not be replied to.