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/thread_spawn.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'lib/rainbows/thread_spawn.rb') diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb index a0ccde6..9da75f1 100644 --- a/lib/rainbows/thread_spawn.rb +++ b/lib/rainbows/thread_spawn.rb @@ -18,6 +18,7 @@ module Rainbows module ThreadSpawn include Base + include Rainbows::WorkerYield def accept_loop(klass) #:nodoc: lock = Mutex.new @@ -26,16 +27,7 @@ module Rainbows klass.new(l) do |l| begin if lock.synchronize { G.cur >= limit } - # Sleep if we're busy, another less busy worker process may - # take it for us if we sleep. This is gross but other options - # still suck because they require expensive/complicated - # synchronization primitives for _every_ case, not just this - # unlikely one. Since this case is (or should be) uncommon, - # just busy wait when we have to. - # We don't use Thread.pass because it needlessly spins the - # CPU during I/O wait, CPU cycles that can be better used - # by other worker _processes_. - sleep(0.01) + worker_yield elsif c = l.kgio_accept klass.new(c) do |c| begin -- cgit v1.2.3-24-ge0c7