about summary refs log tree commit homepage
path: root/lib/rainbows/writer_thread_spawn.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-05-26 22:50:15 +0000
committerEric Wong <normalperson@yhbt.net>2010-05-26 22:50:15 +0000
commit371f05992110616412c57a26fb6688dc2111c65d (patch)
tree691e25d497e634d4ae84461c92c1a6a5c7a801c0 /lib/rainbows/writer_thread_spawn.rb
parent904526129a2377306a735c73b26699583b3b99c5 (diff)
downloadrainbows-371f05992110616412c57a26fb6688dc2111c65d.tar.gz
This should be logical, since we keep the connection alive
when writing in our writer threads.
Diffstat (limited to 'lib/rainbows/writer_thread_spawn.rb')
-rw-r--r--lib/rainbows/writer_thread_spawn.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/rainbows/writer_thread_spawn.rb b/lib/rainbows/writer_thread_spawn.rb
index 3b1356a..1d0cfa0 100644
--- a/lib/rainbows/writer_thread_spawn.rb
+++ b/lib/rainbows/writer_thread_spawn.rb
@@ -37,6 +37,14 @@ module Rainbows
       end
 
       def queue_writer
+        # not using Thread.pass here because that spins the CPU during
+        # I/O wait and will eat cycles from other worker processes.
+        until CUR.size < MAX
+          CUR.delete_if { |t,_|
+            t.alive? ? t.join(0) : true
+          }.size >= MAX and sleep(0.01)
+        end
+
         q = Queue.new
         self.thr = Thread.new(to_io, q) do |io, q|
           while response = q.shift
@@ -93,6 +101,7 @@ module Rainbows
     end
 
     def worker_loop(worker)
+      MySocket.const_set(:MAX, worker_connections)
       super(worker) # accept loop from Unicorn
       CUR.delete_if do |t,q|
         q << nil