[Backgroundrb-devel] Creating workers from workers?

Brett Walker lapomme00 at gmail.com
Mon Aug 7 03:57:57 EDT 2006


On 8/6/06, Ezra Zygmuntowicz <ezmobius at gmail.com> wrote:
>
> On Aug 5, 2006, at 10:35 AM, Brett Walker wrote:
>
> >> On Jul 31, 2006, at 8:05 PM, Ben Johnson wrote:
> >>
> >>> Since MiddleMan is an uninitialized constant in a worker how do you
> >>> create new workers inside a worker?
> >>>
> >>> Thank You,
> >>> Ben Johnson
> >>> E: bjohnson at contuitive.com
> >>> O: 800-341-6826
> >>> M: 817-229-4258
> >>
> >>
> >> Ben-
> >>
> >>      You would have to use the full module path to the MiddleMan class.
> >> Like this:
> >>
> >> ::BackgrounDRb::MiddleMan.new_worker ....
> >>
> >>
> >> -Ezra
> >
> > I need to start a couple workers from one main worker, and I've been
> > trying to get the above to work, to no avail.  What exactly do I need
> > to put in my worker file?
> >
> > I had one other quick question:  I see mention of @job_ctrl in the
> > code, but I can't find where it's used.  Is it no longer needed?
> >
> > Thanks Ezra for a great plugin and all the hard work you do on it.
> >
> > Cheers,
> > Brett
>
>
> Hey Brett-
>
>         Yeah now that I think about it spawning new worker from within a
> worker won't work like that. The reason being is that when the drb
> server gets started up it gets a new instance of the MiddleMan class.
> Like this:
>
>
> DRb.start_service("druby://#{CONFIG['host']}:#{CONFIG['port']}",
> BackgrounDRb::MiddleMan.new(CONFIG['timer_sleep'] || 60))
>
>
>         This means that in order to reference the new_worker method *in the
> instance that is running in the drb server* you can't do that
> directly. In order to spawn other workers from within a worker I
> would have to change the MiddleMan class to be a singleton. This way
> you could grab the one instance of it and call new_worker on that and
> it would work as expected. But the way it is currently setup, you
> don't have a reference to the Main MiddleMan instance from within
> your workers.
>
>         I don't think making the MiddleMan class be a singleton would affect
> any current code but I will have to test this. If it doesn
> 't interfere then I think it makes sense to turn the MiddleMan into a
> singleton. that way you cold gain access to it from within worker
> classes.
>
>         And yeah @job_ctr is a leftover. Thanks for spotting that, I will
> remove it as it currently doesn't do anything.
>
>
> Cheers-
> -Ezra
>
>

I would love to see the singelton ability make it in.  I prefer not to
have to start workers from workers (just an extra complication), but I
need to be able to do some ongoing performance measurements, and this
would allow me to deal with it in one place.

Cheers,
Brett


More information about the Backgroundrb-devel mailing list