Backgroundrb vs Forking/Threading

I know very little about forking the ruby process but am running into
a problem where I need to move some processing to a background task.
What's the main differences (pros/cons) between using Backgroundrb or
a Forking plugin like Spawn (http://rubyforge.org/projects/spawn/)?

The problem I'm trying to solve is that at the end of an event
creation flow we need to send out an email to all the users who were
invited. This list can be long for large events, so it tends to take
some time.

Also, it might be important to know that my server has limited RAM
(512MB) and is running a Mongrel cluster behind Apache.

Thanks,
Jeremy Gillick
http://mixermixer.com

Oh, and to add to that, what about AP4R (http://ap4r.rubyforge.org/
wiki/wiki.pl?HomePage)?

The problem I'm trying to solve is that at the end of an event
creation flow we need to send out an email to all the users who were
invited. Â This list can be long for large events, so it tends to take
some time.

The options I've heard of are:

starfish
backgroundrb
ap4r
system scheduler jobs

Also, it might be important to know that my server has limited RAM
(512MB) and is running a Mongrel cluster behind Apache.

If you find your box paging in and out a lot, you might wanna try
fronting with nginx instead. Its memory footprint isn't much different
from that of the grep process I used to find it. :slight_smile:

Ciao,
Sheldon.

I'm currently using Backgroundrb, although at Railsconf last week,
Ezra says he recommended using BJ (BackgroundJob) instead. I didn't
attend the session on asynchronous processing, just heard it mentioned
by some other people, so I don't know any more details besides that.

starfish
backgroundrb
ap4r
system scheduler jobs
BackgroundJob

Wow, I have more things to look into now. :slight_smile:

...you might wanna try fronting with nginx instead...

Good idea, I think I will try this.

But overall, I'm wondering what the big difference between using a
program like BackgroundRb or BackgroundJob vs. just using a plugin
like Spawn to fork the process inline. Is there an advantage to
installing another server to run the background jobs? Are there
downsides to forking the process inline?

My site already has a community so I don't have much room for
experimentation since I want to keep them happy. :slight_smile: I would like
learn from other people's experiences and use those to build on my
own.

Thanks,
Jeremy

You should never fork processes inline in Ruby. Thats asking for trouble.

But overall, I'm wondering what the big difference between using a
program like BackgroundRb or BackgroundJob vs. just using a plugin
like Spawn to fork the process inline. Â Is there an advantage to
installing another server to run the background jobs?

Yes. Once it's started up, it's fast. More importantly, because it'ss
a service, it can be interrogated as to its state.

Are there
downsides to forking the process inline?

Yes. You'll be forking a 50MB minimum process image, for a start. It's
also not a great idea from within a Rails request handler for numerous
reasons relating to resource contention, and is certainly not
supported.

Ciao,
Sheldon.

Yes. You'll be forking a 50MB minimum process image, for a start. It's
also not a great idea from within a Rails request handler for numerous
reasons relating to resource contention, and is certainly not
supported.

That is precisely what I wanted to know, thanks.

With that in mind, how do the various background servers stack up
against each other? How should I choose one?

Thanks,
Jeremy

From the limited documentation I find for BackgroundJob and Ap4r, it
seems they are not tied with the Rails backend and might not have
access to the models. Is this true?

For my application I would like to pass model objects to the
background runner. Is this possible?

Thanks,
Jeremy

Hmmm, not sure where you got that idea? Take a look here:

http://backgroundrb.rubyforge.org/

Looks like backgroundrb and Rails getting pretty intimate. :slight_smile:

Ciao,
Sheldon.

Mozmonkey wrote:

From the limited documentation I find for BackgroundJob and Ap4r, it
seems they are not tied with the Rails backend and might not have
access to the models. Is this true?

For my application I would like to pass model objects to the
background runner. Is this possible?

Thanks,
Jeremy

In any ruby script all you need to do is require your
config/environment.rb, and you'll be running your rails app.
BackgrounDRb running as a plugin for rails will deal with this for you
automatically.