* [PATCH] configurator: update some migration examples
@ 2009-10-02 8:11 7% Eric Wong
0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2009-10-02 8:11 UTC (permalink / raw)
To: mongrel-unicorn
We now give an example of how a before_fork hook can be used
to incrementally migrate off the old code base without hitting
a thundering herd (especially in the "preload_app false") case.
Also comment on the per-worker listen usage in the RDoc, not
just a hidden comment.
---
I just pushed this out earlier, this example was inspired by Chris
Wanstrath's before_fork hook but modified to use SIGTTOU instead of
SIGQUIT for all but the last worker to minimize memory explosions
during upgrades.
The :tries and :delay options were also inspired by Chris and will be
in v0.93.0 which will probably be released.
lib/unicorn/configurator.rb | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 7e66f60..bff8f7e 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -25,9 +25,26 @@ module Unicorn
# # as there's no need for the master process to hold a connection
# defined?(ActiveRecord::Base) and
# ActiveRecord::Base.connection.disconnect!
+ #
+ # # the following allows a new master process to incrementally
+ # # phase out the old master process with SIGTTOU to avoid a
+ # # thundering herd (especially in the "preload_app false" case)
+ # # when doing a transparent upgrade. The last worker spawned
+ # # will then kill off the old master process with a SIGQUIT.
+ # old_pid = "#{server.config[:pid]}.oldbin"
+ # if old_pid != server.pid
+ # begin
+ # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
+ # Process.kill(sig, File.read(old_pid).to_i)
+ # rescue Errno::ENOENT, Errno::ESRCH
+ # end
+ #
+ # # optionally throttle the master from forking too quickly by sleeping
+ # sleep 1
# end
#
# after_fork do |server, worker|
+ # # per-process listener ports for debugging/admin/migrations
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
#
@@ -50,10 +67,6 @@ module Unicorn
:worker_processes => 1,
:after_fork => lambda { |server, worker|
server.logger.info("worker=#{worker.nr} spawned pid=#{$$}")
-
- # per-process listener ports for debugging/admin:
- # addr = "127.0.0.1:#{8081 + worker.nr}"
- # server.listen(addr, :tries => -1, :delay => 5)
},
:before_fork => lambda { |server, worker|
server.logger.info("worker=#{worker.nr} spawning...")
--
Eric Wong
^ permalink raw reply related [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2009-10-02 8:11 7% [PATCH] configurator: update some migration examples Eric Wong
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).