Apache 2.x: Use fcgid or Mongrel?

Hi, There’s lots of stuff going on currently with choices of production
deployment environments. But I’m not clear on a few things as I need to
decide on a production setup where Apache is a given.

A recent thread (FastCGI vs. Simple CGI - Rails - Ruby-Forum) seemed to favor
Apache 2 with mod_fcgid. And this is supported in articles such as:
http://paul.querna.org/journal/articles/2006/01/01/using-mod_fcgid-for-ruby-on-rails-applications

And then there’s all the excitement about Mongrel.

Question 1. What are the advantages of mongrel over fastcgi?
http://mongrel.rubyforge.org/ is not at all clear on this.
Hint to Zed: How about a “Why use Mongrel” section on the site.

Question 2. Has anybody used Apache 2 with Mongrel? Is this a good idea?
Any configuration examples available?

By the way, I’m not talking about a high-volume site. But as this is on
a shared server with other (php) applications, efficiency is an issue.

Thanks,
Mike.

Greg,

I haven’t done this myself so I might be wrong here, but have you tried
setting
ActionController::AbstractRequest.relative_url_root = “/dir”
in your production.rb? It might make things a bit simpler than
redefining url_for.

Anyway, feel free to ignore me :slight_smile:

Dan

On Mon, Mar 06, 2006 at 12:29:12PM +0100, Mike D wrote:
} Hi, There’s lots of stuff going on currently with choices of
production
} deployment environments. But I’m not clear on a few things as I need
to
} decide on a production setup where Apache is a given.
}
} A recent thread (FastCGI vs. Simple CGI - Rails - Ruby-Forum) seemed to
favor
} Apache 2 with mod_fcgid. And this is supported in articles such as:
}
http://paul.querna.org/journal/articles/2006/01/01/using-mod_fcgid-for-ruby-on-rails-applications

I have had great success with Apache2+fcgid, but then I am not dealing
with
a production deployment. When I say success, I mean I was able to put up
a
Rails app at a non-root path on my existing Apache2 server.

} And then there’s all the excitement about Mongrel.
}
} Question 1. What are the advantages of mongrel over fastcgi?
} http://mongrel.rubyforge.org/ is not at all clear on this.
} Hint to Zed: How about a “Why use Mongrel” section on the site.

The primary advantage, if any, would be performance. The only way to
tell
if this actually is an advantage is to run tests. You would want to run
load tests on a staging environment before releasing to production
anyway.
If I remember correctly (and there is a strong chance I do not) there is
something called Watir which is a Ruby web load testing system.

} Question 2. Has anybody used Apache 2 with Mongrel? Is this a good
idea?
} Any configuration examples available?

I believe you would set up mongrel to run on a nonstandard port (e.g.
3000)
and configure Apache2 to proxy to it. Unsurprisingly you will need
mod_proxy loaded. The following should work, substituting as
appropriate:

ProxyPass /foo/bar http://localhost:3000/
ProxyPassReverse /foo/bar http://localhost:3000/

You will also need to tell Rails to prepend /foo/bar (substitute your
path) to
its links. There may be a better way to do this, but the only way I’ve
come up
with is to put the following in your app/controllers/application.rb:

def url_for(options = {}, *parameters_for_method_reference)
normal_url = super(options, *parameters_for_method_reference)
/^http/ =~ normal_url ? normal_url : ‘/foo/bar’+normal_url
end

Note that it is probably better to put the prepend path string in
config/environments/production.rb rather than directly in
application.rb. There
may be a more elegant solution, but I haven’t come up with it.

} By the way, I’m not talking about a high-volume site. But as this is
on
} a shared server with other (php) applications, efficiency is an
issue.

Since you are more concerned with resource contention than performance,
I
suggest that you monitor disk and memory usage during your load tests
rather than simply reading the numbers from your load testing software.

} Thanks,
} Mike.
–Greg

On Tue, Mar 07, 2006 at 09:57:04AM +1000, Dan S. wrote:
} I haven’t done this myself so I might be wrong here, but have you
tried
} setting ActionController::AbstractRequest.relative_url_root = “/dir”
in
} your production.rb? It might make things a bit simpler than redefining
} url_for.
}
} Anyway, feel free to ignore me :slight_smile:

So there’s bad trolling and there’s good trolling. What I was doing
there
was good trolling. I was presenting a working, if inelegant, solution to
a
poster’s problem in the hopes that I would be corrected by someone who
knew
The Right Way to do it. Now I know, and Knowing Is Half The Battle!

} Dan
–Greg

Haha, just noticed Nicholas S. answered this the same way in the
other thread :slight_smile: