unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Suraj Kurapati <sunaku@gmail.com>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: feature request - when_ready() hook
Date: Wed, 25 Nov 2009 20:50:56 -0800	[thread overview]
Message-ID: <cfbcd2f00911252050y3f43f950y77123253e1284d90@mail.gmail.com> (raw)

Hello,

I've been trying to achieve truly transparent zero downtime deploys
with Unicorn and Rails for some time now (using SIGUSR2 and SIGQUIT
strategy) and I've always hit the problem of my "last worker sends
SIGQUIT to the old master" logic being executed way too soon.

In particular, I tried killing the old master in:

* before_fork() -- approx. 2 minute downtime
* after_fork() -- approx. 2 minute downtime
* storing the old-master-killing logic inside a lambda in after_fork()
(for the last worker only) and later executing that lambda in Rails'
config.after_initialize() hook -- approx. 20 second downtime

As you can see, the more I delayed the execution of that "killing the
old master" logic, the closer I got to zero downtime deploys.  In this
manner, I request the addition of a when_ready() hook which is
executed just after Unicorn prints "worker=# ready!" to its error log
inside Unicorn::HttpServer#worker_loop().

I am happy to implement this (with tests) and submit a patch, but I
first wanted to know your opinion on this approach.  (I should note
that my unicorn setup does not run very close to the memory limit of
its host; instead, the amount of free memory is more than double of
the current unicorn memory footprint, so I can safely spawn a second
set of Unicorn master + workers (via SIGUSR2) without worrying about
the SIGTTOU before_fork() strategy shown in the Unicorn configuration
example.)

Thanks for your consideration.

             reply	other threads:[~2009-11-26  4:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-26  4:50 Suraj Kurapati [this message]
2009-11-26  6:05 ` feature request - when_ready() hook Eric Wong
2009-11-26 19:05   ` Suraj Kurapati
2009-11-26 19:53     ` Eric Wong
2009-11-30 23:47       ` Suraj Kurapati
2010-03-08 22:58         ` Suraj Kurapati

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cfbcd2f00911252050y3f43f950y77123253e1284d90@mail.gmail.com \
    --to=sunaku@gmail.com \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).