summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-09 00:17:06 +0000
committerEric Wong <normalperson@yhbt.net>2011-05-09 00:17:06 +0000
commit725adcc6986bc2658d92ea3ebebe61d2b83060ad (patch)
treedcaa850fc3a329e98dd420083105421cabfc5295
parent3c1649226d2371ce09d14f3fcce18fec0af1ba02 (diff)
coolio_thread_pool, neverblock both use it, and
xepoll_thread_pool will support it next, too.
-rw-r--r--lib/rainbows.rb1
-rw-r--r--lib/rainbows/coolio_thread_pool.rb11
-rw-r--r--lib/rainbows/never_block.rb14
-rw-r--r--lib/rainbows/pool_size.rb14
4 files changed, 20 insertions, 20 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index 0b663ba..da7011a 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -151,6 +151,7 @@ module Rainbows
   autoload :SyncClose, 'rainbows/sync_close'
   autoload :ReverseProxy, 'rainbows/reverse_proxy'
   autoload :JoinThreads, 'rainbows/join_threads'
+  autoload :PoolSize, 'rainbows/pool_size'
 end
 
 require 'rainbows/error'
diff --git a/lib/rainbows/coolio_thread_pool.rb b/lib/rainbows/coolio_thread_pool.rb
index 3d32bfb..378e64d 100644
--- a/lib/rainbows/coolio_thread_pool.rb
+++ b/lib/rainbows/coolio_thread_pool.rb
@@ -17,17 +17,8 @@
 module Rainbows::CoolioThreadPool
   # :stopdoc:
   autoload :Client, 'rainbows/coolio_thread_pool/client'
-  DEFAULTS = {
-    :pool_size => 20, # same default size as ThreadPool (w/o Coolio)
-  }
+  extend Rainbows::PoolSize
   #:startdoc:
-
-  def self.setup # :nodoc:
-    o = Rainbows::O
-    DEFAULTS.each { |k,v| o[k] ||= v }
-    Integer === o[:pool_size] && o[:pool_size] > 0 or
-      raise ArgumentError, "pool_size must a be an Integer > 0"
-  end
   include Rainbows::Coolio::Core
 
   def init_worker_threads(master, queue) # :nodoc:
diff --git a/lib/rainbows/never_block.rb b/lib/rainbows/never_block.rb
index a11b81d..63d9af3 100644
--- a/lib/rainbows/never_block.rb
+++ b/lib/rainbows/never_block.rb
@@ -15,20 +15,14 @@
 #   end
 #
 module Rainbows::NeverBlock
-
   # :stopdoc:
-  DEFAULTS = {
-    :pool_size => 20, # same default size used by NB
-    :backend => :EventMachine, # NeverBlock doesn't support Rev yet
-  }
+  extend Rainbows::PoolSize
 
   # same pool size NB core itself uses
   def self.setup # :nodoc:
-    o = Rainbows::O
-    DEFAULTS.each { |k,v| o[k] ||= v }
-    Integer === o[:pool_size] && o[:pool_size] > 0 or
-      raise ArgumentError, "pool_size must a be an Integer > 0"
-    Rainbows.const_get(o[:backend])
+    super
+    Rainbows::O[:backend] ||= :EventMachine # no Cool.io support, yet
+    Rainbows.const_get(Rainbows::O[:backend])
     require "never_block" # require EM first since we need a higher version
   end
 
diff --git a/lib/rainbows/pool_size.rb b/lib/rainbows/pool_size.rb
new file mode 100644
index 0000000..8089869
--- /dev/null
+++ b/lib/rainbows/pool_size.rb
@@ -0,0 +1,14 @@
+# -*- encoding: binary -*-
+# :stopdoc:
+module Rainbows::PoolSize
+  DEFAULTS = {
+    :pool_size => 50, # same as the default worker_connections
+  }
+
+  def setup
+    o = Rainbows::O
+    DEFAULTS.each { |k,v| o[k] ||= v }
+    Integer === o[:pool_size] && o[:pool_size] > 0 or
+      raise ArgumentError, "pool_size must a be an Integer > 0"
+  end
+end