[Backgroundrb-devel] MiddleMan.worker blocks?

Marc Evans Marc at SoftwareHackery.Com
Wed Mar 7 14:55:20 EST 2007

On Wed, 7 Mar 2007, Mason Hale wrote:

>      # For reasons unknown, the following seems to block!
>      session[:xml_report_job] =
>        MiddleMan.new_worker(:class => :xml_report_worker, :args => args)
> The above looks right to me. It should not matter at all what is in the
> worker class.
> When you say it is blocking -- how do you know? What is the symptom? Is is
> just slow?
> If you create a test worker that loops indefinitely (or for a sufficiently
> long time, "sleep 120" should do) -- does it that block when you create a
> new instance with MiddleMan.new_worker?
> If it is just slow to return, I find there is some lag when spawning a new
> process, which can make the MiddleMan.new_worker call sluggish to return.
> But in my experience it does not block until the worker is done. It *does*
> block until the process is created.
> A way to speed up the new_worker calls is to set an explicit job_key to call
> the do_work method on a long running process, rather than starting a new
> process.
> Mason

I am discovering more information on this, but don't understand the 
underlying cause still. Below is my data method and a method it calls 
within scope od do_work:

   def data(xml,constraints)
     @progress = 10
     xml.telemetry do
       @progress = 30
       @progress = 50
       @progress = 70
       @progress = 90

   def telem_to_xml(klass,xml_method,constraints,xml)
     opts = constraints.dup
     opts[:limit] = 5000
     offset = 0
     while true do
       opts[:offset] = offset
       offset += opts[:limit]
       found = klass.find_restricted(:all,opts)
       break if (found.nil? or found.size < 1)
       found.each { |dct| self.method(xml_method).call(dct,xml) ; sleep 0.001 }

Notice in the above the "sleep 0.001". Without that sleep, I get the 
blocking behavior I described in the original post. With it, I get the 
behavior I would expect, which is that I can retrieve the progress 
reasonably quickly and repeatedly.

Again, any suggestions?

- Marc

More information about the Backgroundrb-devel mailing list