rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob e81d35820accfd61aa63c9040c14c0ac8200dddb 639 bytes (raw)
$ git show HEAD:lib/rainbows/worker_yield.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
 
# -*- encoding: binary -*-
# :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

git clone https://yhbt.net/rainbows.git