Threads in Rails

T

Tony Targonski

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
 
B

Brian McCallister

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
 
L

leon breedt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top