From 94b848a8f9120bce8b0abd776b1a9b7e2f4fa30d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Dec 2010 02:43:44 +0000 Subject: introduce worker_yield method This lets Rainbows! yield the current worker process when busy in the hopes another worker will pick up the slack. We can also override this for the single worker process case later if people care enough. --- lib/rainbows/writer_thread_spawn/client.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/rainbows/writer_thread_spawn') diff --git a/lib/rainbows/writer_thread_spawn/client.rb b/lib/rainbows/writer_thread_spawn/client.rb index f9c373e..ed60f42 100644 --- a/lib/rainbows/writer_thread_spawn/client.rb +++ b/lib/rainbows/writer_thread_spawn/client.rb @@ -4,6 +4,7 @@ class Rainbows::WriterThreadSpawn::Client < Struct.new(:to_io, :q, :thr) include Rainbows::Response include Rainbows::SocketProxy + include Rainbows::WorkerYield CUR = {} # :nodoc: @@ -17,12 +18,10 @@ class Rainbows::WriterThreadSpawn::Client < Struct.new(:to_io, :q, :thr) 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) + }.size >= MAX and worker_yield end q = Queue.new -- cgit v1.2.3-24-ge0c7