about summary refs log tree commit homepage
path: root/lib/unicorn/http_server.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-10 23:54:47 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-11 00:23:57 +0000
commit5d2284afdc2d4f4ff122394ae5fd78a32cb8c09e (patch)
tree5dcdc08565def75ba7d7f106f30d45de9a6de1e2 /lib/unicorn/http_server.rb
parent987b9496171b090e62de488ddc7b9a175c4c8d33 (diff)
downloadunicorn-5d2284afdc2d4f4ff122394ae5fd78a32cb8c09e.tar.gz
This reduces the size of `caller` by 5 frames,
which should make backtraces easier-to-read, raising
exceptions less expensive, and reduce GC runtime.
Diffstat (limited to 'lib/unicorn/http_server.rb')
-rw-r--r--lib/unicorn/http_server.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 604854a..66b137f 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -497,14 +497,22 @@ class Unicorn::HttpServer
   end
 
   def spawn_missing_workers
-    (0...worker_processes).each do |worker_nr|
+    worker_nr = -1
+    until (worker_nr += 1) == @worker_processes
       WORKERS.values.include?(worker_nr) and next
       worker = Worker.new(worker_nr, Unicorn::TmpIO.new)
       before_fork.call(self, worker)
-      WORKERS[fork {
-        after_fork_internal
-        worker_loop(worker)
-      }] = worker
+      if pid = fork
+        WORKERS[pid] = worker
+      else
+        begin
+          after_fork_internal
+          worker_loop(worker)
+          exit(0)
+        rescue Object
+          exit!(1)
+        end
+      end
     end
   end