Mongrel Performance Issue

I have Mongre’/Apache set up and serving up a ROR website which has some
images. I followed these instructions,

My problem is that it is so slow, it’s useless.

How can I begin to optimize? Anyone?


Get today’s hot entertainment gossip

Have you checked out the tuneup guide on the mongrel site?

Also, read:

and don’t worry about Zed calling you “a stupid moron,” he does that to
of us. Because he loves us.

Did you use the first proxypass instructions? If so, mongrel is serving
all your static content, and is not terribly great at that. Apache is.
Scroll down and use some rewrite rules to forward static requests to
the proxy or a mongrel_cluster of 1.

On 9/19/06, Jim W. [email protected] wrote:

Charles Brian Q.
highgroove studios:
slingshot hosting:

On Tue, 2006-09-19 at 16:02 -0400, Charles Brian Q. wrote:

Have you checked out the tuneup guide on the mongrel site?

Also, read:

and don’t worry about Zed calling you “a stupid moron,” he does that
to all of us. Because he loves us.

I call myself a stupid moron too, the problem is universal among
programmers for some reason. :slight_smile:

Did you use the first proxypass instructions? If so, mongrel is
serving up all your static content, and is not terribly great at that.
Apache is. Scroll down and use some rewrite rules to forward static
requests to either the proxy or a mongrel_cluster of 1.

Yes definitely look at how things are configured and make sure that
you’ve ruled out all the usual suspects like mongrel serving files and
too much stuff on one server.

Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu – Come get help.


In the first few lines I refer to ms01\ but I later decided to use
ms1\ but missed correcting the 1st 3 or so references.

The ms1\ could be any context string one likes we here actually use a
very formal
wssp01\ for deploying web services on Tomcat - it stands for web
service service point # 1
mssp01\ Mongrel Service Service PZoint #1



Zed, Anyone,

I have been playing with RoR & more recently Mongrel & have at last
almost got the set up I consider to be the smartest (I am sort of
emulating mod_jk which is fantastic for using a context in a url to
direct specific urls to any tomcat on any nearby computer). In effect
I can’t & don’t want to use Virtual Hosting plus I am condemmed to used
Win2003 for our corporate servers.

Mongrel has been fantastic for what I am doing. This is what I do to
redirect Apache (2.2.3) traffic coming in on port 80 to my mongrel app
on port 8087 …

  1. In the \config\routes.rb file I change
    map.connect ‘:controller/:action/:id’
    map.connect ‘ms01/:controller/:action/:id’

