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/worker_yield.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/rainbows/worker_yield.rb (limited to 'lib/rainbows/worker_yield.rb') diff --git a/lib/rainbows/worker_yield.rb b/lib/rainbows/worker_yield.rb new file mode 100644 index 0000000..ec2a289 --- /dev/null +++ b/lib/rainbows/worker_yield.rb @@ -0,0 +1,15 @@ +# :enddoc: +module Rainbows::WorkerYield + + # Sleep if we're busy (and let other threads run). 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_. + def worker_yield + sleep(0.01) + end +end -- cgit v1.2.3-24-ge0c7