[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Threads in Rails

Tony Targonski

4/12/2005 6:37:00 PM

In my Rails application, I have a function perform some background
calculations inside of a thread.

The problem is that the said thread gets no computation time unless
something else runs in parallel. If the user continuously refreshes a
page (any controller page), the function zooms through the tasks. But if
one was to just initiate the script and leave for a coffee break --
nothing gets done.

Threads are attention whores, how do I fix or work around that?

Thank you,
--Tony



2 Answers

Brian McCallister

4/13/2005 12:34:00 PM

0

Even under FastCGI or mod_ruby, I wouldn't rely on the lifetime (or
cycle) of a given VM for processing anything in the background. A
better approach may be to spawn a dedicated (or several) worker VM's
and send the request for the background job via DRb or some other
communication medium (we need a good message broker for ruby =/)

-Brian

On Apr 12, 2005, at 2:37 PM, Tony Targonski wrote:

> In my Rails application, I have a function perform some background
> calculations inside of a thread.
>
> The problem is that the said thread gets no computation time unless
> something else runs in parallel. If the user continuously refreshes a
> page (any controller page), the function zooms through the tasks. But
> if
> one was to just initiate the script and leave for a coffee break --
> nothing gets done.
>
> Threads are attention whores, how do I fix or work around that?
>
> Thank you,
> --Tony
>
>



leon breedt

4/13/2005 10:46:00 PM

0

On 4/13/05, Tony Targonski <Tony.Targonski@quest.com> wrote:
> In my Rails application, I have a function perform some background
> calculations inside of a thread.
>
> The problem is that the said thread gets no computation time unless
> something else runs in parallel. If the user continuously refreshes a
> page (any controller page), the function zooms through the tasks. But if
> one was to just initiate the script and leave for a coffee break --
> nothing gets done.
>
> Threads are attention whores, how do I fix or work around that?
I had a need for something similar (a long-running operation calling
out to blocking OS calls). My solution was to move that out into a
seperate process and use DRb to communicate the request and query for
the result. At least that way, if the FastCGI dispatcher goes down for
some reason, the operation is still guaranteed to complete
deterministically.

Supporting this kind of thing in Rails proper would start moving it
towards Application Server territory :)

Leon