[Backgroundrb-devel] MiddleMan.worker blocks?

Marc Evans Marc at SoftwareHackery.Com
Wed Mar 7 14:42:50 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.

You may be seen my follow up post, where I indicated that I put the 
comment aboev the wrong line of code. The line that is blocking is the 
line for MiddleMan.worker.

> When you say it is blocking -- how do you know? What is the symptom? Is is
> just slow?

The symptom is that when I try to obtain the worker in order to then 
obtain the progress value, the call to MiddleMan.worker blocks until the 
worker has completed its work.

> 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?

In the example code I sent, I replaced one line in do_work as shown here:

#    (dtd_only.nil? or !dtd_only) ? data(xml,constraints) : dtd(xml)
while (i < 100)
   i += 10
   sleep 10
   @progress = i

By doing so, I no longer experiencing the blocking behavior. The clearly 
tells me that something in the data method is the direct/indirect cause.

> 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

Thanks for your followup message.

- Marc

More information about the Backgroundrb-devel mailing list