From: "Bráulio Bhavamitra" <braulio@eita.org.br>
To: Eric Wong <e@80x24.org>
Cc: unicorn-public <unicorn-public@bogomips.org>
Subject: Re: Master hooks needed
Date: Fri, 3 Oct 2014 21:53:06 -0300 [thread overview]
Message-ID: <CAJri6_s61q4-yMTp8Ev8HizDBnjGXqusmkrJODYX64TtFd+8ZA@mail.gmail.com> (raw)
In-Reply-To: <20141003122222.GA11445@dcvr.yhbt.net>
The problem is actually worser, and the worker.nr == 0 can't be used.
I had to do something like this:
master_run = true
before_fork do |server, worker|
if master_run
#warm up server...
#kill old pid...
#disconnect active record
master_run = false
end
# other stuff for each worker
end
In the last example, using worker.nr == 0 would make the server crash
in case the worker 0 was killed/restarted.
Also the AR's disconnect and *many other stuff* people put on
before_fork should only be run once the master was preloaded, not for
every worker.
So I still think at least a hook like master_preloaded(server) is necessary.
cheers,
bráulio
On Fri, Oct 3, 2014 at 9:22 AM, 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.
next prev parent reply other threads:[~2014-10-04 0:53 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
2014-10-03 17:50 ` Eric Wong
2014-10-03 18:12 ` Valentin Mihov
2014-10-04 0:53 ` Bráulio Bhavamitra [this message]
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=CAJri6_s61q4-yMTp8Ev8HizDBnjGXqusmkrJODYX64TtFd+8ZA@mail.gmail.com \
--to=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).