From 56aaf96ffccebf70bf98f41c64bf533cef68f802 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 2 Mar 2009 18:48:47 -0800 Subject: Load the app _after_ forking workers by default This means processes will share less memory but things should be compatible with all existing setups. --- lib/unicorn.rb | 3 ++- lib/unicorn/configurator.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 42ac8c0..998f8b8 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -89,7 +89,7 @@ module Unicorn config_listeners.each { |addr| listen(addr) } listen(Const::DEFAULT_LISTENER) if @listeners.empty? self.pid = @config[:pid] - build_app! + build_app! if @preload_app spawn_missing_workers self end @@ -391,6 +391,7 @@ module Unicorn # traps for USR1, USR2, and HUP may be set in the @after_fork Proc # by the user. def init_worker_process(worker) + build_app! unless @preload_app TRAP_SIGS.each { |sig| trap(sig, 'IGNORE') } trap('CHLD', 'DEFAULT') trap('USR1') do diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb index ebdcba6..65b29c6 100644 --- a/lib/unicorn/configurator.rb +++ b/lib/unicorn/configurator.rb @@ -23,6 +23,7 @@ module Unicorn :directory => nil, :pid => nil, :backlog => 1024, + :preload_app => false, } attr_reader :config_file @@ -142,6 +143,15 @@ module Unicorn @set[:directory] = path ? File.expand_path(path) : nil end + def preload_app(bool) + case bool + when TrueClass, FalseClass + @set[:preload_app] = bool + else + raise ArgumentError, "preload_app=#{bool.inspect} not a boolean" + end + end + private def set_hook(var, my_proc) #:nodoc: -- cgit v1.2.3-24-ge0c7