One Rails app, One machine, One IP address, Multiple virtual

Hi,

I deployed my app on a dedicated production machine which runs GNU/
Linux Debian Sarge, Ruby 1.8.5, Rails 1.1.6, and it’s served with
LightTPD 1.4.11 and FastCGI.

The machine is a VMWare virtual machine with 512 MB RAM allocated. The
host machine is a Dell PowerEdge 1650 with 2 x Intel Pentium III 1.4
Ghz. But because of VMWare license, only one CPU is enabled.

I only have one address IP for this machine, and hundreds of domain
names pointing to my Rails app. All requests are handled by this
FastCGI configuration:

fastcgi.server = ( “.fcgi” =>
( “localhost” =>
( “min-procs” => 2,
“max-procs” => 2,
“socket” => “/tmp/” + var.app + “.fcgi.socket”,
“bin-path” => server.document-root + “/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)
)
)

Here are my questions:

  1. When I use script/process/reaper I get:

Restarting [30315] /usr/local/bin/ruby /var/web/vero/current/public/
dispatch.fcgi
Restarting [30317] /usr/local/bin/ruby /var/web/vero/current/public/
dispatch.fcgi
Restarting [29089] /usr/local/bin/ruby /var/web/vero/current/public/
dispatch.fcgi
Restarting [29090] /usr/local/bin/ruby /var/web/vero/current/public/
dispatch.fcgi

Why do I see 4 processes restarting when I asked for 2 processes in
the FastCGI configuration?

  1. I want to use page caching. But as my application receives requests
    from many domain names, and content vary with each domain name, I need
    a different cache for each domain name. How can I do that, as the page
    caching is dependent on the document-root, which is fixed?

  2. Is there a more efficient solution in my case, using maybe nginx,
    apache or else? Not forgetting I don’t have much RAM…

Thank you very much for you help!

Hi,

fastcgi.server = ( “.fcgi” =>
( “localhost” =>
( “min-procs” => 2,
“max-procs” => 2,
“socket” => “/tmp/” + var.app + “.fcgi.socket”,
“bin-path” => server.document-root + “/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)
)
)

Your configuration has lighty start the two processes on launch. It’s
not using any fastcgi process you launch with spinner/spawner. Lighty
spawns then as needed, in your case it always spawns 2 processes, and
never more than those two.

Why do I see 4 processes restarting when I asked for 2 processes in
the FastCGI configuration?

Because you have 2 you probably launched with the spawner, and 2
lighty launched itself.

  1. I want to use page caching. But as my application receives requests
    from many domain names, and content vary with each domain name, I need
    a different cache for each domain name. How can I do that, as the page
    caching is dependent on the document-root, which is fixed?

You could do it by using some rewrite rules in lighty that would use
the lighty host variable to find the correct files. Under your main
root, create a new directory per-site, and using lighty rewrites make
it look for the cache there.

If that’s too complicated for your needs, try fragment caching as
another option. Fragment caching takes the host name into
consideration by default, so it should work for you out of the box.

  1. Is there a more efficient solution in my case, using maybe nginx,
    apache or else? Not forgetting I don’t have much RAM…

I don’t think lighty is the problem here. You will have to do similar
configuration rewrites with other servers as well. Though it might be
easier with other servers.

Bye,

Guy.

  1. Is there a more efficient solution in my case, using maybe nginx,
    apache or else? Not forgetting I don’t have much RAM…

I don’t think lighty is the problem here. You will have to do similar
configuration rewrites with other servers as well. Though it might be
easier with other servers.

Lighty is not a problem, fcgi is. Are there any reasons, why you can’t
use mongrel + lighty / nginx ? By the looks of it, currently 2 fcgi
processes serving your application should indicate, that you would be
well off with a single mongrel instance serving dynamic content and
nginx or lighty doing the static files.

For me fcgi was a nightmare solution back in the day. Dying, zombie,
stalled processes, croning their reaping and spawning, etc. Then came
mongrel and saved the day. You should really-really try it and combine
with nginx (if you so much care about the lowest memory footprint) or
lighty, you’ll be delighted.

A good starter read for you:
http://brainspl.at/articles/2006/08/23/nginx-my-new-favorite-front-end-for-mongrel-cluster

Let me know, how it was working for you.

Regards,
András