From 371f05992110616412c57a26fb6688dc2111c65d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 26 May 2010 22:50:15 +0000 Subject: writer_thread_spawn: worker_connections limits thread spawned This should be logical, since we keep the connection alive when writing in our writer threads. --- lib/rainbows.rb | 2 +- lib/rainbows/writer_thread_spawn.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rainbows.rb b/lib/rainbows.rb index 41d436e..dac68c2 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -135,7 +135,7 @@ module Rainbows MODEL_WORKER_CONNECTIONS = { :Base => 1, # this one can't change :WriterThreadPool => 20, - :WriterThreadSpawn => 1, + :WriterThreadSpawn => 20, :Revactor => 50, :ThreadSpawn => 30, :ThreadPool => 20, 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 -- cgit v1.2.3-24-ge0c7