[Rails] Forking FCGI dispatcher
Ara.T.Howard
Ara.T.Howard at noaa.gov
Thu Mar 10 16:55:10 GMT 2005
On Thu, 10 Mar 2005, Andreas Schwarz wrote:
> I hacked a forking FCGI dispatcher for Rails. I have no idea if this is the
> correct way to do it, but it seems to work fine. It improves memory usage a
> bit; after it is started the processes share almost 10 MB (of 12 MB total),
> but unfortunately it drops to 2 MB after a few requests.
>
> =====================================
> #!/usr/local/bin/ruby
>
> require File.dirname(__FILE__) + "/../config/environment"
> require 'dispatcher'
> require 'fcgi'
>
> parent = true
> num = 0
> max = 3
> while parent && num < max
> pid = fork()
> if pid == nil
> # child
> parent = false
> else
> # parent
> num += 1
> end
> end
>
> if parent
> Process.wait
> else
> FCGI.each_cgi { |cgi| Dispatcher.dispatch(cgi) }
> end
> =====================================
why are you doing this? not using apache? this is essentially what the
fastcgi process manager in apache already does and the number of processes is
configurable in httpd.conf unless, of course, you aren't using apache...
also - it doesn't seem like this would work: you will carry your ipc channels
going between web server and original fcgi process from parent to child and
then all children will share the same pipes back to web server. but maybe i
am missing something here since you are saying it works... something tells me
that multiple requests will make this fail... what happens when web server
attempts requests number 4 and you are waiting for 3 processes which never
exit? again, i might not be wrapping my mind around this but it seems
not quite right... interesting though ;-)
cheers.
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
More information about the Rails
mailing list