From: Valentin Mihov <valentin.mihov@gmail.com>
To: Eric Wong <e@80x24.org>
Cc: "Bráulio Bhavamitra" <braulio@eita.org.br>,
unicorn-public <unicorn-public@bogomips.org>
Subject: Re: Master hooks needed
Date: Fri, 3 Oct 2014 15:36:28 +0300 [thread overview]
Message-ID: <CAC=mCcmx1yTiU0XRP+gDJ7qHECEK9GT7ZOK57bbDG3K-OX6H4Q@mail.gmail.com> (raw)
In-Reply-To: <20141003122222.GA11445@dcvr.yhbt.net>
On Fri, Oct 3, 2014 at 3:22 PM, Eric Wong <e@80x24.org> wrote:
>
> Bráulio Bhavamitra <braulio@eita.org.br> wrote:
> > Hello all,
> >
> > If I need to hook something after master load, I'm currently doing:
> >
> > before_fork do |server, worker|
> > # worker 0 is the first to init, so hold the master here
> > if worker.nr == 0
> > #warm up server...
> >
> > #kill old pid...
> > end
> >
> > # other stuff for each worker
> > end
> >
> > Both operations I currently do (server warm up and old pid kill) need
> > to be run only once, and not for every worker as before_fork does,
> > that's why I had to put the condition seen above.
>
> The above is fine if your first worker never dies. I think you can add
> a local variable to ensure it only runs the first time worker.nr == 0 is
> started, in case a worker dies. Something like:
>
> first = true
> before_fork do |server, worker|
> # worker 0 is the first to init, so hold the master here
> if worker.nr == 0 && first
> first = false
> #warm up server...
>
> #kill old pid...
> end
>
> # other stuff for each worker
> end
>
> For what it's worth, I'm not a fan of auto-killing the old PID in the
> unicorn config and regret having it in the example config. It's only
> for the most memory-constrained configs and fragile (because anything
> with pid files is always fragile).
>
> > So hooks for master is needed, something like
> > master_after_load(server) and master_init(server).
> >
> > What do you think?
>
> rack.git also has a Rack::Builder#warmup method. Aman originally
> proposed it for unicorn, but it's useful outside of unicorn so
> we moved it to Rack.
>
> In general, I'm against adding new hooks/options because they tend to
> make maintainability and documentation harder for ops folks.
> I still have nightmares of some Capistrano config filled with hooks
> from years ago :x
>
> Features like these also makes migrating away from unicorn harder, so
> that is another reason we ended up adding #warmup to Rack and not
> unicorn.
>
Isn't it much better to do the warmup in an initializer instead in
unicorn? This way you can preload_app=true and the master will execute
the warmup code and fork. Killing the old pid is probably stopping you
from do that, right?
--Valentin
next prev parent reply other threads:[~2014-10-03 12:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-03 11:34 Master hooks needed Bráulio Bhavamitra
2014-10-03 12:22 ` Eric Wong
2014-10-03 12:36 ` Valentin Mihov [this message]
2014-10-03 17:50 ` Eric Wong
2014-10-03 18:12 ` Valentin Mihov
2014-10-04 0:53 ` Bráulio Bhavamitra
2014-10-04 1:22 ` Eric Wong
2014-10-04 1:35 ` Bráulio Bhavamitra
2014-10-04 1:57 ` Eric Wong
2014-10-04 2:04 ` Bráulio Bhavamitra
2014-10-04 2:25 ` Eric Wong
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='CAC=mCcmx1yTiU0XRP+gDJ7qHECEK9GT7ZOK57bbDG3K-OX6H4Q@mail.gmail.com' \
--to=valentin.mihov@gmail.com \
--cc=braulio@eita.org.br \
--cc=e@80x24.org \
--cc=unicorn-public@bogomips.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).