(this adds a context into the url but only for the dynamic content.
By this I mean that for all RoR generated urls for dynamic content, RoR
adds ms01/ and in Apache conf
all I add is …

ReWriteEngine on
ReWriteRule ^/ms1/(.*) http://localhost:8087/ms1/$1 [P]

(for me ms1 = Mongrel service one)

Now without the uneeded gumph of Virtual hosts I can tell my Apache to
to any Mongrel server I want, on any port, and or any other server & we
do plan to have different apps on different servers as well as some on
the same server as Apache.

BUT, in RoR the static urls don’t get the ms1/ added - RoR when looking
for \public (for images, stylesheets and javascripts), goes to the
Apache server’s default homedir I there is no rewrite rule I can think
of that can identify the static url of one particular app vs any other

The problem I have is that doing what I am doing means that all static
content such as images/stylesheets and javascripts for all apps must be
placed on the one server in one folder while I can put the dynamic
content anywhere.

Ideally RoR would give me an option to add the ms1\ string onto the
front of my static content urls just as it now adds ms1\ onto the front
of my dynamic urls. If I could add a context string (even better if for
example I could make it different to the dynamic content url (i.e. for
dynamic add ms1d\ and on the static content add ms1s\ then I could
direct Apache to where ever I like for either type of content - even
both contexts to the same server if I wanted - all the control is in
the Apache conf file.

If anyone can suggest a way or a ReWriteRule or a Condition that would
allow me to identify incoming urls to Apache, both static content and
dynamic content, and to identify which these urls belong to, I
will have a very flexible way of implementing multiple apps on multiple
servers. With Java/Apache & Tomcat, I have this today with mod_jk. I
feel I am so close to getting this same flexibility in RoR.


Doug M
(IT Tech Architect & one big Rails & Mongrel fan)


Many thanks - this does handle reverse proxying. It also appears to
the urls. What is not clear to me is if it addresses the issue that
RoR adds
prefixes onto dynamic content but not static content (public: images,
and javascripts).

If I had an add-in that allowed me to nominate a url context (such as
that was to go on the front of the static content (the stuff we
normally have to
put in /public/ ) I know this would mean I then have to create a
folder ms1/ in
/public/ and move the static content for this app from /public/ to
for testing and production.

You fix is great for production but it appears designed to cater for
the base
machine url. What I need is the ability to redirect urls based on the
they are aimed at (using a context such as /ms1 in the url). I can make this work in
routes.rb - RoR does not apply the
change to this url & it cannot be intercepted on apache.



My plugin does handle that. It modifies the URLs for requests and also
deals with the static files by modifying the value of asset_host. The
it was written was so that I could run Mongrel on Windows behind IIS
has little to offer in the way of a decent reverse proxy.

I wrote a plugin for Rails apps that might do exactly what you need.
designed to handle this sort of problem. You leave your routes alone
(standard routes) and apply the prefix in the configuration file for the

It’s meant to handle dumb reverse proxies, so it expects the full
URL. ( but it works like a charm, rewriting all

The nice thing is that it only applies this fix in production mode so
can continue to develop your app locally without having to enable /
the plugin.

Let me know if this works for you.


Many thanks for your input

I will read up that info.

Also just on the offchance - did you use to work in IBM’s Smalltalk
There was a Brian H. there that I had dealings with when IBM
VisualAge Smalltalk, as soon as I saw your name & an association with
Ruby I wondered


Doug M


I read the doc 'Serving Multiple Rails Apps on Windows with Apache &
Mongrel & that is indeed enough to meet what I want.

I think that since you wrote that there is now a good mod_proxy module
for Apache so your input has given me some ideas to try first but
without doubt your mod will do it.

Many thanks

Doug Marker

Just for clarification:

Yes it is catered towards using the machine’s base URL… but in theory
should work if you just used /ms1 as the base_url instead of a full

It simply prepends urls with whatever is in the base path. In theory
place this on a linux box with several instances on
and set the base_url to and set appropriate
proxying. All requests created by Rails would be rewritten to use the
frontend address.

Of course, this only works if you have used the Rails helpers to
your links.

I contributed some stuff to the upcoming Rails Deployment book about
types of setups… but I have some older articles that might help you

See the one titled ‘Serving Multiple Rails Applications on Windows with
Apache and Mongrel’. I do it without using VHOSTS. Some of the steps are
little out of date because Mongrel has changed a bit, but I’m not
anything because of the book.


Glad I was able to point you in the right direction.

I have never worked at IBM :slight_smile:


One other question I have is it would be fantastic to be able to use a
mod like you have created (more I look at it the better it looks :slight_smile: )
to be able to optionally set a different url prefix for static content.
This increases the flexibility markedly.

Mongrel isn’t so good at handling large volumes of static images & no
one really wants to create say 6 apps on different Mongrel instances
(perhaps on different servers) but have to put the static input for all
these apps in one common directory because of the urls RoR generates
for static input have no identifying contexts to use in proxy
redirection & I gather that you mod uses the same url for both static
and dynamic content. Mongrel doesn’t have (IIRC) the ability to
further redirect requests for static content (such as images) to
another server (even if it could it becomes messy)


Doug M

Charles Brian Q. wrote:

and don’t worry about Zed calling you “a stupid moron,” he does that to
all of us. Because he loves us.

There’s a remedy:

Joe R.
MUDCRAP-CE Grasshopper
Smart Moron


Having reread all the info in your posts & done some delving into
‘asset_host’ I have succeeded in achiving all the goals I set out to.

I have multiple apps. Apache as the front-end, have activated
Mod_rewrite & Mod_proxy etc:

Each apps urls are split into dynamic content and static content. and
each has its own
url prefix
For app1 dyna content = http://myapachesvr/ms1d/store
For app1 static content =

Apache sees the ms1? context & using rewrite & proxying rules directs
each type of content for this app, to the appropriate location.

This is simple & works well. I can place the static content on apache
in sep folder for each app and let mongrel instances serve the dynamic

Performance seems fine.


Doug M

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs