'before_fork' is executed in parallel by two processes ¿?

Eric Wong normalperson at yhbt.net
Tue Jan 5 16:51:04 EST 2010


Iñaki Baz Castillo <ibc at aliax.net> wrote:
> El Martes, 5 de Enero de 2010, Iñaki Baz Castillo escribió:
> >   before_fork do |server, worker|
> >     `echo "before_fork $$" >> /tmp/kk`
> >   end
> 
> 
> > And this is the file output:
> > 
> >   before_fork 3447
> >   after_fork  3456
> >   before_fork 3454
> >   before_fork 3463
> >   after_fork  3464
> >   after_fork  3472
> 
> 
> Hummm, this could be something strange related to how `` works...
> 
> If I do the following:
> 
>   before_fork do |server, worker|
>     `echo "before_fork $$" >> /tmp/kk`
>      File.open("/tmp/kk", "a") do |f|
>        f.puts "$$=#{$$}"
>      end
>   end

Odd, I'm confused by the way `` is working there too...  I wonder if
this is a Ruby bug...  Anyhow, in your use case system() or your
File.open block should be the way to go.  Don't use `` when system()
will do.

> then I get:
> 
>   before_fork 11989
>   $$=11977
>   before_fork 11994
>   $$=11977
>   before_fork 12000
>   $$=11977
> 
> So I'm totally lost. However if I test my databases in "before_fork" then I 
> see N number of DB connections (N = workers num).

How are you testing the database?  `` or via Ruby code?

-- 
Eric Wong


More information about the mongrel-unicorn mailing list