[Backgroundrb-devel] Two backgroundrb questions

Ezra Zygmuntowicz ezmobius at gmail.com
Tue Jul 18 11:29:58 EDT 2006

On Jul 18, 2006, at 6:24 AM, Matt Mower wrote:

> Hi Ezra,
> I'm converting some code I have which basically ran Enumerable#map
> asynchronously using a thread-per-value to use backgroundrb
> (recommended by zedas). That code works but I have a scaling problem
> and needed to introduce throttling.
> However now that I've looked at it I don't see any sign of throttling
> in backgroundrb. It looks like there is a 1:1 relationship between
> workers and threads. Perhaps zed misunderstood what I was looking
> for...
> Also I don't see how:
>  MiddleMan.get_worker(session[:job_key]).progress
> or
>  MiddleMan.get_worker(session[:job_key]).results
> described in the documentation work. Where in the worker are you
> controlling the value of progress or results? Nothing in the
> definition of Backgroundrb::Rails seems to support this. Am I missing
> some magic?
> The only docs I seem to be able to find are:
>  http://backgroundrb.rubyforge.org/
> Sorry if I'm being dense and/or inobservant.
> Cheers,
> Matt

Hey Matt-

	Yeah you are right, there is a one worker per thread mapping in  
backgroundrb. So I am not clear exactly what you need to achieve with  
it. Can you give me a code sample or an outline of what you need to  

	As far as progress or results goes, you are left to take care of  
that yourself if you want to use progress bars. Here is an example  
worker that uses progress and result:

class Worker < BackgrounDRb::Rails

   attr_reader :result
   attr_reader :progress

   def do_work(args)
     @progress = 0
     @result = args[:text]
       while @progress < 100
         sleep rand / 2
         # do some work here and store it in @result
         @progress += 1

   def progress

The do_work() method is called within the thread for that worker so  
it can do its processing loop without blocking the call within rails.  
I'm not sure if it is the best match for trying to spawn hundreds of  
threads. But if you need to do something like that then it is  
possible. Maybe if you can explain what you want to accomplish I can  
help you find the right course of action. It could be that  
backgroundrb is not the solution you need and maybe you need to make  
a custom drb server that is lightweight and just handles your passed  


More information about the Backgroundrb-devel mailing list