[Backgroundrb-devel] Best way to organize workers

Ryan Leavengood leavengood at gmail.com
Mon Feb 4 16:54:03 EST 2008


On Feb 4, 2008 2:07 PM, Scott Ward <scott at shefield.com> wrote:
>
> Basically, I am wondering if I should combine a bunch of these periodic,
> non-overlapping tasks into one worker called "general_maintenance_worker" or
> something like that.  For each task, I could create a different method and
> schedule them as needed in backgroundrb.yml.
>
> That should work, but is it "right"?  What's the "best practice" is in this
> situation?

I am planning on doing the exact same thing for my periodic tasks. I
think it makes sense so let's make it into a BackgrounDRb best
practice :)

The thing to keep in mind is each worker gets a Ruby process, which
can consume 20-40 MB of memory. So if you can combine workers it will
definitely save resources. There really isn't a good reason I can
think of to have a bunch of workers sitting around just to be run one
or twice a day. So might as well put them all into one worker.
Especially if you can schedule tasks so they never overlap.

The way to keep this from getting too messy (as in a worker with tons
of unrelated code) is to extract the real work into separate ruby
modules which are required in the worker and then called from the
worker methods. Well that is how I have written things :)

Ryan


More information about the Backgroundrb-devel mailing list