Forking non web processes

Sam Saffron sam.saffron at gmail.com
Fri Oct 25 20:53:26 UTC 2013


Nice, will try this out, thank you

On Sat, Oct 26, 2013 at 7:44 AM, Eric Wong <normalperson at yhbt.net> wrote:
> Sam Saffron <sam.saffron at gmail.com> wrote:
>> The only reason for this level of crazy is to get the 30% memory
>> saving you do when forking off a master in Ruby 2.0s CoW friendly GC.
>> I understand this is less traditional, but perfectly acceptable for
>> low cost VPS hosting.
>>
>> The unicorn master does "reap/terminate" the child fork on startup, so
>> you are forced to hold off on forking.
>
> You can probably replace a worker process in the after_fork hook
>
> (totally untested)
>
> after_fork do |server, worker|
>   if worker.nr == 1
>     server.listeners = [] # drop listen sockets
>
>     # keep ticking
>     Thread.new { worker.tick = Time.now.to_i while sleep(server.timeout/2) }
>     begin
>       run_your_own_thing
>     ensure
>       exit
>     end
>   end
> end
>
> Or even just fork off via your Rack app.  This will be more portable in
> case you want to try a different server.  unicorn workers do nothing
> special with SIGCHLD, so your app can do whatever it wants with it.
> _______________________________________________
> Unicorn mailing list - mongrel-unicorn at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-unicorn
> Do not quote signatures (like this one) or top post when replying


More information about the mongrel-unicorn mailing list