From: Eric Wong <e@80x24.org>
To: "Bráulio Bhavamitra" <braulio@eita.org.br>
Cc: unicorn-public <unicorn-public@bogomips.org>
Subject: Re: Master hooks needed
Date: Fri, 3 Oct 2014 12:22:22 +0000 [thread overview]
Message-ID: <20141003122222.GA11445@dcvr.yhbt.net> (raw)
In-Reply-To: <CAJri6_tdtd5tfPcrTcTBbmQKrmRYnnGJERFwSo1T6PTDsoOO_A@mail.gmail.com>
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.
next prev parent reply other threads:[~2014-10-03 12:22 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 [this message]
2014-10-03 12:36 ` Valentin Mihov
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=20141003122222.GA11445@dcvr.yhbt.net \
--to=e@80x24.org \
--cc=braulio@eita.org.br \
--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).