diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-12-27 02:43:44 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-12-27 02:43:44 +0000 |
commit | 94b848a8f9120bce8b0abd776b1a9b7e2f4fa30d (patch) | |
tree | 672d1f677360e849bb4bf5200dc87ec266f701dc /lib/rainbows/writer_thread_spawn | |
parent | a310302708faa19042282e94525544cfbb23eba5 (diff) | |
download | rainbows-94b848a8f9120bce8b0abd776b1a9b7e2f4fa30d.tar.gz |
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.
Diffstat (limited to 'lib/rainbows/writer_thread_spawn')
-rw-r--r-- | lib/rainbows/writer_thread_spawn/client.rb | 5 |
1 files changed, 2 insertions, 3 deletions
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 |